From 13894996601daf10d133f4a71eb0b26794d782bc Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 4 May 2019 21:46:31 +0200 Subject: handle empty Rectangle better in starmath which required fixing a unit test to call Prepare, otherwise the nodes are not ready for layout Change-Id: I763c1b05d4dfafa73ebaee55d080876848de94f6 Reviewed-on: https://gerrit.libreoffice.org/71800 Tested-by: Jenkins Reviewed-by: Noel Grandin --- starmath/qa/cppunit/test_node.cxx | 8 ++++++-- starmath/source/node.cxx | 5 ++++- starmath/source/rect.cxx | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/starmath/qa/cppunit/test_node.cxx b/starmath/qa/cppunit/test_node.cxx index a4c7df456399..7ee441ec1941 100644 --- a/starmath/qa/cppunit/test_node.cxx +++ b/starmath/qa/cppunit/test_node.cxx @@ -72,17 +72,21 @@ void NodeTest::testTdf47813() #undef MATRIX ScopedVclPtrInstance pOutputDevice; SmFormat aFmt; + pNodeA->Prepare(aFmt, *mxDocShell, 0); pNodeA->Arrange(*pOutputDevice, aFmt); + pNodeC->Prepare(aFmt, *mxDocShell, 0); pNodeC->Arrange(*pOutputDevice, aFmt); + pNodeL->Prepare(aFmt, *mxDocShell, 0); pNodeL->Arrange(*pOutputDevice, aFmt); + pNodeR->Prepare(aFmt, *mxDocShell, 0); pNodeR->Arrange(*pOutputDevice, aFmt); long nWidthA = pNodeA->GetRect().GetWidth(); long nWidthC = pNodeC->GetRect().GetWidth(); long nWidthL = pNodeL->GetRect().GetWidth(); long nWidthR = pNodeR->GetRect().GetWidth(); CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, nWidthC/static_cast(nWidthA), 0.01); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, nWidthL/static_cast(nWidthA), 0.01); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, nWidthR/static_cast(nWidthA), 0.01); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, nWidthL/static_cast(nWidthA), 0.02); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, nWidthR/static_cast(nWidthA), 0.02); } void NodeTest::testTdf52225() diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx index 97d97582826d..fcdcbbdb2e07 100644 --- a/starmath/source/node.cxx +++ b/starmath/source/node.cxx @@ -2064,6 +2064,7 @@ void SmTextNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell, i SetRectHorAlign( RectHorAlign::Left ); maText = GetToken().aText; + assert(!maText.isEmpty()); GetFont() = rFormat.GetFont(GetFontDesc()); if (IsItalic( GetFont() )) @@ -2402,7 +2403,9 @@ void SmMathSymbolNode::AdaptToY(OutputDevice &rDev, sal_uLong nHeight) // get denominator of error factor for height long nTmpBorderWidth = GetFont().GetBorderWidth(); - long nDenom = SmRect(aTmpDev, nullptr, GetText(), nTmpBorderWidth).GetHeight(); + long nDenom = 0; + if (!GetText().isEmpty()) + nDenom = SmRect(aTmpDev, nullptr, GetText(), nTmpBorderWidth).GetHeight(); // scale fontwidth with this error factor aFntSize.setHeight( aFntSize.Height() * nHeight ); diff --git a/starmath/source/rect.cxx b/starmath/source/rect.cxx index ab32022aac2a..113cf4998a65 100644 --- a/starmath/source/rect.cxx +++ b/starmath/source/rect.cxx @@ -38,6 +38,7 @@ bool SmGetGlyphBoundRect(const vcl::RenderContext &rDev, // basically the same as 'GetTextBoundRect' (in class 'OutputDevice') // but with a string as argument. { + assert(!rText.isEmpty()); // handle special case first if (rText.isEmpty()) { @@ -183,6 +184,7 @@ SmRect::SmRect(const OutputDevice &rDev, const SmFormat *pFormat, : aTopLeft(0, 0) , aSize(rDev.GetTextWidth(rText), rDev.GetTextHeight()) { + assert(!rText.isEmpty()); const FontMetric aFM (rDev.GetFontMetric()); bool bIsMath = aFM.GetFamilyName().equalsIgnoreAsciiCase( FONTNAME_MATH ); bool bAllowSmaller = bIsMath && !SmIsMathAlpha(rText); -- cgit