Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9c9ef1a

Browse files
committed
Record svg glyphs in 1/64 pixel units.
1/64-pixel is the "natural" unit for TrueType and FreeType ("F26Dot6"). Using it makes glyphs recorded in SVG files shorter, e.g. ``` M 88.796875 4.296875 Q 88.796875 2.09375 87.140625 0.5 Q 85.5 -1.09375 83.203125 -1.09375 ``` becomes ``` M 1113 -72 Q 709 -72 476 233 Q 244 538 244 953 ``` (the concatenated svg output of test_mathtext.py is ~10% shorter) and easier to compare with FreeType values when troubleshooting font embedding. An additional `transform="scale(0.015625)"` (i.e. 1/64) is added at the end to scale the glyph, but given that a further scaling and translation is done to actually render the glyph at the right size and position in the svg, I doubt that this really affects svg renderer performance (likely they can compose the two scalings first).
1 parent d823656 commit 9c9ef1a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,12 @@ def _update_glyph_map_defs(self, glyph_map_new):
10181018
writer.start('defs')
10191019
for char_id, (vertices, codes) in glyph_map_new.items():
10201020
char_id = self._adjust_char_id(char_id)
1021+
# x64 to go back to FreeType's internal (integral) units.
10211022
path_data = self._convert_path(
1022-
Path(vertices, codes), simplify=False)
1023-
writer.element('path', id=char_id, d=path_data)
1023+
Path(vertices * 64, codes), simplify=False)
1024+
writer.element(
1025+
'path', id=char_id, d=path_data,
1026+
transform=generate_transform([('scale', (1 / 64,))]))
10241027
writer.end('defs')
10251028
self._glyph_map.update(glyph_map_new)
10261029

0 commit comments

Comments
 (0)