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

Improve usability of dviread.Text by third parties.#22609

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
oscargus merged 1 commit intomatplotlib:mainfromanntzer:dvifonthelpers
Apr 19, 2022

Conversation

anntzer
Copy link
Contributor

dviread.Text specifies individual glyphs in parsed dvi files; this is
used by the pdf and svg backends (via textpath, for svg) to parse the
result of usetex-compiled strings and embed the right glyphs at the
right places in the output file (as a reminder, agg currenly uses dvipng
to rasterize the dvi file, and the ps backend relies on pstricks).
Unfortunately, if third-party backends (e.g. mplcairo) want to do use
the same strategy as pdf/svg, then they need to jump through a few hoops
(e.g. understand PsfontsMap and find_tex_font) and use some private APIs
(_parse_enc), as explained below. Try to improve the situation, by
adding some methods on the Text class (which may later allow deprecating
PsfontsMap and find_tex_font as public API).

First, the actual font to be used is speficied via the.font
attribute, which itself has a.texname which itself must be used as
a key intoPsfontsMap(find_tex_font("pdftex.map")) to get the actual
font path (and some other info). Instead, just provide a.font_path
property. pdftex.map can also require that the font be "slanted" or
"extended" (that's some of the "other info), lift that as well to
.font_effects. The.font attribute has a.size; also we can lift
up to.font_size. Altogether, this will allow making.font private
(later) -- except for the fact that Text is a namedtuple so deprecating
fields is rather annoying.

The trickiest part is actually specifying what glyph to select from the
font. dvi just gives us an integer, whose interpretation depends again
on pdftex.map. If pdftex.map specifies "no encoding" for the font, then
the integer is the "native glyph index" of the font, and should be
passed as-is to FreeType's FT_Load_Char (after selecting the native
charmap). If pdftex.map does specify an encoding, then that's a file
that needs to be separately loaded, parsed (with _parse_enc), and
ultimately converts the index into a glyph name (which can be passed to
FreeType's FT_Load_Glyph). Altogether, from the PoV of the end user,
the "glyph specification" is thus either an int (a native charmap index)
or a str (a glyph name); thus, provide.glyph_spec which is that API.

As an example of using that API, see the changes to textpath.py.


I probably won't have too much time to hash out the best API here (well, I'm OK with the one I wrote, but perhaps better choices are possible) in the coming days, but just posting this out in response to#22127, as this is, I think, the way towards tightening the dviread public API while consolidating the useful functionality for third parties.

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

@oscargus
Copy link
Member

FWIW, to me, it seems to make sense. But since I generally do not have that strong opinions (knowledge) about proper API, I wait with approval...

@tacaswelltacaswell added this to thev3.6.0 milestoneMar 22, 2022
Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

Anybody can merge after CI pass.

dviread.Text specifies individual glyphs in parsed dvi files; this isused by the pdf and svg backends (via textpath, for svg) to parse theresult of usetex-compiled strings and embed the right glyphs at theright places in the output file (as a reminder, agg currenly uses dvipngto rasterize the dvi file, and the ps backend relies on pstricks).Unfortunately, if third-party backends (e.g. mplcairo) want to do usethe same strategy as pdf/svg, then they need to jump through a few hoops(e.g. understand PsfontsMap and find_tex_font) and use some private APIs(_parse_enc), as explained below.  Try to improve the situation, byadding some methods on the Text class (which may later allow deprecatingPsfontsMap and find_tex_font as public API).First, the actual font to be used is speficied via the `.font`attribute, which itself has a `.texname` which itself must be used asa key into `PsfontsMap(find_tex_font("pdftex.map"))` to get the actualfont path (and some other info).  Instead, just provide a `.font_path`property. pdftex.map can also require that the font be "slanted" or"extended" (that's some of the "other info), lift that as well to`.font_effects`.  The `.font` attribute has a `.size`; also we can liftup to `.font_size`.  Altogether, this will allow making `.font` private(later) -- except for the fact that Text is a namedtuple so deprecatingfields is rather annoying.The trickiest part is actually specifying what glyph to select from thefont.  dvi just gives us an integer, whose interpretation depends againon pdftex.map.  If pdftex.map specifies "no encoding" for the font, thenthe integer is the "native glyph index" of the font, and should bepassed as-is to FreeType's FT_Load_Char (after selecting the nativecharmap).  If pdftex.map does specify an encoding, then that's a filethat needs to be separately loaded, parsed (with _parse_enc), andultimately converts the index into a glyph name (which can be passed toFreeType's FT_Load_Glyph).  Altogether, from the PoV of the end user,the "glyph specification" is thus either an int (a native charmap index)or a str (a glyph name); thus, provide `.glyph_name_or_index` which isthat API.As an example of using that API, see the changes to textpath.py.
@oscargusoscargus merged commitc6c7ec1 intomatplotlib:mainApr 19, 2022
@anntzeranntzer deleted the dvifonthelpers branchApril 19, 2022 09:49
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@timhoffmtimhoffmtimhoffm approved these changes

@oscargusoscargusoscargus approved these changes

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

Successfully merging this pull request may close these issues.

4 participants
@anntzer@oscargus@tacaswell@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp