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 embed
toUnicodeCmap)) toUnicodeCmap))
(define/contract (widthOfString this string size [features #f]) (define width-cache (make-hash))
((string? number?) ((option/c list?)) . ->*m . number?) (define (widthOfString this string size [features #f])
(cond ((string? number?) ((option/c (listof symbol?))) . ->*m . number?)
[features ; #f disables features ; null enables default features ; list adds features ; #f disables features ; null enables default features ; list adds features
(define run (send (· this font) layout string 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 width (· run advanceWidth))
(define scale (/ size (+ (· this font unitsPerEm) 0.0))) (define scale (/ size (+ (· this font unitsPerEm) 0.0)))
(* width scale)] (* width scale))))
[else (send (· this font) measure-string string size)]))
;; called from text.rkt ;; 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 ;; since the normal Tw operator only works on character code 32, which isn't
;; used for embedded fonts. ;; used for embedded fonts.
;; 180321: the first call to this operation is very slow from Quad ;; 180321: the first call to this operation is very slow from Quad
;; 181126: because `encode` calls `layout`
(match-define (list encoded-char-strs positions) (match-define (list encoded-char-strs positions)
(if (not (zero? wordSpacing)) (if (not (zero? wordSpacing))
(error 'unimplemented-brach) ; todo (error 'unimplemented-brach) ; todo

Binary file not shown.

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save