-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fixed Issue #8068 - SVG encoding #8415
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
Changes from all commits
6b4827a
3fad38d
0122faf
49ad267
41e1047
c9f84b6
cee6250
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,13 +44,6 @@ def __init__(self): | |
|
||
self._texmanager = None | ||
|
||
self._adobe_standard_encoding = None | ||
|
||
def _get_adobe_standard_encoding(self): | ||
enc_name = dviread.find_tex_file('8a.enc') | ||
enc = dviread.Encoding(enc_name) | ||
return {c: i for i, c in enumerate(enc.encoding)} | ||
|
||
def _get_font(self, prop): | ||
""" | ||
find a ttf font. | ||
|
@@ -299,14 +292,12 @@ def get_glyphs_tex(self, prop, s, glyph_map=None, | |
# codes are modstly borrowed from pdf backend. | ||
|
||
texmanager = self.get_texmanager() | ||
use_glyph = False | ||
|
||
if self.tex_font_map is None: | ||
self.tex_font_map = dviread.PsfontsMap( | ||
dviread.find_tex_file('pdftex.map')) | ||
|
||
if self._adobe_standard_encoding is None: | ||
self._adobe_standard_encoding = self._get_adobe_standard_encoding() | ||
|
||
fontsize = prop.get_size_in_points() | ||
if hasattr(texmanager, "get_dvi"): | ||
dvifilelike = texmanager.get_dvi(s, self.FONT_SCALE) | ||
|
@@ -358,11 +349,21 @@ def get_glyphs_tex(self, prop, s, glyph_map=None, | |
warnings.warn("No supported encoding in font (%s)." % | ||
font_bunch.filename) | ||
|
||
# Character is a glyph and needs to be mapped to corresponding index | ||
if charmap_name == "ADOBE_STANDARD" and font_bunch.encoding: | ||
use_glyph = True | ||
enc0 = dviread.Encoding(font_bunch.encoding) | ||
enc = {i: self._adobe_standard_encoding.get(c, None) | ||
for i, c in enumerate(enc0.encoding)} | ||
|
||
# Make a list of each glyph by splitting the encoding | ||
enc0_list = [] | ||
for e in enc0.encoding: | ||
enc0_list += e.split("/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: one needs to do |
||
|
||
# Encoding provided by the font file mapping names to index | ||
enc = {i: font.get_name_index(c) or None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in a block for when I think the fix should probably be fixed above to select a better character map for the file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the block where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then the conditional should be changed, not just silently internally ignored. |
||
for i, c in enumerate(enc0_list)} | ||
else: | ||
use_glyph = False | ||
enc = {} | ||
self._ps_fontd[dvifont.texname] = font, enc | ||
|
||
|
@@ -382,7 +383,10 @@ def get_glyphs_tex(self, prop, s, glyph_map=None, | |
charcode = glyph | ||
|
||
if charcode is not None: | ||
glyph0 = font.load_char(charcode, flags=ft2font_flag) | ||
if use_glyph: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be merged up into the conditionals above to simplify the logic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. your right, I missed that there was a path to get a non-empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this is very problematic, the code path above where you set |
||
glyph0 = font.load_glyph(charcode, flags=ft2font_flag) | ||
else: | ||
glyph0 = font.load_char(charcode, flags=ft2font_flag) | ||
else: | ||
warnings.warn("The glyph (%d) of font (%s) cannot be " | ||
"converted with the encoding. Glyph may " | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the same as
enc0_list = [e.split('/') for e in enc0.encoding]
?Why do this splitting?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that'll make a 2D list, but we need 1D.
The encoding that is generated looks like this
['Grave/Acute/Circumflex/Tilde/Dieresis/Hungarumlaut/Ring.....']
Thus splitting at "/" gives us individual character names.
Not only that, each index actually corresponds to its character code
(eg: enc0_list[142] = 'uni20A9' which is the Won character)
Therefore, line 363-364, enumerates the list with
i = character code
andc = character name
and creates a dictionarycharacter code => font index
Later, in the code the glyph is retrieved using this dictionary
Hope this makes sense :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how has this ever worked if that is the case?