-
Notifications
You must be signed in to change notification settings - Fork 88
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
pycairo based rewrite of the drawing examples. #55
Conversation
Should work also with cairocffi. TODO/Limitations: - glyph-mono+alpha requires libtiff on small-endian platforms for mono-rendering to bitswap correctly. It may be possible to use FT_Bitmap_Convert() instead. TODO - wordle requires pycairo 1.11+ (released only on 2017-04-09) for the overlap check, and does not pack as tightly. Further work. Changing paint color/alpha also not seem to work. Investigate.
The liftiff-based workaround is not as bad as it sounds since python's PIL requires it. That Image.show() works at all means libtiff is around. Writing with FT_Bitmap_Convert likely will be slower. |
Apparently Ubuntu/Debian has been shipping the region_t addition for some years for python 3 for the overlap check, so if you are on Ubuntu/Debian and using python 3, the wordle example may work as is without upgrading pycairo. Fedora certainly does not ship the patch. |
…pycairo The worlde example no longer requires pycairo 1.11+ . It now packs as tightly as the old (and still faster). The tight-packing check depends on the background being black, so that's changed. Still to investigate: The different tiles should have different alphas.
This fixes the last issue; I don't particularly want to workaround the libtiff dependency for mono(1-bit) drawing, so this is all. |
To try to get an exact match, I changed the number of words back to 100, seed the random number to be the same, plus this change (the original example flp the y axis a few times...):
and get this comparison from imagemagick's compare. This shows that the first few tiles from the center of the spiral are identical, but pixel differences do accumulate, and after about 5 tiles, the differences are enough that the tiling of the spirals no longer matches. Just for interest. I cannot get a time comparison - the cairo based example is possibly about 20x faster, |
…nd always succeed, unlike _Get_BBox())
Finished. Please review and merge. @rougier |
updating ft_enums/__init__.py to include new FT_CURVE_TAGS
This can now process glyphs from well-behaved postscript fonts such as MinionPro-Regular.otf from Adobe acrobat reader.
The outline should be drawn to the box of the bitmap instead of the other way round. The two boxes happen to be almost symmetrically placed for g in Vera but to one side for g from MinionPro-Regular.otf .
@rougier Added 8 commits, a few to do with the review and a few fixes the cubic curve/alignments. I don't think there are any important issues; so I'd say just merge. |
Nope, still need to test. And to test, I need to instal pycairo > 1.10. Unfortunately the "official" version from https://www.cairographics.org/pycairo/ seems to be stuck at 1.10.0. What version do you use actually? |
Although I mentioned at the beginning pycairo 1.11+ is needed, I have since worked around that.
If you are on python 2.x, python 1.10 is suficient - I think I ran all of them with just 1.10 as shipped by Fedora
just fine, with python 2.x .
pycairo 1.10 for python 3.x lacks one or two things so, If you are on python 3.x,
a few examples (the later/more complicated ones)
needs python 1.11+ from https://github.com/pygobject/pycairo .
…--------------------------------------------
On Thu, 4/5/17, Nicolas P. Rougier <notifications@github.com> wrote:
Nope, still need test and to
test, I need to instal pycairo > 1.10. Unfortunately the
"official" version from https://www.cairographics.org/pycairo/
seems to be stuck at 1.10.0. What version do you use
actually?
|
Beside the `try catch`, I had a look at what python 3's older pycairo is exactly doing, and the change log.
That "Surface.get_data: Not Implemented yet." itself is a typo. Somebody just forgot to change
"Surface.get_data" to "ImageSurface.get_data" . This method is present but always throws in the
in the python 3 + older pycairo combo. I wish it is just missing. As it is, one only know by trying to run that method and to see if it works.
Not pretty.
Version check is unreliable - python 2 + pycairo 1.10.0 works, python 3 + pycairo 1.10.0 (stock) does not. Besides, some distros carry extra patches for 1.10.0 ... so even the python 3 + pycairo 1.10.0 combo may work, depending on what distro you use. So there isn't much one can do, beyond just try and catch the actual run. At least now one get told pycairo is too old, and where to download.
|
No luck in installing pycairo on OSX. Need to investigate. I'll merge and see that later. |
That's a pity. Do you already have cairo instead from homebrew or macport? It is not trivial to build cairo by hand. The last time I cross-compile cairo for mac was a bit over a year ago. You need to have libpng, freetype, fontconfig, pixman, first, in that order. and possibly some of g*, such as glib2 . After that then you can talk about pycairo. I suspect you can get pycairo via homebrew/macport? That's easier. May not be the latest but as I said, if you use python 2.x, the antique version pycairo works. Seems max os x still ships multiple versions of python? So many things on linux depend on cairo, it is quite trivial on linux. Oh, and now they are on github, and fairly responsive/active again under a new team, https://github.com/pygobject/pycairo , I am sure they want to know about difficulty of installing. |
I'm using Python 3. I tried the homebrew version (that works) but it is stuck at 1.10. Same from pip. From latest release, I got an error when building:
I need to investigate when I've some free time. |
It was a missing extern in the end. Build is fine now. |
I see you already filled the sierra build issue and had it merged ( pygobject/pycairo#36 ). I was going to filed & @ you to supply the details. Turn out I haven't pulled since clone so my pycairo is still at v1.12.0-5-g29805af at two weeks ago; the line affecting you was added on Tuesday this week. Wouldn't have helped as that still builds fine on linux. You have found an interesting issue with the emoji font. version 10.0d3e2 (shipped with Yosemite I think, the one I usually test with) is okay; I grabbed a ttc from the internet, supposedly 12.0d17e1 , and it shows as yours - The stray pixels are real; but the So the couple of stray pixels seems to be apple's flaw in updating the font bettween Yosemite and Sierra; the extra-shadow is a bug in pngtopam (at least on Linux). Do you have pngtopam on Mac OS X? try 'pngtopam emoji-color-cairo.png > broken.ppm' then display the latter. |
Using ImageMagick and converting the png to ppm I get the broken image so it's unlikely a bug if the same extra shadow appears using two different converters. |
It is not two different converters - imagemagick calls pngto* . Try moving your pngto* programs aside, and you will find that imagemagick stops working. You are seeing the same bug. It is one bug, in pngtopam . Try using somerthing that does not call pngto* . On linux, imagemagick calls pngto* inside libMagickCore . |
Didn't know that. Using the |
I used xv and gimp to looked at it also. xv is older than imagemagick so I am fairly sure it doesn't use it, but I don't expect you to have xv since it is X11 based. gimp doesn't show the extra shadow either. Surely on Mac OS X there are image viewers which does not use imagemagick? Since python PIL's |
It seems that I was wrong. PIL has its own png reader ( PIL/PngImagePlugin.py ) . So we do have two sets of applications, PIL and imagemagick on oneside, xv and gimp on the other, which reads the png differently.
|
Okay, I think I got to the problmem with the alpha channel. PIL Image has its own image writing code ( PIL/PpmImagePlugin.py , PIL/BmpImagePlugin.py ) to saves to bmp or ppm , before launching the display code. The image writing code ignore alphas. So the thing is that programs which ignores the alpha channel sees the extra shadow. And you do have 3 programs which ignore the alpha channel, convert in its default mode, PIL, and netpbm-progs. Apple put some garbage there and also says that part is transparent, that's pretty much it. |
Issuing a pull for the display problem - @rougier : would be nice if you get it a try on Mac os . |
edit I wanted to do strikethrough to keep the paragraph but indicates that the below nolonger applies.
Already fixed by further commits later.