python-mapnik icon indicating copy to clipboard operation
python-mapnik copied to clipboard

Can't render text with pycairo

Open oliverbienert opened this issue 7 years ago • 4 comments

I successfully built python-mapnik using the mason build, according to instructions. However, pycairo test fails as already mentioned in #168. I am able to create svg as long as I don't use a TextSymbolizer. If I try to render text, then the same error occurs, no matter which font-face I declare:

python: ../../../../src/cairo-scaled-font.c:459: _cairo_scaled_glyph_page_destroy: Assertion `!scaled_font->cache_frozen' failed.

In #2675 the problem was apparently solved, but then it reappears now. This is a real show stopper and I can reproduce it on different systems.

Importing mapnik before cairo, as mentioned in #2675 also does not help.

oliverbienert avatar Nov 21 '17 21:11 oliverbienert

It is just an idea, but when I was playing with color fonts I was getting this error on some systems only when I was using these color fonts. Maybe there is some font which causes this. You can list all fonts Mapnik can see by

list(mapnik.FontEngine.face_names())

Mapnik automatically imports fonts from some system font paths. You can override it by MAPNIK_FONT_DIRECTORY:

export MAPNIK_FONT_DIRECTORY=/home/user/dev/mapnik/fonts/dejavu-fonts-ttf-2.37

talaj avatar Nov 22 '17 11:11 talaj

No, unfortunately, it doesn't matter what font I use. I registered my font folder like so:

from mapnik import register_fonts, FontEngine
custom_fonts_dir = '/usr/share/fonts/truetype'
register_fonts(custom_fonts_dir)

and tried quite a number of fonts. But it always crashes and does not render.

I'll try to compile myself and see if it works if I comment those 2 Assertion lines. But it feels like a hack.

oliverbienert avatar Nov 22 '17 16:11 oliverbienert

I've set up a debian stretch in a lxc container (using lxd) and did the following (in short):

  • Downloaded cairo, pycairo and dependencies from source (According to instructions at Linux from scratch)
  • Edited cairo-scaled-font.c and commented lines 459-460 (The 2 assertions)
  • Compiled cairo
  • Set up pycairo system wide (Don't know if this is necessary)
  • Checked out mapnik (3.0.16) and installed needed dependencies
  • Compiled mapnik
  • Created virtualenv
  • Checked out python-mapnik (3.0.16)
  • Installed pycairo in virtualenv
  • Installed python-mapnik in virtualenv

Now I have a working solution, the fonts are rendered as expected. However, I still think that this is a hack for those assertions are there for a reason. And I still want to know why those assertions fail in the first place.

oliverbienert avatar Nov 23 '17 12:11 oliverbienert

Hi everyone!, has anyone had success regarding the problem? I have tried different paths and I can not render text. I tried to comment the lines as indicated by @oliverbienert , but I ended up in another error. (sorry by strange english)

avillagran-geo avatar Sep 03 '18 14:09 avillagran-geo