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

Skip to content

Commit 1fb0ace

Browse files
committed
Switch svg glyph references back to hex; merge tex & non-tex names.
When embedding glyphs as paths in SVG files, each glyph has a name just so that we can link to them when actually placing the glyphs. Previously there were two different paths for non-usetex glyphs and usetex glyphs. - In a2287b1 I accidentally changed the number component of non-usetex names from hex to decimal (usetex was always using decimal); switch it back to hex as that's typically how glyph tables are listed anyways. Also switch the usetex case to hex for consistency. - Make non-usetex and usetex names use the same way to generate the name. The 2nd entry of ps_font_info typically matches postscript_name (but is only available for Type1 fonts, whereas postscript_name is defined for all fonts), but even if they donn't (see test_unicode_won), this doesn't matter as long as we are internally consistent... Also changed unicode_won test to actually parse the xml -- the regexp search seems quite slow locally, and anyways regex'ing xml is not necessarily a great idea :)
1 parent a8831d5 commit 1fb0ace

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ def test_unicode_won():
118118
fig.savefig(fd, format='svg')
119119
buf = fd.getvalue().decode('ascii')
120120

121-
won_id = 'Computer_Modern_Sans_Serif-142'
122-
assert re.search(r'<path d=(.|\s)*?id="{0}"/>'.format(won_id), buf)
123-
assert re.search(r'<use[^/>]*? xlink:href="#{0}"/>'.format(won_id), buf)
121+
won_id = 'SFSS3583-8e'
122+
tree = xml.etree.ElementTree.fromstring(buf)
123+
assert len(tree.findall(f'.//{{*}}path[@d][@id="{won_id}"]')) == 1
124+
assert won_id in tree.findall(f'.//{{*}}use').attrib.values
124125

125126

126127
def test_svgnone_with_data_coordinates():

lib/matplotlib/textpath.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,7 @@ def _get_char_id(self, font, ccode):
4141
"""
4242
Return a unique id for the given font and character-code set.
4343
"""
44-
return urllib.parse.quote('{}-{}'.format(font.postscript_name, ccode))
45-
46-
def _get_char_id_ps(self, font, ccode):
47-
"""
48-
Return a unique id for the given font and character-code set (for tex).
49-
"""
50-
ps_name = font.get_ps_font_info()[2]
51-
char_id = urllib.parse.quote('%s-%d' % (ps_name, ccode))
52-
return char_id
44+
return urllib.parse.quote(f"{font.postscript_name}-{ccode:x}")
5345

5446
def get_text_width_height_descent(self, s, prop, ismath):
5547
if ismath == "TeX":
@@ -254,7 +246,7 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
254246
# characters into strings.
255247
for x1, y1, dvifont, glyph, width in page.text:
256248
font, enc = self._get_ps_font_and_encoding(dvifont.texname)
257-
char_id = self._get_char_id_ps(font, glyph)
249+
char_id = self._get_char_id(font, glyph)
258250

259251
if char_id not in glyph_map:
260252
font.clear()

0 commit comments

Comments
 (0)