Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rework mapping of dvi glyph indices to freetype indices.#29829

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
story645 merged 1 commit intomatplotlib:mainfromanntzer:dvi2ft
May 8, 2025

Conversation

anntzer
Copy link
Contributor

@anntzeranntzer commentedMar 29, 2025
edited
Loading

In89a7e19, an API for converting "dvi glyph indices" (as stored in a dvi file) to FreeType-compatible keys (either "indices into the native charmap" or "glyph names") was introduced. It was intended that end users (i.e., backends) would check the type oftext.glyph_name_or_index ((A) int or (B) str) and load the glyph accordingly ((A)FT_Set_Charmap(native_cmap); FT_Load_Char(index); or (B)FT_Load_Glyph(FT_Get_Name_Index(name));); however, with the future introduction of {xe,lua}tex support, this kind of type checking becomes inconvenient, because {xe,lua}tex's "dvi glyph indices", which are directly equal to FreeType glyph indices (i.e. they would be loaded withFT_Load_Glyph(index);), would normally also be converted to ints.

This PR introduces a new API (Text.index) that performs this mapping (via the newDviFont._index_dvi_to_freetype), always mapping to FreeType glyph indices (i.e. one can always just callFT_Load_Glyph on the result). To do so, in case (A) it loads itself the native charmap (something the end user needed to do by themselves previously) and performs the cmap-to-index conversion (FT_Get_Char_Index) previously implicit inFT_Load_Char; in case (B) it performs itself the name-to-index conversion (FT_Get_Name_Index). When {xe,lua}tex support is introduced in the future,_index_dvi_to_freetype will just return the index as is.

The old APIs are not deprecated yet, as other changes will occur for {xe,lua}tex support (e.g. font_effects will go away and be replaced by.font.effects, as {xe,lua}tex don't store that info in the pdftexmap entry), and grouping all API changes together seems nicer (to only require a single adaptation step by the API consumer).

PR summary

PR checklist

@anntzeranntzerforce-pushed thedvi2ft branch 4 times, most recently from7a760d1 to45eae37CompareApril 1, 2025 07:51
@anntzeranntzer marked this pull request as draftApril 6, 2025 08:21
@anntzeranntzer marked this pull request as ready for reviewApril 15, 2025 06:26
@anntzeranntzerforce-pushed thedvi2ft branch 2 times, most recently from99185ed to48be1caCompareApril 17, 2025 10:06
In89a7e19, an API for converting "dvi glyph indices" (as storedin a dvi file) to FreeType-compatible keys (either "indices intothe native charmap" or "glyph names") was introduced.  It wasintended that end users (i.e., backends) would check the type of`text.glyph_name_or_index` ((A) int or (B) str) and load the glyphaccordingly ((A) `FT_Set_Charmap(native_cmap); FT_Load_Char(index);` or(B) `FT_Load_Glyph(FT_Get_Name_Index(name));`); however, with the futureintroduction of {xe,lua}tex support, this kind of type checking becomesinconvenient, because {xe,lua}tex's "dvi glyph indices", which aredirectly equal to FreeType glyph indices (i.e. they would be loaded with`FT_Load_Glyph(index);`), would normally also be converted to ints.This PR introduces a new API (`Text.index`) that performs this mapping(via the new `DviFont._index_dvi_to_freetype`), always mapping toFreeType glyph indices (i.e. one can always just call `FT_Load_Glyph`on the result).  To do so, in case (A) it loads itself the nativecharmap (something the end user needed to do by themselves previously)and performs the cmap-to-index conversion (`FT_Get_Char_Index`)previously implicit in `FT_Load_Char`; in case (B) it performs itselfthe name-to-index conversion (`FT_Get_Name_Index`).  When {xe,lua}texsupport is introduced in the future, `_index_dvi_to_freetype` willjust return the index as is.The old APIs are not deprecated yet, as other changes will occur for{xe,lua}tex support (e.g. font_effects will go away and be replaced by`.font.effects`, as {xe,lua}tex don't store that info in the pdftexmapentry), and grouping all API changes together seems nicer (to onlyrequire a single adaptation step by the API consumer).
Comment on lines +649 to +651
# - if no ".enc" file is specified, then the font must be a Type 1
# font, and dvi indices directly index into the font's CharStrings
# vector.
Copy link
Member

Choose a reason for hiding this comment

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

just checking but is this why this step is no longer needed:index = t1_encodings[font][glyph_name_or_index]

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This still happens at the bottom:self._encoding = face._get_t1_encoding_vector() (likewise caching the value of the encoding vector, but this now occurs on the DviFont object) thenreturn self._encoding[idx].

if self._encoding is None:
psfont = PsfontsMap(find_tex_file("pdftex.map"))[self.texname]
if psfont.filename is None:
raise ValueError("No usable font file found for {} ({}); "
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a test for coverage?

Copy link
ContributorAuthor

@anntzeranntzerMay 7, 2025
edited
Loading

Choose a reason for hiding this comment

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

This gets further refactored in the followup PR#29939 into DviFont.path, whichdoes have test coverage (because it is also used elsewhere -- seehttps://app.codecov.io/gh/matplotlib/matplotlib/pull/29939#4c703021fcf83cd901550e2c525d78ae-R733). I can move code around so that the intermediate stage also has full coverage if you prefer, but this split seems more logical to me.

@story645story645 merged commit3da6ea9 intomatplotlib:mainMay 8, 2025
40 checks passed
@anntzeranntzer deleted the dvi2ft branchMay 8, 2025 16:41
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@story645story645story645 left review comments

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

3 participants
@anntzer@QuLogic@story645

[8]ページ先頭

©2009-2025 Movatter.jp