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

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Mar 12 16:02:07 EDT 2007


Author: traianstanev
Date: 2007-03-12 16:02:07 -0400 (Mon, 12 Mar 2007)
New Revision: 1202

Modified:
   trunk/MgDev/Common/Stylization/LabelRenderer.cpp
   trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp
   trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h
   trunk/MgDev/Common/Stylization/StylizationEngine.cpp
Log:
Fixed a y inversion bug with the code that generates candidate positions for point labels. Updated some of the label debugging code.

Modified: trunk/MgDev/Common/Stylization/LabelRenderer.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/LabelRenderer.cpp	2007-03-12 17:53:22 UTC (rev 1201)
+++ trunk/MgDev/Common/Stylization/LabelRenderer.cpp	2007-03-12 20:02:07 UTC (rev 1202)
@@ -349,6 +349,17 @@
 //////////////////////////////////////////////////////////////////////////////
 void LabelRenderer::AddExclusionRegion(RS_F_Point* pts, int npts)
 {
+
+#ifdef DEBUG_LABELS
+    LineBuffer lb(5);
+    lb.MoveTo(pts[0].x, pts[0].y);
+    lb.LineTo(pts[1].x, pts[1].y);
+    lb.LineTo(pts[2].x, pts[2].y);
+    lb.LineTo(pts[3].x, pts[3].y);
+    lb.Close();
+    m_serenderer->DrawScreenPolyline(&lb, 0xffff0000, 3.0);
+#endif
+
     RS_F_Point* tmp = (RS_F_Point*)alloca(npts * sizeof(RS_F_Point));
 
     //convert back to mapping space since the overpost manager uses mapping space
@@ -427,13 +438,13 @@
 
 #ifdef DEBUG_LABELS
     // this debugging code draws a box around the label (using its bounds)
-    RS_D_Point dpts[4];
-    for (int j=0; j<4; ++j)
-    {
-        dpts[j].x = (int)fpts[j].x;
-        dpts[j].y = (int)fpts[j].y;
-    }
-    gdImagePolygon((gdImagePtr)m_renderer->GetImage(), (gdPointPtr)dpts, 4, ConvertColor((gdImagePtr)m_renderer->GetImage(), info.m_tdef.color()));
+        LineBuffer lb(5);
+        lb.MoveTo(fpts[0].x, fpts[0].y);
+        lb.LineTo(fpts[1].x, fpts[1].y);
+        lb.LineTo(fpts[2].x, fpts[2].y);
+        lb.LineTo(fpts[3].x, fpts[3].y);
+        lb.Close();
+        m_serenderer->DrawScreenPolyline(&lb, info.m_tdef.color().argb(), 0.0);
 #endif
 
     //-------------------------------------------------------
@@ -493,7 +504,14 @@
     if (check)
     {
         if (OverlapsStuff(fpts, 4))
+        {
+            //here are done with the style and we free it.
+            //it was cloned when it was passed to the LabelRenderer.
+            //delete info.m_sestyle;
+            //info.m_sestyle = NULL;
+
             return false;
+        }
     }
 
     //add bounds to exclusion regions if needed
@@ -511,7 +529,6 @@
         m_serenderer->DrawSymbol(info.m_sestyle->symbol, m, angle);
 
 #ifdef DEBUG_LABELS
-        //debug -- draw the bounds also
         LineBuffer lb(5);
         lb.MoveTo(fpts[0].x, fpts[0].y);
         lb.LineTo(fpts[1].x, fpts[1].y);
@@ -519,10 +536,14 @@
         lb.LineTo(fpts[3].x, fpts[3].y);
         lb.Close();
         m_serenderer->DrawScreenPolyline(&lb, 0xff000000, 0.0);
-        //end debug
 #endif
     }
 
+    //here are done with the style and we free it.
+    //it was cloned when it was passed to the LabelRenderer.
+    //delete info.m_sestyle;
+    //info.m_sestyle = NULL;
+
     return true;
 }
 

Modified: trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp	2007-03-12 17:53:22 UTC (rev 1201)
+++ trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.cpp	2007-03-12 20:02:07 UTC (rev 1202)
@@ -23,7 +23,7 @@
 
 //recomputes the bounds of an SE_RenderPointStyle that contains a text
 //whose alignment we have messed with
-void UpdateStyleBounds(SE_RenderPointStyle* st, double cx, double cy, SE_Renderer* renderer)
+void UpdateStyleBounds(SE_RenderPointStyle* st, SE_Renderer* renderer)
 {
     SE_RenderText* txt = ((SE_RenderText*)st->symbol[0]);
     
@@ -73,7 +73,7 @@
     st->bounds->max[1] = rotatedBounds.maxy;
 }
 
-void SE_PositioningAlgorithms::EightBall(SE_Renderer*    renderer, 
+void SE_PositioningAlgorithms::EightSurrounding(SE_Renderer*    renderer, 
                                          LineBuffer*     geometry, 
                                          SE_Matrix&      xform, 
                                          SE_Style*       style, 
@@ -160,7 +160,7 @@
 
     w += offset;
     h += offset;
-    
+
     bool useBounds = symbol_bounds.IsValid();
     if (useBounds)
     {
@@ -234,47 +234,48 @@
 
     //OK, who says I can't write bad code? Behold:
     SE_LabelInfo candidates[8];
+    double yScale = renderer->GetFontEngine()->_Yup() ? 1.0 : -1.0; //which way does y go in the renderer?
 
     SE_RenderPointStyle* st0 = DeepClonePointStyle(rstyle2);
     ((SE_RenderText*)st0->symbol[0])->tdef.halign() = RS_HAlignment_Left;
     ((SE_RenderText*)st0->symbol[0])->tdef.valign() = RS_VAlignment_Half;
-    UpdateStyleBounds(st0, cx + op_pts[0], cy + op_pts[1], renderer);
-    candidates[0] = SE_LabelInfo(cx + op_pts[0], cy + op_pts[1], 0, 0, RS_Units_Device, 0.0, st0);
+    UpdateStyleBounds(st0, renderer);
+    candidates[0] = SE_LabelInfo(cx + op_pts[0], cy + op_pts[1]*yScale , 0, 0, RS_Units_Device, 0.0, st0);
 
     SE_RenderPointStyle* st1 = DeepClonePointStyle(st0);
     ((SE_RenderText*)st1->symbol[0])->tdef.valign() = RS_VAlignment_Descent;
-    UpdateStyleBounds(st1, cx + op_pts[2], cy + op_pts[3], renderer);
-    candidates[1] = SE_LabelInfo(cx + op_pts[2], cy + op_pts[3], 0, 0, RS_Units_Device, 0.0, st1);
+    UpdateStyleBounds(st1, renderer);
+    candidates[1] = SE_LabelInfo(cx + op_pts[2], cy + op_pts[3]*yScale, 0, 0, RS_Units_Device, 0.0, st1);
 
     SE_RenderPointStyle* st2 = DeepClonePointStyle(st1);
     ((SE_RenderText*)st2->symbol[0])->tdef.halign() = RS_HAlignment_Center;
-    UpdateStyleBounds(st2, cx + op_pts[4], cy + op_pts[5], renderer);
-    candidates[2] = SE_LabelInfo(cx + op_pts[4], cy + op_pts[5], 0, 0, RS_Units_Device, 0.0, st2);
+    UpdateStyleBounds(st2, renderer);
+    candidates[2] = SE_LabelInfo(cx + op_pts[4], cy + op_pts[5]*yScale, 0, 0, RS_Units_Device, 0.0, st2);
 
     SE_RenderPointStyle* st3 = DeepClonePointStyle(st2);
     ((SE_RenderText*)st3->symbol[0])->tdef.halign() = RS_HAlignment_Right;
-    UpdateStyleBounds(st3, cx + op_pts[6], cy + op_pts[7], renderer);
-    candidates[3] = SE_LabelInfo(cx + op_pts[6], cy + op_pts[7], 0, 0, RS_Units_Device, 0.0, st3);
+    UpdateStyleBounds(st3, renderer);
+    candidates[3] = SE_LabelInfo(cx + op_pts[6], cy + op_pts[7]*yScale, 0, 0, RS_Units_Device, 0.0, st3);
 
     SE_RenderPointStyle* st4 = DeepClonePointStyle(st3);
     ((SE_RenderText*)st4->symbol[0])->tdef.valign() = RS_VAlignment_Half;
-    UpdateStyleBounds(st4, cx + op_pts[8], cy + op_pts[9], renderer);
-    candidates[4] = SE_LabelInfo(cx + op_pts[8], cy + op_pts[9], 0, 0, RS_Units_Device, 0.0, st4);
+    UpdateStyleBounds(st4, renderer);
+    candidates[4] = SE_LabelInfo(cx + op_pts[8], cy + op_pts[9]*yScale, 0, 0, RS_Units_Device, 0.0, st4);
 
     SE_RenderPointStyle* st5 = DeepClonePointStyle(st4);
     ((SE_RenderText*)st5->symbol[0])->tdef.valign() = RS_VAlignment_Ascent;
-    UpdateStyleBounds(st5, cx + op_pts[10], cy + op_pts[11], renderer);
-    candidates[5] = SE_LabelInfo(cx + op_pts[10], cy + op_pts[11], 0, 0, RS_Units_Device, 0.0, st5);
+    UpdateStyleBounds(st5, renderer);
+    candidates[5] = SE_LabelInfo(cx + op_pts[10], cy + op_pts[11]*yScale, 0, 0, RS_Units_Device, 0.0, st5);
 
     SE_RenderPointStyle* st6 = DeepClonePointStyle(st5);
     ((SE_RenderText*)st6->symbol[0])->tdef.halign() = RS_HAlignment_Center;
-    UpdateStyleBounds(st6, cx + op_pts[12], cy + op_pts[13], renderer);
-    candidates[6] = SE_LabelInfo(cx + op_pts[12], cy + op_pts[13], 0, 0, RS_Units_Device, 0.0, st6);
+    UpdateStyleBounds(st6, renderer);
+    candidates[6] = SE_LabelInfo(cx + op_pts[12], cy + op_pts[13]*yScale, 0, 0, RS_Units_Device, 0.0, st6);
 
     SE_RenderPointStyle* st7 = DeepClonePointStyle(st6);
     ((SE_RenderText*)st7->symbol[0])->tdef.halign() = RS_HAlignment_Left;
-    UpdateStyleBounds(st7, cx + op_pts[14], cy + op_pts[15], renderer);
-    candidates[7] = SE_LabelInfo(cx + op_pts[14], cy + op_pts[15], 0, 0, RS_Units_Device, 0.0, st7);
+    UpdateStyleBounds(st7, renderer);
+    candidates[7] = SE_LabelInfo(cx + op_pts[14], cy + op_pts[15]*yScale, 0, 0, RS_Units_Device, 0.0, st7);
 
     renderer->ProcessLabelGroup(candidates, 8, RS_OverpostType_FirstFit, true, NULL);
 }

Modified: trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h
===================================================================
--- trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h	2007-03-12 17:53:22 UTC (rev 1201)
+++ trunk/MgDev/Common/Stylization/SE_PositioningAlgorithms.h	2007-03-12 20:02:07 UTC (rev 1202)
@@ -10,7 +10,7 @@
 
 public:
 
-    static void EightBall(SE_Renderer*    renderer, 
+    static void EightSurrounding(SE_Renderer*    renderer, 
                           LineBuffer*     geometry, 
                           SE_Matrix&      xform, 
                           SE_Style*       style, 

Modified: trunk/MgDev/Common/Stylization/StylizationEngine.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/StylizationEngine.cpp	2007-03-12 17:53:22 UTC (rev 1201)
+++ trunk/MgDev/Common/Stylization/StylizationEngine.cpp	2007-03-12 20:02:07 UTC (rev 1202)
@@ -581,7 +581,7 @@
     //here we decide which one to call based on the name of the positioning algorithm
     if (positioningAlgo == L"EightSurrounding")
     {
-        SE_PositioningAlgorithms::EightBall(m_renderer, geometry, xform, style, rstyle, mm2px);
+        SE_PositioningAlgorithms::EightSurrounding(m_renderer, geometry, xform, style, rstyle, mm2px);
     }
     //else if (style->positioningAlgorithm == MultipleHighwayShields)
     //{



More information about the mapguide-commits mailing list