main
Matthew Butterick 6 years ago
parent c7918f9504
commit a7e0340a79

@ -29,7 +29,7 @@
(or (string->number attr) 0))])
(field [ascender (string->number (or (hash-ref attributes 'Ascender #f) "0"))])
(field [descender (string->number (or (hash-ref attributes 'Descender #f) "0"))])
(field [lineGap (- (- (list-ref bbox 3) (list-ref bbox 1)) (- ascender descender))])
(field [line-gap (- (- (list-ref bbox 3) (list-ref bbox 1)) (- ascender descender))])
(as-methods
parse

@ -50,13 +50,18 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
[name (font-postscript-name font)]
[scale (/ 1000 (font-units-per-em font))])
(inherit-field ascender descender bbox line-gap dictionary document)
(set! ascender (* (font-ascent font) scale))
(set! descender (* (font-descent font) scale))
(set! line-gap (* (font-linegap font) scale))
(set! bbox (font-bbox font))
(set! document document-in)
(inherit-field [@ascender ascender]
[@descender descender]
[@bbox bbox]
[@line-gap line-gap]
[@dictionary dictionary]
[@document document])
(set! @ascender (* (font-ascent font) scale))
(set! @descender (* (font-descent font) scale))
(set! @line-gap (* (font-linegap font) scale))
(set! @bbox (font-bbox font))
(set! @document document-in)
(define/override (widthOfString string size [features #f])
; #f disables features ; null enables default features ; list adds features
@ -92,7 +97,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(define/override (embed)
;; no CFF support
(define isCFF #false) #;(is-a? (· this subset) CFFSubset)
(define fontFile (send document ref))
(define fontFile (send @document ref))
(when isCFF
(send fontFile set-key! 'Subtype "CIDFontType0C"))
@ -122,7 +127,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(define name (string-append tag "+" (font-postscript-name font)))
(define bbox (font-bbox font))
(define descriptor (send document ref
(define descriptor (send @document ref
(mhash
'Type "FontDescriptor"
'FontName name
@ -130,8 +135,8 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
'FontBBox (map (λ (x) (* scale x))
(bbox->list bbox))
'ItalicAngle (font-italic-angle font)
'Ascent ascender
'Descent descender
'Ascent @ascender
'Descent @descender
'CapHeight (* (or (font-cap-height font) (· this sfont ascent)) scale)
'XHeight (* (or (font-x-height font) 0) scale)
'StemV 0)))
@ -142,7 +147,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(· descriptor end)
(define descendantFont (send document ref
(define descendantFont (send @document ref
(mhash
'Type "Font"
'Subtype (string-append "CIDFontType" (if isCFF "0" "2"))
@ -165,7 +170,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
[set-key! 'DescendantFonts (list descendantFont)]
[set-key! 'ToUnicode (· this toUnicodeCmap)])
(send dictionary end))
(send @dictionary end))
(define/public (toUnicodeCmap)

@ -19,16 +19,21 @@
((hash-ref standard-fonts name
(λ () (raise-argument-error 'PDFFont "valid font name" name)))))])
(inherit-field ascender descender bbox line-gap dictionary document)
(inherit-field [@ascender ascender]
[@descender descender]
[@bbox bbox]
[@line-gap line-gap]
[@dictionary dictionary]
[@document document])
(set! ascender (· font ascender))
(set! descender (· font descender))
(set! bbox (· font bbox))
(set! line-gap (· font line-gap))
(set! document document-in)
(set! @ascender (get-field ascender font))
(set! @descender (get-field descender font))
(set! @bbox (get-field bbox font))
(set! @line-gap (get-field line-gap font))
(set! @document document-in)
(define/override (embed)
(set-field! payload dictionary
(set-field! payload @dictionary
(mhash 'Type "Font"
'BaseFont name
'Subtype "Type1"

Loading…
Cancel
Save