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

Skip to content

Small changes to svg font embedding details #17669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,12 @@ def _update_glyph_map_defs(self, glyph_map_new):
writer.start('defs')
for char_id, (vertices, codes) in glyph_map_new.items():
char_id = self._adjust_char_id(char_id)
# x64 to go back to FreeType's internal (integral) units.
path_data = self._convert_path(
Path(vertices, codes), simplify=False)
writer.element('path', id=char_id, d=path_data)
Path(vertices * 64, codes), simplify=False)
writer.element(
'path', id=char_id, d=path_data,
transform=generate_transform([('scale', (1 / 64,))]))
writer.end('defs')
self._glyph_map.update(glyph_map_new)

Expand Down
11 changes: 6 additions & 5 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from io import BytesIO
import re
import tempfile
import xml.etree.ElementTree
import xml.parsers.expat
Expand Down Expand Up @@ -211,11 +210,13 @@ def test_unicode_won():

with BytesIO() as fd:
fig.savefig(fd, format='svg')
buf = fd.getvalue().decode('ascii')
buf = fd.getvalue()

won_id = 'Computer_Modern_Sans_Serif-142'
assert re.search(r'<path d=(.|\s)*?id="{0}"/>'.format(won_id), buf)
assert re.search(r'<use[^/>]*? xlink:href="#{0}"/>'.format(won_id), buf)
tree = xml.etree.ElementTree.fromstring(buf)
ns = 'http://www.w3.org/2000/svg'
won_id = 'SFSS3583-8e'
assert len(tree.findall(f'.//{{{ns}}}path[@d][@id="{won_id}"]')) == 1
assert f'#{won_id}' in tree.find(f'.//{{{ns}}}use').attrib.values()


def test_svgnone_with_data_coordinates():
Expand Down
12 changes: 2 additions & 10 deletions lib/matplotlib/textpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ def _get_char_id(self, font, ccode):
"""
Return a unique id for the given font and character-code set.
"""
return urllib.parse.quote('{}-{}'.format(font.postscript_name, ccode))

def _get_char_id_ps(self, font, ccode):
"""
Return a unique id for the given font and character-code set (for tex).
"""
ps_name = font.get_ps_font_info()[2]
char_id = urllib.parse.quote('%s-%d' % (ps_name, ccode))
return char_id
return urllib.parse.quote(f"{font.postscript_name}-{ccode:x}")

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

if char_id not in glyph_map:
font.clear()
Expand Down