FontSets appear to be unsettable from Python #1483

Closed
migurski opened this Issue Sep 14, 2012 · 11 comments

Comments

Projects
None yet
2 participants
Member

migurski commented Sep 14, 2012

(this is a copy of a mail I sent to mapnik-devel, reposting here to give it an issue number)

So, I have a mapnik.Map, call it mmap:

mmap = mapnik.Map()
# etc.

Now I want to add some fonts to it, like this:

fset = mapnik.FontSet()
fset.add_face_name('Comic Sans')
fset.add_face_name('Papyrus')
mmap.append_fontset('my-set', fset)

So far, so good, on to the TextSymbolizer:

tsym = mapnik.TextSymbolizer(expression, '', size, color)
tsym.fontset = 'my-set'

Mapnik complains, it wants a FontSet instance, and throws an ArgumentError, okay:

tsym.fontset = fset

The XML output has the FontSet element with its proper name, but no "fontset-name" attribute on the symbolizer. I figure maybe the FontSet mapnik knows about is different from the one I initially fed it, so:

tsym.fontset = mmap.find_fontset('my-set')

Same deal: I get a FontSet element in my output XML, but not a "fontset-name" attribute on the symbolizer. Am I doing something wrong here? It is possible to set a fontset on a TextSymbolizer instance and have it come out in Mapnik's XML dump, right?

Owner

springmeyer commented Sep 14, 2012

Yes, should be possible. Hopefully just a bug in the symbolizer serialization. You might be able to confirm this by trying to render to an image with the map object at a reasonable zoom that contains text and if it works then it should be able to be serialized correctly. I'm away from my laptop now but can try to fix in the morning.

Member

migurski commented Sep 14, 2012

I’ll give it a run, thanks!

Member

migurski commented Sep 14, 2012

I was able to successfully render the image I expected, so I think you’re right that this is a serialization bug.

Owner

springmeyer commented Sep 14, 2012

Okay, the problem is that simply that you need to name the FontSet object in python, but you can't. So a basic fix in mapnik's python bindings are needed to allow this. Then in python if you do: fset = mapnik.FontSet('fset') it will start working.

Owner

springmeyer commented Sep 14, 2012

test added in 4973136 that will start working shortly.

Member

migurski commented Sep 14, 2012

Awesome. Would it still be necessary to repeat that name when calling mmap.append_fontset()?

Owner

springmeyer commented Sep 14, 2012

yes it will. I'd like to remove that, but I figure its too much of an api break.

Owner

springmeyer commented Sep 14, 2012

fixed in 8cfb40a, this is now in master and will work in the next release: either 2.1.1 or 2.2.x, which ever comes first.

Member

migurski commented Sep 14, 2012

I agree, and I don’t actually mind a bit of repeating myself here & there. Thanks so much for this! I’ve worked around it somewhat for current versions of Mapnik with a new TileStache provider that skips the need to serialize XML: http://tilestache.org/doc/TileStache.Goodies.Providers.Cascadenik.html

@springmeyer springmeyer pushed a commit that referenced this issue Sep 26, 2012

Dane Springmeyer after #1483 fontset is boost optional so check appropriately in load_…
…map (solves assert)
b9b97ba

@springmeyer springmeyer pushed a commit that referenced this issue Sep 26, 2012

Dane Springmeyer after #1483 fontset is boost optional so check appropriately in load_…
…map (solves assert)
e221168
Member

migurski commented Nov 18, 2012

This is not expected to work in 2.1.0 stable at this time, right? I’m running into the same problem again, and I'm guessing that it’s not fixed in the latest stable release from the Mapnik PPA.

Owner

springmeyer commented Nov 18, 2012

Right. Not 2.1.0. But the 2.1.x series (to become 2.1.1) has the fix as I see the my comments above.

@PetrDlouhy PetrDlouhy added a commit to PetrDlouhy/mapnik that referenced this issue Aug 22, 2013

@PetrDlouhy Dane Springmeyer + PetrDlouhy refactor fontsets making them optional on the symbolizer and removing…
… the dangerous default contructor - closes #1483 (TODO - consider modifying insert_fontset to only take single arg of fontset instance)
96c3b0e

@PetrDlouhy PetrDlouhy added a commit to PetrDlouhy/mapnik that referenced this issue Aug 22, 2013

@PetrDlouhy Dane Springmeyer + PetrDlouhy after #1483 fontset is boost optional so check appropriately in load_…
…map (solves assert)
a4e9871
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment