@@ -617,40 +617,18 @@ def _get_pdf_charprocs(font_path, glyph_ids):
617
617
procs = {}
618
618
for glyph_id in glyph_ids :
619
619
g = font .load_glyph (glyph_id ,LoadFlags .NO_SCALE )
620
- # NOTE: We should be using round(), but instead use
621
- # "(x+.5).astype(int)" to keep backcompat with the old ttconv code
622
- # (this is different for negative x's).
623
- d1 = (np .array ([g .horiAdvance ,0 ,* g .bbox ])* conv + .5 ).astype (int )
620
+ d1 = [
621
+ round (g .horiAdvance * conv ),0 ,
622
+ # Round bbox corners *outwards*, so that they indeed bound the glyph.
623
+ math .floor (g .bbox [0 ]* conv ),math .floor (g .bbox [1 ]* conv ),
624
+ math .ceil (g .bbox [2 ]* conv ),math .ceil (g .bbox [3 ]* conv ),
625
+ ]
624
626
v ,c = font .get_path ()
625
- v = (v * 64 ).astype (int )# Back to TrueType's internal units (1/64's).
626
- # Backcompat with old ttconv code: control points between two quads are
627
- # omitted if they are exactly at the midpoint between the control of
628
- # the quad before and the quad after, but ttconv used to interpolate
629
- # *after* conversion to PS units, causing floating point errors. Here
630
- # we reproduce ttconv's logic, detecting these "implicit" points and
631
- # re-interpolating them. Note that occasionally (e.g. with DejaVu Sans
632
- # glyph "0") a point detected as "implicit" is actually explicit, and
633
- # will thus be shifted by 1.
634
- quads ,= np .nonzero (c == 3 )
635
- quads_on = quads [1 ::2 ]
636
- quads_mid_on = np .array (
637
- sorted ({* quads_on }& {* (quads - 1 )}& {* (quads + 1 )}),int )
638
- implicit = quads_mid_on [
639
- (v [quads_mid_on ]# As above, use astype(int), not // division
640
- == ((v [quads_mid_on - 1 ]+ v [quads_mid_on + 1 ])/ 2 ).astype (int ))
641
- .all (axis = 1 )]
642
- if (font .postscript_name ,glyph_id )in [
643
- ("DejaVuSerif-Italic" ,77 ),# j
644
- ("DejaVuSerif-Italic" ,135 ),# \AA
645
- ]:
646
- v [:,0 ]-= 1 # Hard-coded backcompat (FreeType shifts glyph by 1).
647
- v = (v * conv + .5 ).astype (int )# As above re: truncation vs rounding.
648
- v [implicit ]= ((# Fix implicit points; again, truncate.
649
- (v [implicit - 1 ]+ v [implicit + 1 ])/ 2 ).astype (int ))
627
+ v = (v * 64 * conv ).round ()# Back to TrueType's internal units (1/64's).
650
628
procs [font .get_glyph_name (glyph_id )]= (
651
629
" " .join (map (str ,d1 )).encode ("ascii" )+ b" d1\n "
652
630
+ _path .convert_to_string (
653
- Path (v ,c ),None ,None ,False ,None ,- 1 ,
631
+ Path (v ,c ),None ,None ,False ,None ,0 ,
654
632
# no code for quad Beziers triggers auto-conversion to cubics.
655
633
[b"m" ,b"l" ,b"" ,b"c" ,b"h" ],True )
656
634
+ b"f" )