Skip to content
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

Make cairo based examples more beginner friendly. #115

Open
Suzumizaki opened this issue Nov 27, 2019 · 5 comments
Open

Make cairo based examples more beginner friendly. #115

Suzumizaki opened this issue Nov 27, 2019 · 5 comments

Comments

@Suzumizaki
Copy link

I reformed examples which cooperating with "cairo", and placed at https://github.com/Suzumizaki/freetype-py/tree/examples_with_cairo. But I know too many fixed for one pull-request. Are there any ideas or should treat them as just for only my own use?

I did:

  • run_all_examples_with_cario.py is added. Users can test at once for now.
    • all *_cairo.py has run() function and if __name__ == '__main__': block.
    • all *-cairo.py is moved and renamed with_cairo/*_cairo.py.
  • Automatic importing cairocffi when pycairo not exists.
  • Skip Pillow/PIL.Image.show() when Pillow/PIL not exists.
  • Reformat to meet PEP8.
  • And several fixes are documented in each *.py
    • On Windows, emoji_color_cairo.py can use Segoe UI Emoji.
    • When libtiff cannot use directly, Just run python code (bitmap_to_surface.py)
    • Supports convertion from freetype.FT_PIXEL_MODE_BGRA to cairo.FORMAT_ARGB32.
    • avoid nearly-infinite loop (woodle_cairo.py).

Note:
I don't know how to correctly run emoji_color_cairo.py on Mac OS.

Tested with:

  • Both Python 3.7.5(64bit) and Python 2.7.17(32bit) on Windows 10(64bit).
  • Python 3.7.4 on Mac OS 10.14 (Mojave), except emoji_color_cairo.py.

Thanks.

@HinTak
Copy link
Collaborator

HinTak commented Nov 27, 2019 via email

@Suzumizaki
Copy link
Author

Thank you for reply quickly.

Also, if "run_all_examples_with_cario.py" is singular and different from the others, you should name it so - e.g. all capital, or starts with "00_..." etc?

I think that is not so important thing(there's only 10 samples and the filename tells what it will do), but I can accept the idea. I like '00_' prefix better than all capitals.

like "./with_cairo/run_all_examples_with_cario.py" , or some other PATH-based magic ?

Sorry I forgot to add.
but we can do like below, something problems?:

import os
cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
try:
    (... run samples ...)
finally:
    os.chdir(cwd)

if you put "if name_ ..." in one set, you should put them in the other set too - as I said, they are two different ways of drawing, and intentionally kept the same, except where the drawing codes is different.

Also, I don't think consistency is important between sets, because if differences exist we can learn more about python itself. Or, If the unifing is important, I think we should make the modules which contains only the diferences.

pycairo had been updated / unified. While the maintained-status with cairoffi may be in the opposite.

Really?! On my Windows 10, I can't install pycairo both python2/3 with pip, but I can cairocffi on both python2/3! Also I succeeded to install cairocffi on Mac OS, but haven't try pycairo on Mac. I'll try later.

I think libtiff is only used for some very edge cases - mono bitmaps?

Yes, but "glyph-mono+alpha-cairo.py (master)" does it when called with dummy arguments.
(And sorry, "glyph_mono_plus_alpha_cairo.py(mine)" does it as default. That's my fault.)

I don't think there is an infinite loop in woodle_cairo.py - ?

"Looks like infinite" case. Rarely one, but it can take over 10-times longer than major case.

Mostly I don't think you should put them into a different folder - unless you also put the other set into their own; and also I don't think you should modify only the cairo set for things like "if name_ ..." . If you add those, add them to both sets.

OK, I understand. but sorry to say, it might be somewhat hard work for me than I did. Because I have some difficulty to run 'not cairo' samples currently.

I'll possibly have a look at what you did, and selectively merge some of the ideas (like the ARGB changes) into upstreams at some point; but do ping / remind me if I don't get around to it.

Thank you for now. When I have the time to retry later, I will fix more issue splitted version of them.

@HinTak
Copy link
Collaborator

HinTak commented Dec 2, 2019

Okay, that's interesting - I am surprised that you have problens running the mathplotlib drawing set. They were the older ones, and I thought they are more platform-neutral.

Cairo's support (I meant Cairo itself, not cairo's python bindings) on windows has been historically somewhat poor - the name "Cairo" came from "Xr" (greek "X" - "chi", pronounced "kai", and "r", "rho"), for "X render", and was initially somewhat tied to X11 / unix.

@HinTak
Copy link
Collaborator

HinTak commented Dec 4, 2019

I have had a quick look at the actual code - besides relocating, you also renamed the files (changing "-" to "_" in the file names). That makes diff'ing (with git diff HEAD:example/ YOURS:examples/with_cairo - which can diff across repo and relocations) and comparing difficult...

Anyway, I think it needs to be broken down into a lot of different commits. For example, the FT_PIXEL_MODE_BGRA addition is alright, but you should not cast from FT_PIXEL_MODE_BGRA to cairo's FORMAT_ARGB32, as although they are the same on small endian platforms, strictly speaking not the same, as one is small-endian (regardless of host type) while the other is host byte-order, which is small-endian on Intel.

As I said, I'll put some of the ideas upstream gradually, when I get round to it.

@Suzumizaki
Copy link
Author

you also renamed the files (changing "-" to "_" in the file names).

Yes, because I want to run them at once from 'run_all_examples_with_cario.py', due to import statement cannot use hyphen("-") as module name. Of course as you say I should make pull-request to change only their name, if I want to do so.

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

No branches or pull requests

2 participants