Skip to content

Commit 0b30a3c

Browse files
anntzerQuLogic
authored andcommitted
Remove ttconv backwards-compatibility code
1 parent 35c4647 commit 0b30a3c

File tree

113 files changed

+27
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+27
-62
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -617,40 +617,18 @@ def _get_pdf_charprocs(font_path, glyph_ids):
617617
procs = {}
618618
for glyph_id in glyph_ids:
619619
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 th 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+
]
624626
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).
650628
procs[font.get_glyph_name(glyph_id)] = (
651629
" ".join(map(str, d1)).encode("ascii") + b" d1\n"
652630
+ _path.convert_to_string(
653-
Path(v, c), None, None, False, None, -1,
631+
Path(v, c), None, None, False, None, 0,
654632
# no code for quad Beziers triggers auto-conversion to cubics.
655633
[b"m", b"l", b"", b"c", b"h"], True)
656634
+ b"f")
-1.97 KB
Binary file not shown.
322 Bytes
Binary file not shown.
393 Bytes
Binary file not shown.
34 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.
9 Bytes
Binary file not shown.
10 Bytes
Binary file not shown.
20 Bytes
Binary file not shown.
16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)