rougier / freetype-py

Python binding for the freetype library
Other
305 stars 88 forks source link

Make cairo based examples more beginner friendly. #115

Open Suzumizaki opened 4 years ago

Suzumizaki commented 4 years ago

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:

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

Tested with:

Thanks.

HinTak commented 4 years ago

I don't think you should relocate those files; they depend on Vera.tff and VeraMono.tff in the current directory, and I also don't like that you are "demoting" cairo based examples versus graph-plotting Pillow-based, putting them into a sub-directory - they are equal and different ways of drawing.

This apparently probably means you perhaps mistakenly always run "run_all_examples_with_cario.py" in the directory above, where the two fonts are located ... like "./with_cairo/run_all_examples_with_cario.py" , or some other PATH-based magic ?

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

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.

pycairo was unmaintained/under-maintained, and had python 2/3 forks, when I re-wrote the examples - yes, I wrote all of the cairo examples, to teach myself pycairo - hence the comments about switching to cairoffi ; since then, pycairo had been updated / unified. While the maintained-status with cairoffi may be in the opposite.

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

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

On Mac OS X, AppleEmoji is located in one of the system font folders; I didn't want to hard-code the path, but it is located in /System/Library/Fonts/ or /Library/Fonts (and depending on the version of OS, ttf or ttc) . You can symlink / copy the emoji font file to the current directory to run it. (as all the examples assume the font file is in the current directory).

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.

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.

Suzumizaki commented 4 years ago

Thank you for reply quickly.

Also, if "run_all_examples_withcario.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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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.