mapnik / Cascadenik

Cascading Sheets Of Style for Mapnik
http://github.com/mapnik/Cascadenik/wiki/Cascadenik
BSD 3-Clause "New" or "Revised" License
111 stars 20 forks source link

TextSymbolizer attributes with Mapnik 2.1 #21

Open Nimn opened 12 years ago

Nimn commented 12 years ago

Mapnik 2.1 (not yet released) seems to have made changes on TextSymbolizer attributes. The attributes used by Cascadenik are now under "format" and "placements.defaults". The folowing path applied on branch mapnik2 seems to fix that:

diff --git a/cascadenik/output.py b/cascadenik/output.py
index a696df9..77a9f2b 100644
--- a/cascadenik/output.py
+++ b/cascadenik/output.py
@@ -232,7 +232,7 @@ class LineSymbolizer:

 class TextSymbolizer:
     def __init__(self, name, face_name, size, color, wrap_width=None, \
-        label_spacing=None, label_position_tolerance=None, max_char_angle_delta=None, \
+        label_spacing=None, label_position_tolerance=None, maximum_angle_char_delta=None, \
         halo_color=None, halo_radius=None, dx=None, dy=None, avoid_edges=None, \
         minimum_distance=None, allow_overlap=None, label_placement=None, \
         character_spacing=None, line_spacing=None, text_transform=None, fontset=None, \
@@ -247,7 +247,7 @@ class TextSymbolizer:
         assert wrap_width is None or type(wrap_width) is int
         assert label_spacing is None or type(label_spacing) is int
         assert label_position_tolerance is None or type(label_position_tolerance) is int
-        assert max_char_angle_delta is None or type(max_char_angle_delta) is int
+        assert maximum_angle_char_delta is None or type(maximum_angle_char_delta) is int
         assert halo_color is None or halo_color.__class__ is style.color
         assert halo_radius is None or type(halo_radius) is int
         assert dx is None or type(dx) is int
@@ -271,7 +271,7 @@ class TextSymbolizer:
         self.wrap_width = wrap_width
         self.label_spacing = label_spacing
         self.label_position_tolerance = label_position_tolerance
-        self.max_char_angle_delta = max_char_angle_delta
+        self.maximum_angle_char_delta = maximum_angle_char_delta
         self.halo_color = halo_color
         self.halo_radius = halo_radius
         self.dx = dx
@@ -312,23 +312,23 @@ class TextSymbolizer:
         sym = mapnik.TextSymbolizer(expr, self.face_name, self.size,
                                     mapnik.Color(str(self.color)))

-        sym.wrap_width = self.wrap_width or sym.wrap_width
-        sym.label_spacing = self.label_spacing or sym.label_spacing
-        sym.label_position_tolerance = self.label_position_tolerance or sym.label_position_tolerance
-        sym.max_char_angle_delta = self.max_char_angle_delta or sym.max_char_angle_delta
-        sym.halo_fill = mapnik.Color(str(self.halo_color)) if self.halo_color else sym.halo_fill
-        sym.halo_radius = self.halo_radius or sym.halo_radius
-        sym.character_spacing = self.character_spacing or sym.character_spacing
-        sym.line_spacing = self.line_spacing or sym.line_spacing
-        sym.avoid_edges = self.avoid_edges.value if self.avoid_edges else sym.avoid_edges
-        sym.force_odd_labels = self.force_odd_labels.value if self.force_odd_labels else sym.force_odd_labels
-        sym.minimum_distance = self.minimum_distance or sym.minimum_distance
-        sym.allow_overlap = self.allow_overlap.value if self.allow_overlap else sym.allow_overlap
+        sym.placements.defaults.wrap_width = self.wrap_width or sym.placements.defaults.wrap_width
+        sym.placements.defaults.label_spacing = self.label_spacing or sym.placements.defaults.label_spacing
+        sym.placements.defaults.label_position_tolerance = self.label_position_tolerance or sym.placements.defaults.label_position_tolerance
+        sym.placements.defaults.maximum_angle_char_delta = self.maximum_angle_char_delta or sym.placements.defaults.maximum_angle_char_delta
+        sym.format.halo_fill = mapnik.Color(str(self.halo_color)) if self.halo_color else sym.format.halo_fill
+        sym.format.halo_radius = self.halo_radius or sym.format.halo_radius
+        sym.format.character_spacing = self.character_spacing or sym.format.character_spacing
+        sym.format.line_spacing = self.line_spacing or sym.format.line_spacing
+        sym.placements.defaults.avoid_edges = self.avoid_edges.value if self.avoid_edges else sym.placements.defaults.avoid_edges
+        sym.placements.defaults.force_odd_labels = self.force_odd_labels.value if self.force_odd_labels else sym.placements.defaults.force_odd_labels
+        sym.placements.defaults.minimum_distance = self.minimum_distance or sym.placements.defaults.minimum_distance
+        sym.placements.defaults.allow_overlap = self.allow_overlap.value if self.allow_overlap else sym.placements.defaults.allow_overlap
         if self.label_placement:
-            sym.label_placement = mapnik.label_placement.names.get(self.label_placement,mapnik.label_placement.POINT_PLACEMENT)
+            sym.placements.defaults.label_placement = mapnik.label_placement.names.get(self.label_placement,mapnik.label_placement.POINT_PLACEMENT)
         # note-renamed in Mapnik2 to 'text_transform'
         if self.text_transform:
-            sym.text_transform = convert_enums.get(self.text_transform,mapnik.text_transform.NONE)
+            sym.format.text_transform = convert_enums.get(self.text_transform,mapnik.text_transform.NONE)
         if self.vertical_alignment:
             # match the logic in load_map.cpp for conditionally applying vertical_alignment default
             default_vertical_alignment = mapnik.vertical_alignment.MIDDLE
@@ -337,10 +337,10 @@ class TextSymbolizer:
             elif self.dy < 0.0:
                 default_vertical_alignment = mapnik.vertical_alignment.TOP

-            sym.vertical_alignment = mapnik.vertical_alignment.names.get(self.vertical_alignment,
+            sym.placements.defaults.vertical_alignment = mapnik.vertical_alignment.names.get(self.vertical_alignment,
                 default_vertical_alignment)
         if self.justify_alignment:
-            sym.justify_alignment = mapnik.justify_alignment.names.get(self.justify_alignment,
+            sym.placements.defaults.justify_alignment = mapnik.justify_alignment.names.get(self.justify_alignment,
               mapnik.justify_alignment.MIDDLE)

         if self.fontset:
@@ -349,9 +349,9 @@ class TextSymbolizer:
             sys.stderr.write('\nCascadenik debug: Warning, FontSets will be ignored as they are not yet supported in Mapnik via Python...\n')

         try:
-            sym.displacement = (self.dx or 0.0, self.dy or 0.0)
+            sym.placements.defaults.displacement = (self.dx or 0.0, self.dy or 0.0)
         except:
-            sym.displacement(self.dx or 0.0, self.dy or 0.0)
+            sym.placements.defaults.displacement(self.dx or 0.0, self.dy or 0.0)

         return sym
springmeyer commented 12 years ago

Hi @Nimn - thanks for the report/patch. Yes, Cascadenik is not up to date with latest Mapnik. The mapnik2 branch was an attempt, but it too is quite out of date.

That said, the changes between Mapnik 2.0.x and 2.1.x (unreleased) for the text_symbolizer a still in process, and therefore need to be handled on the mapnik side - basically we need backward compatibility maintained in Mapnik. See https://github.com/mapnik/mapnik/issues/1115. So, if you have time for a patch I would prefer that is it against Mapnik for the placements/format issues.

Nimn commented 12 years ago

Hi @springmeyer Actually this seems better to manage it in mapnik. I will not do it now but I try to give a look at it in the following weeks.

springmeyer commented 12 years ago

Okay, sounds good. I also previously ask @herm if he could work on this, so just check with him before you start to make sure its not already done.

herm commented 12 years ago

I will fix this in mapnik soon. Currently I have a very bad internet connection and not very much free time. But the situation will improve soon and then I'll fix it.

migurski commented 12 years ago

I handled a few of these 584aafaf, not all though, and not tested thoroughly.

springmeyer commented 12 years ago

@herm - can you post an update about when you think you can get to this?

herm commented 12 years ago

I think next week should be possible.

herm commented 12 years ago

Should be fixed in mapnik/mapnik@707052c.

migurski commented 12 years ago

Is this a backwards-incompatible change in 2.1?

herm commented 12 years ago

I added to compatibily layer for 2.1 and it will probably stay there for the whole 2.x series but it might be removed in 3.x.

nvkelso commented 11 years ago

These are priority: text-opacity/rgba, character-spacing and *-placement: internal