main
Matthew Butterick 6 years ago
parent 261ecddc95
commit a111263513

@ -30,15 +30,17 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
embed
toUnicodeCmap))
(define/contract (widthOfString this string size [features #f])
((string? number?) ((option/c list?)) . ->*m . number?)
(cond
[features ; #f disables features ; null enables default features ; list adds features
(define run (send (· this font) layout string features))
(define width-cache (make-hash))
(define (widthOfString this string size [features #f])
((string? number?) ((option/c (listof symbol?))) . ->*m . number?)
; #f disables features ; null enables default features ; list adds features
(hash-ref! width-cache
(list string size (and features (sort features symbol<?)))
(λ ()
(define run (send (· this font) layout string features))
(define width (· run advanceWidth))
(define scale (/ size (+ (· this font unitsPerEm) 0.0)))
(* width scale)]
[else (send (· this font) measure-string string size)]))
(* width scale))))
;; called from text.rkt

@ -197,6 +197,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/mixins/text.coffee
;; since the normal Tw operator only works on character code 32, which isn't
;; used for embedded fonts.
;; 180321: the first call to this operation is very slow from Quad
;; 181126: because `encode` calls `layout`
(match-define (list encoded-char-strs positions)
(if (not (zero? wordSpacing))
(error 'unimplemented-brach) ; todo

Binary file not shown.

@ -27,7 +27,7 @@ endobj
<<
/Producer (PDFKit)
/Creator (PDFKit)
/CreationDate (D:20181120220342Z)
/CreationDate (D:20181126220022Z)
>>
endobj
2 0 obj

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save