[Libreoffice-commits] core.git: starmath/inc starmath/source

Takeshi Abe tabe at fixedpoint.jp
Thu Feb 2 00:32:48 UTC 2017


 starmath/inc/rect.hxx    |    6 -
 starmath/source/rect.cxx |  161 +++++++++++++++++++++++------------------------
 2 files changed, 80 insertions(+), 87 deletions(-)

New commits:
commit d7736283aae4a79aa497bd2196a076ff402e671f
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Wed Feb 1 22:48:04 2017 +0900

    starmath: these functions are local
    
    Change-Id: I7b1c9722e300585603ce54610d7ef20425a4e634
    Reviewed-on: https://gerrit.libreoffice.org/33797
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Takeshi Abe <tabe at fixedpoint.jp>

diff --git a/starmath/inc/rect.hxx b/starmath/inc/rect.hxx
index 4270465..2a33bb5 100644
--- a/starmath/inc/rect.hxx
+++ b/starmath/inc/rect.hxx
@@ -29,12 +29,6 @@
 #include "format.hxx"
 
 
-bool SmGetGlyphBoundRect(const OutputDevice &rDev,
-                         const OUString &rText, Rectangle &rRect);
-
-bool SmIsMathAlpha(const OUString &rText);
-
-
 inline long SmFromTo(long nFrom, long nTo, double fRelDist)
 {
     return nFrom + static_cast<long>(fRelDist * (nTo - nFrom));
diff --git a/starmath/source/rect.cxx b/starmath/source/rect.cxx
index aa64894..54ceb6e 100644
--- a/starmath/source/rect.cxx
+++ b/starmath/source/rect.cxx
@@ -31,6 +31,85 @@
 #include <cassert>
 #include <unordered_set>
 
+namespace {
+
+bool SmGetGlyphBoundRect(const vcl::RenderContext &rDev,
+                         const OUString &rText, Rectangle &rRect)
+    // basically the same as 'GetTextBoundRect' (in class 'OutputDevice')
+    // but with a string as argument.
+{
+    // handle special case first
+    if (rText.isEmpty())
+    {
+        rRect.SetEmpty();
+        return true;
+    }
+
+    // get a device where 'OutputDevice::GetTextBoundRect' will be successful
+    OutputDevice *pGlyphDev;
+    if (rDev.GetOutDevType() != OUTDEV_PRINTER)
+        pGlyphDev = const_cast<OutputDevice *>(&rDev);
+    else
+    {
+        // since we format for the printer (where GetTextBoundRect will fail)
+        // we need a virtual device here.
+        pGlyphDev = &SM_MOD()->GetDefaultVirtualDev();
+    }
+
+    const FontMetric  aDevFM (rDev.GetFontMetric());
+
+    pGlyphDev->Push(PushFlags::FONT | PushFlags::MAPMODE);
+    vcl::Font aFnt(rDev.GetFont());
+    aFnt.SetAlignment(ALIGN_TOP);
+
+    // use scale factor when calling GetTextBoundRect to counter
+    // negative effects from antialiasing which may otherwise result
+    // in significant incorrect bounding rectangles for some characters.
+    Size aFntSize = aFnt.GetFontSize();
+
+    // Workaround to avoid HUGE font sizes and resulting problems
+    long nScaleFactor = 1;
+    while( aFntSize.Height() > 2000 * nScaleFactor )
+        nScaleFactor *= 2;
+
+    aFnt.SetFontSize( Size( aFntSize.Width() / nScaleFactor, aFntSize.Height() / nScaleFactor ) );
+    pGlyphDev->SetFont(aFnt);
+
+    long nTextWidth = rDev.GetTextWidth(rText);
+    Point aPoint;
+    Rectangle   aResult (aPoint, Size(nTextWidth, rDev.GetTextHeight())),
+                aTmp;
+
+    bool bSuccess = pGlyphDev->GetTextBoundRect(aTmp, rText);
+    OSL_ENSURE( bSuccess, "GetTextBoundRect failed" );
+
+
+    if (!aTmp.IsEmpty())
+    {
+        aResult = Rectangle(aTmp.Left() * nScaleFactor, aTmp.Top() * nScaleFactor,
+                            aTmp.Right() * nScaleFactor, aTmp.Bottom() * nScaleFactor);
+        if (&rDev != pGlyphDev) /* only when rDev is a printer... */
+        {
+            long nGDTextWidth  = pGlyphDev->GetTextWidth(rText);
+            if (nGDTextWidth != 0  &&
+                nTextWidth != nGDTextWidth)
+            {
+                aResult.Right() *= nTextWidth;
+                aResult.Right() /= nGDTextWidth * nScaleFactor;
+            }
+        }
+    }
+
+    // move rectangle to match possibly different baselines
+    // (because of different devices)
+    long nDelta = aDevFM.GetAscent() - pGlyphDev->GetFontMetric().GetAscent() * nScaleFactor;
+    aResult.Move(0, nDelta);
+
+    pGlyphDev->Pop();
+
+    rRect = aResult;
+    return bSuccess;
+}
 
 bool SmIsMathAlpha(const OUString &rText)
     // true iff symbol (from StarMath Font) should be treated as letter
@@ -62,8 +141,7 @@ bool SmIsMathAlpha(const OUString &rText)
     return aMathAlpha.find(cChar) != aMathAlpha.end();
 }
 
-
-// SmRect members
+}
 
 
 SmRect::SmRect()
@@ -542,83 +620,4 @@ SmRect SmRect::AsGlyphRect() const
     return aRect;
 }
 
-bool SmGetGlyphBoundRect(const vcl::RenderContext &rDev,
-                         const OUString &rText, Rectangle &rRect)
-    // basically the same as 'GetTextBoundRect' (in class 'OutputDevice')
-    // but with a string as argument.
-{
-    // handle special case first
-    if (rText.isEmpty())
-    {
-        rRect.SetEmpty();
-        return true;
-    }
-
-    // get a device where 'OutputDevice::GetTextBoundRect' will be successful
-    OutputDevice *pGlyphDev;
-    if (rDev.GetOutDevType() != OUTDEV_PRINTER)
-        pGlyphDev = const_cast<OutputDevice *>(&rDev);
-    else
-    {
-        // since we format for the printer (where GetTextBoundRect will fail)
-        // we need a virtual device here.
-        pGlyphDev = &SM_MOD()->GetDefaultVirtualDev();
-    }
-
-    const FontMetric  aDevFM (rDev.GetFontMetric());
-
-    pGlyphDev->Push(PushFlags::FONT | PushFlags::MAPMODE);
-    vcl::Font aFnt(rDev.GetFont());
-    aFnt.SetAlignment(ALIGN_TOP);
-
-    // use scale factor when calling GetTextBoundRect to counter
-    // negative effects from antialiasing which may otherwise result
-    // in significant incorrect bounding rectangles for some characters.
-    Size aFntSize = aFnt.GetFontSize();
-
-    // Workaround to avoid HUGE font sizes and resulting problems
-    long nScaleFactor = 1;
-    while( aFntSize.Height() > 2000 * nScaleFactor )
-        nScaleFactor *= 2;
-
-    aFnt.SetFontSize( Size( aFntSize.Width() / nScaleFactor, aFntSize.Height() / nScaleFactor ) );
-    pGlyphDev->SetFont(aFnt);
-
-    long nTextWidth = rDev.GetTextWidth(rText);
-    Point aPoint;
-    Rectangle   aResult (aPoint, Size(nTextWidth, rDev.GetTextHeight())),
-                aTmp;
-
-    bool bSuccess = pGlyphDev->GetTextBoundRect(aTmp, rText);
-    OSL_ENSURE( bSuccess, "GetTextBoundRect failed" );
-
-
-    if (!aTmp.IsEmpty())
-    {
-        aResult = Rectangle(aTmp.Left() * nScaleFactor, aTmp.Top() * nScaleFactor,
-                            aTmp.Right() * nScaleFactor, aTmp.Bottom() * nScaleFactor);
-        if (&rDev != pGlyphDev) /* only when rDev is a printer... */
-        {
-            long nGDTextWidth  = pGlyphDev->GetTextWidth(rText);
-            if (nGDTextWidth != 0  &&
-                nTextWidth != nGDTextWidth)
-            {
-                aResult.Right() *= nTextWidth;
-                aResult.Right() /= nGDTextWidth * nScaleFactor;
-            }
-        }
-    }
-
-    // move rectangle to match possibly different baselines
-    // (because of different devices)
-    long nDelta = aDevFM.GetAscent() - pGlyphDev->GetFontMetric().GetAscent() * nScaleFactor;
-    aResult.Move(0, nDelta);
-
-    pGlyphDev->Pop();
-
-    rRect = aResult;
-    return bSuccess;
-}
-
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list