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

Skip to content

Commit 8ab1ad6

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 1fb0ace commit 8ab1ad6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,12 @@ def _update_glyph_map_defs(self, glyph_map_new):
10091009
writer.start('defs')
10101010
for char_id, (vertices, codes) in glyph_map_new.items():
10111011
char_id = self._adjust_char_id(char_id)
1012+
# x64 to go back to FreeType's internal (integral) units.
10121013
path_data = self._convert_path(
1013-
Path(vertices, codes), simplify=False)
1014-
writer.element('path', id=char_id, d=path_data)
1014+
Path(vertices * 64, codes), simplify=False)
1015+
writer.element(
1016+
'path', id=char_id, d=path_data,
1017+
transform=generate_transform([('scale', (1 / 64,))]))
10151018
writer.end('defs')
10161019
self._glyph_map.update(glyph_map_new)
10171020

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_unicode_won():
121121
won_id = 'SFSS3583-8e'
122122
tree = xml.etree.ElementTree.fromstring(buf)
123123
assert len(tree.findall(f'.//{{*}}path[@d][@id="{won_id}"]')) == 1
124-
assert won_id in tree.findall(f'.//{{*}}use').attrib.values
124+
assert f'#{won_id}' in tree.find('.//{*}use').attrib.values()
125125

126126

127127
def test_svgnone_with_data_coordinates():

0 commit comments

Comments
 (0)