-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FT2Font extension improvements #28842
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
Conversation
If you want real Pythonic enums (that actually inherit from enum.Enum) you can reuse the P11X_DECLARE_ENUM macro I wrote in mplcairo. |
2217d5f
to
a36f9c0
Compare
I can't say I understand all of that macro, but I can certainly copy it over if that's the way we want to go. |
(I don't really mind either way, but you mentioned that real enums may be better, so I suggested it. I can also try to explain better how it works...) |
a36f9c0
to
ee7082b
Compare
The failure in the docs actually shows the confusion with the "just a bunch of constants" approach: matplotlib/galleries/examples/misc/ftface_props.py Lines 49 to 63 in 9675122
Only Bold and Italic are style flags; the rest are face flags, and checking them as they are here would always return False. Also, given that the enum values are bitfields already, not bit positions, the math there doesn't make sense. |
On second reading, I have some understanding of it all. It would be nice though if I could add a docstring to each class (as done here), and avoid the C++ enum (but I think I need this one for the |
ee7082b
to
082b797
Compare
I guess to add a docstring you need to do something like |
082b797
to
6a3b9fe
Compare
Yep, looks like that worked nicely.
I started making a copy without the |
ee46b09
to
d3b6c9d
Compare
|
||
The following constants are now part of `.ft2font.Kerning`: | ||
|
||
- ``KERNING_DEFAULT`` |
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.
perhaps note that the new name doesn't include KERNING_; ditto for LOAD_.
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.
Done.
src/_enums.h
Outdated
auto const& [py_base_cls, pairs] = | ||
spec.cast<std::pair<std::string, py::object>>(); | ||
mod.attr(py::cast(py_name)) = spec = | ||
py::module::import("pydoc").attr("locate")(py_base_cls)( |
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.
You can probably use pkgutil.resolve_name here instead of the older and undocumented pydoc.locate (though both would work).
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.
Or should we just hard-code this coming from enum
(and only provide the class name to the macro)?
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.
That's probably fine too, anything works here...
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.
OK, I just did the hard-coding then, and added more explicit docs about it.
ed46569
to
016a7b4
Compare
Ah, apparently using |
016a7b4
to
7fd09b7
Compare
If I've understood the remaining failure, MSVC doesn't expand |
You likely need to pass |
OK, I checked and |
c7d1d03
to
437dfc0
Compare
So this is failing on AppVeyor because we're still on the 2017 image; I opened #28869 separately to see if we can bump to the 2019 one. |
437dfc0
to
52effce
Compare
52effce
to
3e73e48
Compare
We're passing now that AppVeyor has been updated. |
2096a3a
to
69c873d
Compare
69c873d
to
200b849
Compare
200b849
to
bc2b853
Compare
Port things to numpydoc, and add additional explanation where possible.
This follows some of the idea from matplotlib#9763, but is based on code from mplcairo. Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
Unfortunately, FreeType doesn't define this as an enum of any sort, just as a bunch of macro `#define`s. So we have to make our own for pybind11 to bind.
bc2b853
to
5864017
Compare
sorry, took two tries to get the rebase right. |
PR summary
This does two things:
ft2font
, and follow numpydoc style.Enum
-like objects.Unfortunately,This is based on the implementation in New FreeType wrapper. #9763 and mplcairo, but extended to all the flags as well.pybind11
doesn't support Python's new-ishEnum
class, but it should be a reasonable approximation.The
Enum
change still accepts plain integers, but raises a deprecation warning (as does accessing those constants from the module.)I have not written an API change note in case we don't want to do this.We may also want to mark the deprecation as pending.PR checklist