From 151da08bbe4a057a00b2d2a42d10e3e3de66c96f Mon Sep 17 00:00:00 2001
From: anv <anv@opencascade.com>
Date: Thu, 21 Sep 2017 15:15:12 +0300
Subject: [PATCH] 0029117: Adding translation of Multileader entity

Scaling of width of glyphs is added om Font_FTFont class.
Font "SimSan" is specified as fallback alias for font "NSimSan" (contains Chinese hieroglyphs).
---
 src/Font/Font_BRepFont.cxx | 13 +++++++------
 src/Font/Font_BRepFont.hxx |  7 +++++++
 src/Font/Font_FTFont.cxx   | 17 +++++++++--------
 src/Font/Font_FTFont.hxx   | 26 +++++++++++++++++---------
 src/Font/Font_FontMgr.cxx  |  3 ++-
 5 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/src/Font/Font_BRepFont.cxx b/src/Font/Font_BRepFont.cxx
index 01476bbef0..8f8dc94a7b 100755
--- a/src/Font/Font_BRepFont.cxx
+++ b/src/Font/Font_BRepFont.cxx
@@ -66,9 +66,10 @@ namespace
 
   //! Auxiliary method to convert FT_Vector to gp_XY
   static gp_XY readFTVec (const FT_Vector& theVec,
-                          const Standard_Real theScaleUnits)
+                          const Standard_Real theScaleUnits,
+                          const Standard_Real theWidthScaling = 1.0)
   {
-    return gp_XY (theScaleUnits * Standard_Real(theVec.x) / 64.0, theScaleUnits * Standard_Real(theVec.y) / 64.0);
+    return gp_XY (theScaleUnits * Standard_Real(theVec.x) * theWidthScaling / 64.0, theScaleUnits * Standard_Real(theVec.y) / 64.0);
   }
 
 }
@@ -286,8 +287,8 @@ Standard_Boolean Font_BRepFont::renderGlyph (const Standard_Utf32Char theChar,
     BRepBuilderAPI_MakeWire aWireMaker;
 
     gp_XY aPntPrev;
-    gp_XY aPntCurr = readFTVec (aPntList[aPntsNb - 1], myScaleUnits);
-    gp_XY aPntNext = readFTVec (aPntList[0], myScaleUnits);
+    gp_XY aPntCurr = readFTVec (aPntList[aPntsNb - 1], myScaleUnits, myWidthScaling);
+    gp_XY aPntNext = readFTVec (aPntList[0], myScaleUnits, myWidthScaling);
 
     bool isLineSeg = !myIsSingleLine
                   && FT_CURVE_TAG(aTags[aPntsNb - 1]) == FT_Curve_Tag_On;
@@ -299,7 +300,7 @@ Standard_Boolean Font_BRepFont::renderGlyph (const Standard_Utf32Char theChar,
     {
       aPntPrev = aPntCurr;
       aPntCurr = aPntNext;
-      aPntNext = readFTVec (aPntList[(aPntId + 1) % aPntsNb], myScaleUnits);
+      aPntNext = readFTVec (aPntList[(aPntId + 1) % aPntsNb], myScaleUnits, myWidthScaling);
 
       // process tags
       if (FT_CURVE_TAG(aTags[aPntId]) == FT_Curve_Tag_On)
@@ -383,7 +384,7 @@ Standard_Boolean Font_BRepFont::renderGlyph (const Standard_Utf32Char theChar,
         my4Poles.SetValue (1, aPntPrev);
         my4Poles.SetValue (2, aPntCurr);
         my4Poles.SetValue (3, aPntNext);
-        my4Poles.SetValue (4, gp_Pnt2d(readFTVec (aPntList[(aPntId + 2) % aPntsNb], myScaleUnits)));
+        my4Poles.SetValue (4, gp_Pnt2d(readFTVec (aPntList[(aPntId + 2) % aPntsNb], myScaleUnits, myWidthScaling)));
         Handle(Geom2d_BezierCurve) aBezier = new Geom2d_BezierCurve (my4Poles);
         if (myIsCompositeCurve)
         {
diff --git a/src/Font/Font_BRepFont.hxx b/src/Font/Font_BRepFont.hxx
index dbbf7d0c0d..51dec3d0d6 100755
--- a/src/Font/Font_BRepFont.hxx
+++ b/src/Font/Font_BRepFont.hxx
@@ -96,6 +96,13 @@ public:
   //! Notice that altering this flag clears currently accumulated cache!
   Standard_EXPORT void SetCompositeCurveMode (const Standard_Boolean theToConcatenate);
 
+  //! Setup glyph scaling along X-axis.
+  //! By default glyphs are not scaled (scaling factor = 1.0)
+  void SetWidthScaling (const float theScaleFactor)
+  {
+    myWidthScaling = theScaleFactor;
+  }
+
 public:
 
   //! @return vertical distance from the horizontal baseline to the highest character coordinate.
diff --git a/src/Font/Font_FTFont.cxx b/src/Font/Font_FTFont.cxx
index 3687b74a1c..5542baa50f 100755
--- a/src/Font/Font_FTFont.cxx
+++ b/src/Font/Font_FTFont.cxx
@@ -29,13 +29,14 @@ IMPLEMENT_STANDARD_RTTIEXT(Font_FTFont,Standard_Transient)
 // purpose  :
 // =======================================================================
 Font_FTFont::Font_FTFont (const Handle(Font_FTLibrary)& theFTLib)
-: myFTLib      (theFTLib),
-  myFTFace     (NULL),
-  myPointSize  (0U),
-  myLoadFlags  (FT_LOAD_NO_HINTING | FT_LOAD_TARGET_NORMAL),
+: myFTLib       (theFTLib),
+  myFTFace      (NULL),
+  myPointSize   (0U),
+  myWidthScaling(1.0),
+  myLoadFlags   (FT_LOAD_NO_HINTING | FT_LOAD_TARGET_NORMAL),
   myIsSingleLine(false),
-  myKernAdvance(new FT_Vector()),
-  myUChar      (0U)
+  myKernAdvance (new FT_Vector()),
+  myUChar       (0U)
 {
   if (myFTLib.IsNull())
   {
@@ -270,9 +271,9 @@ float Font_FTFont::AdvanceX (const Standard_Utf32Char theUCharNext)
   if (FT_HAS_KERNING (myFTFace) == 0 || theUCharNext == 0
    || FT_Get_Kerning (myFTFace, myUChar, theUCharNext, FT_KERNING_UNFITTED, myKernAdvance) != 0)
   {
-    return fromFTPoints<float> (myFTFace->glyph->advance.x);
+    return myWidthScaling * fromFTPoints<float> (myFTFace->glyph->advance.x);
   }
-  return fromFTPoints<float> (myKernAdvance->x + myFTFace->glyph->advance.x);
+  return myWidthScaling * fromFTPoints<float> (myKernAdvance->x + myFTFace->glyph->advance.x);
 }
 
 // =======================================================================
diff --git a/src/Font/Font_FTFont.hxx b/src/Font/Font_FTFont.hxx
index f9583e07ca..8409aad6fa 100755
--- a/src/Font/Font_FTFont.hxx
+++ b/src/Font/Font_FTFont.hxx
@@ -107,6 +107,13 @@ public:
     return myPointSize;
   }
 
+  //! Setup glyph scaling along X-axis.
+  //! By default glyphs are not scaled (scaling factor = 1.0)
+  void SetWidthScaling (const float theScaleFactor)
+  {
+    myWidthScaling = theScaleFactor;
+  }
+
   //! Compute advance to the next character with kerning applied when applicable.
   //! Assuming text rendered horizontally.
   Standard_EXPORT float AdvanceX (const Standard_Utf32Char theUCharNext);
@@ -161,16 +168,17 @@ protected:
 
 protected:
 
-  Handle(Font_FTLibrary) myFTLib;       //!< handle to the FT library object
-  FT_Face                myFTFace;      //!< FT face object
-  NCollection_String     myFontPath;    //!< font path
-  unsigned int           myPointSize;   //!< point size set by FT_Set_Char_Size
-  int32_t                myLoadFlags;   //!< default load flags
-  bool                   myIsSingleLine;//!< single stroke font flag, FALSE by default
+  Handle(Font_FTLibrary) myFTLib;        //!< handle to the FT library object
+  FT_Face                myFTFace;       //!< FT face object
+  NCollection_String     myFontPath;     //!< font path
+  unsigned int           myPointSize;    //!< point size set by FT_Set_Char_Size
+  float                  myWidthScaling; //!< scale glyphs along X-axis
+  int32_t                myLoadFlags;    //!< default load flags
+  bool                   myIsSingleLine; //!< single stroke font flag, FALSE by default
 
-  Image_PixMap           myGlyphImg;    //!< cached glyph plane
-  FT_Vector*             myKernAdvance; //!< buffer variable
-  Standard_Utf32Char     myUChar;       //!< currently loaded unicode character
+  Image_PixMap           myGlyphImg;     //!< cached glyph plane
+  FT_Vector*             myKernAdvance;  //!< buffer variable
+  Standard_Utf32Char     myUChar;        //!< currently loaded unicode character
 
 public:
 
diff --git a/src/Font/Font_FontMgr.cxx b/src/Font/Font_FontMgr.cxx
index 9b966024ef..d49a6764a8 100644
--- a/src/Font/Font_FontMgr.cxx
+++ b/src/Font/Font_FontMgr.cxx
@@ -49,7 +49,8 @@ static const Font_FontMgr_FontAliasMapNode Font_FontMgr_MapOfFontsAliases[] =
   { "Symbol"                   , "Symbol"         , Font_FA_Regular  },
   { "ZapfDingbats"             , "WingDings"      , Font_FA_Regular  },
   { "Rock"                     , "Arial"          , Font_FA_Regular  },
-  { "Iris"                     , "Lucida Console" , Font_FA_Regular  }
+  { "Iris"                     , "Lucida Console" , Font_FA_Regular  },
+  { "NSimSun"                  , "SimSun"         , Font_FA_Regular  }
 
 #elif defined(__ANDROID__)