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

New FreeType wrapper.#9763

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

Closed
anntzer wants to merge1 commit intomatplotlib:mainfromanntzer:ft2
Closed

New FreeType wrapper.#9763

anntzer wants to merge1 commit intomatplotlib:mainfromanntzer:ft2

Conversation

anntzer
Copy link
Contributor

@anntzeranntzer commentedNov 13, 2017
edited
Loading

A FreeType wrapper rewrite based on pybind11. See#5414 (which sadly appears to be abandoned) for the motivation. Also implements (essentially) aMEP14-style API (see theLayout class), which should make it fairly easy (based on my experience with mplcairo) to support complex text layout (Indic scripts#8765; Right-to-left languages) (if we accept to bring in new (optional?) dependencies). The layout class should also make mathtext rendering (a bit) faster: the current implementation requires the parser to gotwice through the string (once just to compute the extents of result, once with the actual rendering); this implementation just asks the parser to pass a list of positioned glyphs and rectangles (single pass) and does the sizing itself (with an iteration over the glyphs/rectangles, rather than an additional parsing round).

This requires a C++17 compiler, but such compilers are now directlyavailable on conda. Note, however, that Matplotlib's setupext.py does not play well with non-system compilers (#9737) so you can effectively only test this PR locally with a modern system compiler (this is also why the PR is marked [ci skip]). Solving#9737 is probably a strict prerequisite for this PR.

The new wrapper weights <1000 lines of code, which is ~3x shorter than the old ones.

Adaptation of the codebase to the new wrapper is mostly complete. Non-antialiased text rendering is currently missing (but should be easy to implement).

Although I tried to reproduce the (dubious)hinting_factor option that currently exists, I haven't actually managed to make the text layout as bad as ft2font sometime does (cf. the wiggly baselines mentioned in#5414) :-), and I don't think it's really worth trying to do that -- but that means that test images will need to be updated.

Unlike#5414, I haven't moved the wrapper to a library separate from matplotlib, because I'd rather take advantage of the FreeType-related build scripts (includinglocal_freetype) rather than replicating them.

@Kojoley
Copy link
Member

This is really cool! Every time I look into freetype/agg bindings I want them to be written with something like this.

This requires a C++17 compiler

The C++17 standard has not yet released 😉

C++11 is fully supported only by VS 2017 (and except some bugs in by VS 2015), what makes it Python 3 only if it is going to stay a part of mpl and not an independent library.

Why not use Cython? I do not see a big difference in bringingpybind11 orcython dependency.

Layout::~Layout()
{
if (!moved) {
std::for_each(glyphs.begin(), glyphs.end(), FT_Done_Glyph);
Copy link
Member

Choose a reason for hiding this comment

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

If you moved out to an emptyLayout theglyphs will be empty so no need in extra handling, you can just remove the flag and leave defaulted move constructorLayout(Layout&&) = default;, or if you are for some reason do not need to free the glyphs (after moving toLayout with some glyphs) you should just vallglyphs.clear() in move-ctor.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

std::move will not empty the first vector (why would it? the vector is in an invalid state after the move, it may well still be the same).
And as you noticed the flag is there to avoid FT_Done_Glyph'ing twice the same glyph after a move occurred.

FT_CHECK(
FT_Glyph_To_Bitmap, &glyph, FT_RENDER_MODE_NORMAL, nullptr, false);
}
auto b_glyph = reinterpret_cast<FT_BitmapGlyph>(glyph);
Copy link
Member

Choose a reason for hiding this comment

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

strict aliasing

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

namespace matplotlib::ft2 {

Face::Face(std::string const& path, double hinting_factor) :
ptr{
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand whyshared_ptr is needed if you are initializing it in the object constructor...

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Because it's a bit more convenient if a copy constructor is available (also, pybind11 requires either the move or the copy ctor to exist). So you either need to use a raw pointer and call FT_Reference_Face in the copy ctor and then FT_Done_Face on the way out, or use a shared_ptr+custom deleter and the default copy/move ctors which do the job for you.

@anntzer
Copy link
ContributorAuthor

If you want a backend binding written in the same style you should look athttps://github.com/anntzer/mplcairo... (why did I not fix Agg? because I can't find half-decent docs for Agg anywhere...).

@anntzeranntzerforce-pushed theft2 branch 6 times, most recently from13f925e tob1676d0CompareNovember 17, 2017 08:29
@Tillsten
Copy link
Contributor

I think@anntzer is right, pybind is the better choice here. In cython, one has to replicate a lot from the header files in cython declarations, which is quite nightmarish for a library like freetype. Maybe cffi could deal with it, but in my experience it also requires a lot of wrangling with complicated headers.

@anntzeranntzerforce-pushed theft2 branch 2 times, most recently from6d4ae43 to2b5d281CompareDecember 3, 2017 22:03
@anntzeranntzerforce-pushed theft2 branch 4 times, most recently froma3cc592 toaa04c71CompareJanuary 14, 2018 12:12
@anntzeranntzer modified the milestones:v2.2,v3.0Jan 17, 2018
@anntzeranntzer mentioned this pull requestJan 25, 2018
@jklymakjklymak mentioned this pull requestMar 7, 2018
4 tasks
@jklymak
Copy link
Member

Where is this at now that we are at MPL3.0?

@Kojoley
Copy link
Member

I do not have problem with pybind11 or recent C++ standards, however while we can bundle/download pybind11 it is not a case for a compiler. I can take downgrading compiler version requirement work. Will this work for you?

@anntzer
Copy link
ContributorAuthor

I don't mind making the thing C++14 compatible (this doesn't look too hard, as you mentioned); C++11 would be annoying at least because it lacks std::(experimental::)optional, haven't checked if more things are needed.
The annoying part of the work now is just the rebase, and the multiple additional rebases that will likely be needed while this wanders through reviewing ;)

@Kojoley
Copy link
Member

Isstd::optional used in the PR? It is a C++17 thing, but if it is needed for pybind11 we could try to borrowoptional from Boost/libc++ (which implementation actually does not require even C++11), and evenvariant if it is also needed.

What about C++14: Python 3.5+ on Windows requires MSVC2015+, so the problem is in some linux distros, and we can just tell to use recent Clang targeted system standard library (however it is most likely not an option for distro maintainers).

@anntzer
Copy link
ContributorAuthor

std::optional is used but we can also fallback on the older std::experimental::optional, which is also supported by pybind11, dunno how far back this lets us go compiler-wise.

@jklymakjklymak marked this pull request as draftMarch 24, 2021 23:34
@ianthomas23ianthomas23 mentioned this pull requestSep 9, 2022
13 tasks
@story645story645 modified the milestones:unassigned,needs sortingOct 6, 2022
@github-actions
Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actionsgithub-actionsbot added the status: inactiveMarked by the “Stale” Github Action labelApr 24, 2023
@anntzeranntzer deleted the ft2 branchSeptember 6, 2024 21:49
@anntzeranntzer restored the ft2 branchSeptember 6, 2024 21:49
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 12, 2024
This follows some of the idea frommatplotlib#9763.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 19, 2024
This follows some of the idea frommatplotlib#9763.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
@QuLogicQuLogic mentioned this pull requestSep 19, 2024
3 tasks
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 20, 2024
This follows some of the idea frommatplotlib#9763.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 20, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 21, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 23, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestSep 24, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestOct 2, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestOct 10, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestOct 16, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestOct 16, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
tacaswell pushed a commit to QuLogic/matplotlib that referenced this pull requestOct 18, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
tacaswell pushed a commit to QuLogic/matplotlib that referenced this pull requestOct 18, 2024
This follows some of the idea frommatplotlib#9763, but is based on code frommplcairo.Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@KojoleyKojoleyKojoley left review comments

@mdboommdboomAwaiting requested review from mdboom

Assignees
No one assigned
Labels
MEP: MEP14text handlingstatus: inactiveMarked by the “Stale” Github Actionstatus: needs rebasetopic: text
Projects
None yet
Milestone
future releases
Development

Successfully merging this pull request may close these issues.

6 participants
@anntzer@Kojoley@Tillsten@jklymak@tacaswell@story645

[8]ページ先頭

©2009-2025 Movatter.jp