[mapguide-commits] r1211 - trunk/MgDev/Common/Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Mar 13 15:28:04 EDT 2007


Author: traianstanev
Date: 2007-03-13 15:28:04 -0400 (Tue, 13 Mar 2007)
New Revision: 1211

Modified:
   trunk/MgDev/Common/Stylization/RS_FontEngine.cpp
   trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp
   trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h
   trunk/MgDev/Common/Stylization/StylizationEngine.cpp
Log:
Added support for path labeling in new style SymbolDefinitions. This is done using the PositioningAlgorithm tag, just like for point labeling. I had some struggle with getting vertical alignment of text to look ok -- Halfline alignment just didn't want to be exactly at the halfline. I think I understand the problem, and I added a small fix to what height is used to compute the fractional vertical offset for the string from the baseline, but we will have to see experimentally if that fix is any good.

Modified: trunk/MgDev/Common/Stylization/RS_FontEngine.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/RS_FontEngine.cpp	2007-03-13 19:24:33 UTC (rev 1210)
+++ trunk/MgDev/Common/Stylization/RS_FontEngine.cpp	2007-03-13 19:28:04 UTC (rev 1211)
@@ -458,8 +458,14 @@
         char_pos += char_width;
     }
 
+    
     //get vertical alignment delta
-    double voffset = GetVerticalAlignmentOffset(valign, tm.font, tm.font_height, tm.font_height * 1.05, 1);
+    //return value will be positive if y goes down and negative if y goes up 
+    //i.e. it's the offset we need to apply to y in the coordinate system of the 
+    //renderer
+    double voffset = GetVerticalAlignmentOffset(valign, tm.font, 
+        tm.text_height, //for path labeling, using actualy string height rather than font height works better...
+        tm.font_height * 1.05, 1);
 
     //apply vertical alignment to character position
     //horizontal alignment is ignored in this case
@@ -468,16 +474,10 @@
         // add in the rotated vertical alignment contribution
         double angle = tm.char_pos[i].anglerad;
 
-        double cs = cos(angle);
-        double sn = sin(angle);
-        double hAlignOffset = -sn*voffset;
-        double vAlignOffset =  cs*voffset;
-
-        //adjust insertion point
-        tm.char_pos[i].x += hAlignOffset;
-        tm.char_pos[i].y -= vAlignOffset;
+        tm.char_pos[i].x += voffset * sin(angle);
+        tm.char_pos[i].y += voffset * cos(angle);
     }
-
+    
     return true;
 }
 
@@ -705,7 +705,7 @@
     double em_square_size = font->m_units_per_EM;
     double font_ascent    = font->m_ascender * actual_height / em_square_size;
     double font_descent   = font->m_descender * actual_height / em_square_size;
-    double font_capline   = font_ascent;
+    double font_capline   = actual_height;
 
     switch (vAlign)
     {

Modified: trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp	2007-03-13 19:24:33 UTC (rev 1210)
+++ trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp	2007-03-13 19:28:04 UTC (rev 1211)
@@ -3,6 +3,7 @@
 #include "SE_Include.h"
 #include "SE_PositioningAlgorithms.h"
 #include "SE_Renderer.h"
+#include "Renderer.h"
 #include "SE_Bounds.h"
 #include "RS_FontEngine.h"
 #include <algorithm>
@@ -91,6 +92,9 @@
     //get actual feature point
     geometry->Centroid(LineBuffer::ctPoint, &cx, &cy, &dummy);
 
+    //transform the point to screen space
+    renderer->WorldToScreenPoint(cx, cy, cx, cy);
+
     //assume there is a single text label in the render symbol
     //and extract it from in there
     SE_RenderPointStyle* rstyle2 = new SE_RenderPointStyle(); //LEAK
@@ -279,6 +283,31 @@
 
     renderer->ProcessLabelGroup(candidates, 8, RS_OverpostType_FirstFit, true, NULL);
 }
+
+
+void SE_PositioningAlgorithms::PathLabels(SE_Renderer*    se_renderer, 
+                      LineBuffer*     geometry, 
+                      SE_Matrix&      xform, 
+                      SE_Style*       style, 
+                      SE_RenderStyle* rstyle, 
+                      double          mm2px
+                      )
+{
+    //This placement algorithm implements MapGuide path labels -- periodic text label along
+    //a linestring or multi line string feature, with stitching of adjacent features that have the
+    //same label
+
+
+    //assume that a single text was used in the SymbolDefinition that requests this positioning algorithm
+    SE_RenderText* rt = (SE_RenderText*)rstyle->symbol[0];
+
+    RS_LabelInfo info(0.0, 0.0, 0.0, 0.0, RS_Units_Device, rt->tdef, true);
+
+    //TODO: get rid of this dynamic_cast once we fix the class hierarchy
+    Renderer* renderer = dynamic_cast<Renderer*>(se_renderer);
+    renderer->ProcessLabelGroup(&info, 1, rt->text, RS_OverpostType_AllFit, true, geometry); 
+}
+
     
 
 void SE_PositioningAlgorithms::MultipleHighwaysShields(SE_Renderer*    renderer, 

Modified: trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h	2007-03-13 19:24:33 UTC (rev 1210)
+++ trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h	2007-03-13 19:28:04 UTC (rev 1211)
@@ -17,8 +17,15 @@
                           SE_RenderStyle* rstyle, 
                           double          mm2px
                           );
-    
 
+    static void PathLabels(SE_Renderer*    renderer, 
+                          LineBuffer*     geometry, 
+                          SE_Matrix&      xform, 
+                          SE_Style*       style, 
+                          SE_RenderStyle* rstyle, 
+                          double          mm2px
+                          );
+
     static void MultipleHighwaysShields(SE_Renderer*    renderer, 
                                         LineBuffer*     geometry, 
                                         SE_Matrix&      xform, 

Modified: trunk/MgDev/Common/Stylization/StylizationEngine.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/StylizationEngine.cpp	2007-03-13 19:24:33 UTC (rev 1210)
+++ trunk/MgDev/Common/Stylization/StylizationEngine.cpp	2007-03-13 19:28:04 UTC (rev 1211)
@@ -197,7 +197,7 @@
 
             if (!sym->positioningAlgorithm.empty() && sym->positioningAlgorithm != L"Default")
             {
-                LayoutCustomLabel(sym->positioningAlgorithm, xformGeom->xf_buffer(), tmpxform, style, rstyle, mm2px);
+                LayoutCustomLabel(sym->positioningAlgorithm, geometry, tmpxform, style, rstyle, mm2px);
             }
             else
             {
@@ -595,9 +595,10 @@
     {
         SE_PositioningAlgorithms::EightSurrounding(m_renderer, geometry, xform, style, rstyle, mm2px);
     }
-    //else if (style->positioningAlgorithm == MultipleHighwayShields)
-    //{
-    //}
+    else if (positioningAlgo == L"PathLabels")
+    {
+        SE_PositioningAlgorithms::PathLabels(m_renderer, geometry, xform, style, rstyle, mm2px);
+    }
 }
 
 //clears cached filters/styles/etc



More information about the mapguide-commits mailing list