store upm

main
Matthew Butterick 6 years ago
parent ac0f8ba060
commit b739ce847b

@ -40,6 +40,7 @@
id
ascender
descender
upm
line-gap
bbox
ref

@ -42,6 +42,7 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(define unicode (mhasheq 0 '(0))) ; always include the missing glyph (gid = 0)
(define widths (mhasheq 0 (glyph-advance-width (get-glyph font 0))))
(define name (font-postscript-name font))
(define upm (font-units-per-em font))
(define scale (/ 1000 (font-units-per-em font)))
(define ascender (* (font-ascent font) scale))
(define descender (* (font-descent font) scale))
@ -49,14 +50,14 @@ https://github.com/mbutterick/pdfkit/blob/master/lib/font/embedded.coffee
(define line-gap (* (font-linegap font) scale))
(define encoding-cache (make-hash)) ; needs to be per font, not in top level of module
(efont
name id ascender descender line-gap bbox #f #f efont-embedded efont-encode efont-measure-string
name id ascender descender upm line-gap bbox #f #f efont-embedded efont-encode efont-measure-string
font subset unicode widths scale encoding-cache))
(define (efont-measure-string ef str size [features null])
; #f disables features ; null enables default features ; list adds features
(define scale (/ size (+ (font-units-per-em (efont-font ef)) 0.0)))
(define scale (/ size (pdf-font-upm ef) 1.0))
;; use `encode` because it's cached.
;; we assume that the side effects of `encode`
;; (e.g., appending to `widths` and `unicode`)

@ -24,11 +24,12 @@
(define kern-pairs (make-hash kps))
(define ascender (string->number (hash-ref attributes 'Ascender "0")))
(define descender (string->number (hash-ref attributes 'Descender "0")))
(define upm 1000)
(define bbox (for/list ([attr (in-list (string-split (hash-ref attributes 'FontBBox)))])
(or (string->number attr) 0)))
(define line-gap (- (third bbox) (first bbox) ascender descender))
(sfont
name id ascender descender line-gap bbox #f #f sfont-embed sfont-encode sfont-measure-string
name id ascender descender upm line-gap bbox #f #f sfont-embed sfont-encode sfont-measure-string
attributes glyph-widths kern-pairs))
(define (sfont-embed sf)

Loading…
Cancel
Save