Skip to content

Fixed Issue #8068 - SVG encoding#8415

Closed
sughandj wants to merge 7 commits into
matplotlib:masterfrom
sughandj:issue8068_svg_encoding
Closed

Fixed Issue #8068 - SVG encoding#8415
sughandj wants to merge 7 commits into
matplotlib:masterfrom
sughandj:issue8068_svg_encoding

Conversation

@sughandj

@sughandj sughandj commented Apr 1, 2017

Copy link
Copy Markdown

SVG backend now supports special characters like won symbol with usetex.
#8068

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Apr 2, 2017
@tacaswell

Copy link
Copy Markdown
Member

Does #8286 also fix the same problem?

@sughandj

Copy link
Copy Markdown
Author

@tacaswell Hi, sorry for the late reply.
I checked out #8286 and tried to reproduce #8068, the warning is not there however, the Won character doesn't show up.
Looks like #8286 doesn't solve #8068.

for i, c in enumerate(enc0.encoding)}

# Make a list of each glyph by splitting the encoding
enc0_list = []

Copy link
Copy Markdown
Member

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?

@sughandj sughandj Apr 18, 2017

Copy link
Copy Markdown
Author

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 and c = character name and creates a dictionary character code => font index
Later, in the code the glyph is retrieved using this dictionary

if enc:
    charcode = enc.get(glyph, None)

Hope this makes sense :)

Copy link
Copy Markdown
Member

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?

enc0_list += e.split("/")

# Encoding provided by the font file mapping names to index
enc = {i: font.get_name_index(c) or None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in a block for when charmap_name == "ADOBE_STANDARD", why change to not use the standard encoding?

I think the fix should probably be fixed above to select a better character map for the file?

@sughandj sughandj Apr 18, 2017

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the block where if charmap_name == "ADOBE_STANDARD" and font_bunch.encoding:
Since font_bunch already has Unicode values in them, we don't need to specially use the adobe standard file.
Thus, it was removed completely.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the conditional should be changed, not just silently internally ignored.


if charcode is not None:
glyph0 = font.load_char(charcode, flags=ft2font_flag)
if use_glyph:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The charcode is set right before we reach this condition if charcode is not None:
Therefore, it seems like the right spot to decide which font method to use to load the charcode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 enc that did not set use_glyph to True.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is very problematic, the code path above where you set use_glyph is a caching mechanism so the second time around this may have the wrong value of use_glyph?

@tacaswell

Copy link
Copy Markdown
Member

Can you explain this changes a bit better? Assume I know nothing about how font encoding works :)

Could you include the changes from #8286 in this PR (or explain why they are wrong!)?

@sughandj

Copy link
Copy Markdown
Author

@tacaswell I hope the replies to your comments give you more insight of the changes :)
Let me know if you have any other questions.

@tacaswell

Copy link
Copy Markdown
Member

The test failures look real.

I am still extremely uncomfortable with this change because I do not understand it yet.

This seems to be drastically changing how this code works (by consuming the encoding from the font rather than forcing it to use the adobe character map) but is still leaving a bunch of the old machinery around leaving the code in a very confused state.

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Aug 29, 2017
# Make a list of each glyph by splitting the encoding
enc0_list = []
for e in enc0.encoding:
enc0_list += e.split("/")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: one needs to do e.decode("ascii").split("/") to test this PR on Py3.

@anntzer anntzer mentioned this pull request Dec 3, 2018
6 tasks
@anntzer

anntzer commented Jul 5, 2019

Copy link
Copy Markdown
Contributor

I think this has been superseded by #12928 (which owes much to this PR, thanks :)).

@anntzer anntzer closed this Jul 5, 2019
@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants