From a7e0340a798533f260c88f64e1b41b327b7874f9 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 22 Dec 2018 20:45:54 -0800 Subject: [PATCH] gingerly --- pitfall/pitfall/afm-font.rkt | 2 +- pitfall/pitfall/embedded.rkt | 31 ++++++++++++++++++------------- pitfall/pitfall/standard-font.rkt | 19 ++++++++++++------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/pitfall/pitfall/afm-font.rkt b/pitfall/pitfall/afm-font.rkt index ab9a7ad9..e255c3ab 100644 --- a/pitfall/pitfall/afm-font.rkt +++ b/pitfall/pitfall/afm-font.rkt @@ -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 diff --git a/pitfall/pitfall/embedded.rkt b/pitfall/pitfall/embedded.rkt index fba78e22..a987fdc7 100644 --- a/pitfall/pitfall/embedded.rkt +++ b/pitfall/pitfall/embedded.rkt @@ -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) diff --git a/pitfall/pitfall/standard-font.rkt b/pitfall/pitfall/standard-font.rkt index b7444e3f..b09cac42 100644 --- a/pitfall/pitfall/standard-font.rkt +++ b/pitfall/pitfall/standard-font.rkt @@ -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"