[mapguide-commits] r9866 - sandbox/adsk/trunk/Common/Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Aug 31 18:53:34 PDT 2021


Author: simonliu
Date: 2021-08-31 18:53:33 -0700 (Tue, 31 Aug 2021)
New Revision: 9866

Modified:
   sandbox/adsk/trunk/Common/Stylization/RS_FontEngine.cpp
   sandbox/adsk/trunk/Common/Stylization/RS_FontEngine.h
Log:
Fix an issue that the offset of the ghost text is not proper if the font size is very small, for example, the font size is 0.4mm. 
By default, the offset of the ghost text is 0.25mm.
If the height of the font is very small, for example, 0.4mm. The 0.25mm offset is relatively big. 
And after the 0.25mm offset is converted to the value of the screen unit, 
the value is much bigger than 1 if the user zooms to see the text. In this case, 1/10 of the font height 
is used instead of 0.25mm.

Modified: sandbox/adsk/trunk/Common/Stylization/RS_FontEngine.cpp
===================================================================
--- sandbox/adsk/trunk/Common/Stylization/RS_FontEngine.cpp	2021-08-16 06:26:30 UTC (rev 9865)
+++ sandbox/adsk/trunk/Common/Stylization/RS_FontEngine.cpp	2021-09-01 01:53:33 UTC (rev 9866)
@@ -1,5 +1,5 @@
 //
-//  Copyright (C) 2004-2011 by Autodesk, Inc.
+//  Copyright (C) 2021 by Autodesk, Inc.
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of version 2.1 of the GNU Lesser
@@ -646,18 +646,9 @@
         }
     }
 
-    // calculate a 0.25 mm offset for ghosting - this value is in screen units
-    double offset = MetersToScreenUnits(tdef.font().units(), 0.00025);
+    const double offset = GetGhostTextOffset(tdef.font().units(), tdef.font().height());
+    const double screenUnitsPerPixel = m_pSERenderer->GetScreenUnitsPerPixel();
 
-    // truncate the offset to the nearest pixel so we get uniform ghosting around
-    // the string (the same number of pixels on each side after rendering)
-    double screenUnitsPerPixel = m_pSERenderer->GetScreenUnitsPerPixel();
-    offset -= fmod(offset, screenUnitsPerPixel);
-
-    // finally, make sure we have at least one pixel's worth of offset
-    if (offset < screenUnitsPerPixel)
-        offset = screenUnitsPerPixel;
-
     const RS_Font* pFont = tm.font;
     RS_TextDef tmpTDef = tdef;
     double fontHeight = tm.font_height;
@@ -897,18 +888,8 @@
         }
     }
 
-    // calculate a 0.25 mm offset for ghosting - this value is in screen units
-    double offset = MetersToScreenUnits(tdef.font().units(), 0.00025);
+    const double offset = GetGhostTextOffset(tdef.font().units(), tdef.font().height());
 
-    // truncate the offset to the nearest pixel so we get uniform ghosting around
-    // the string (the same number of pixels on each side after rendering)
-    double screenUnitsPerPixel = m_pSERenderer->GetScreenUnitsPerPixel();
-    offset -= fmod(offset, screenUnitsPerPixel);
-
-    // finally, make sure we have at least one pixel's worth of offset
-    if (offset < screenUnitsPerPixel)
-        offset = screenUnitsPerPixel;
-
     // draw the characters, each in its computed position
     RS_String c;
 
@@ -1164,7 +1145,39 @@
     return offsetX;
 }
 
+//////////////////////////////////////////////////////////////////////////////
+// Computes the offset of the ghosted text.
+double RS_FontEngine::GetGhostTextOffset(RS_Units fontUnit, double fontHeight)
+{
+    // calculate a 0.25 mm offset for ghosting - this value is in screen units
+    // If the height of the font is very small, for example, 0.4mm. The 0.25mm offset 
+    // is relatively big. And after the 0.25mm offset is converted to the value of the screen unit, 
+    // the value is much bigger than 1 if the user zooms to see the text. In this case, 1/10 of the font height 
+    // is used instead of 0.25mm.
+    double offsetDistance = 0.00025;
+    if (fontUnit == RS_Units_Device)
+    {
+        if (fontHeight > 0.0)
+        {
+            fontHeight /= 10.0;
+            offsetDistance = fontHeight > offsetDistance ? offsetDistance : fontHeight;
+        }
+    }
+    double offset = MetersToScreenUnits(fontUnit, offsetDistance);
 
+    // truncate the offset to the nearest pixel so we get uniform ghosting around
+    // the string (the same number of pixels on each side after rendering)
+    const double screenUnitsPerPixel = m_pSERenderer->GetScreenUnitsPerPixel();
+    offset -= fmod(offset, screenUnitsPerPixel);
+
+    // finally, make sure we have at least one pixel's worth of offset
+    if (offset < screenUnitsPerPixel)
+        offset = screenUnitsPerPixel;
+
+    return offset;
+}
+
+
 //////////////////////////////////////////////////////////////////////////////
 // Scales an input length in meters in the specified units - device or
 // mapping - to a length in screen units.

Modified: sandbox/adsk/trunk/Common/Stylization/RS_FontEngine.h
===================================================================
--- sandbox/adsk/trunk/Common/Stylization/RS_FontEngine.h	2021-08-16 06:26:30 UTC (rev 9865)
+++ sandbox/adsk/trunk/Common/Stylization/RS_FontEngine.h	2021-09-01 01:53:33 UTC (rev 9866)
@@ -1,5 +1,5 @@
 //
-//  Copyright (C) 2004-2011 by Autodesk, Inc.
+//  Copyright (C) 2021 by Autodesk, Inc.
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of version 2.1 of the GNU Lesser
@@ -87,6 +87,8 @@
 
     double GetHorizontalAlignmentOffset(RS_HAlignment hAlign, double lineWidth);
 
+    double GetGhostTextOffset(RS_Units fontUnit, double fontHeight);
+
 public:
     SE_Renderer* m_pSERenderer;
     SE_LineStroke m_frameStroke;



More information about the mapguide-commits mailing list