summaryrefslogtreecommitdiffstats
path: root/starmath
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2017-02-01 22:48:04 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2017-02-02 00:32:16 +0000
commitd7736283aae4a79aa497bd2196a076ff402e671f (patch)
tree71f8870580d6954fa9bae61a8a4a1a6461529d54 /starmath
parenttdf#105625: Allow Delete/Backspace to delete whole fieldmark (diff)
downloadcore-d7736283aae4a79aa497bd2196a076ff402e671f.tar.gz
core-d7736283aae4a79aa497bd2196a076ff402e671f.zip
starmath: these functions are local
Change-Id: I7b1c9722e300585603ce54610d7ef20425a4e634 Reviewed-on: https://gerrit.libreoffice.org/33797 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/rect.hxx6
-rw-r--r--starmath/source/rect.cxx161
2 files changed, 80 insertions, 87 deletions
diff --git a/starmath/inc/rect.hxx b/starmath/inc/rect.hxx
index 427046500114..2a33bb5c5023 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 aa6489427d6d..54ceb6eda4bb 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: */