From b39596b109e05e6b49687e072bcb1e0b39b21dcc Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Fri, 1 Jul 2016 13:37:45 +0900 Subject: tdf#47813 Fix alignment for SmUnHorNode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Originally SmUnHorNode::Arrange() was somewhat kludgy. This change implements a similar manner with SmBinHorNode::Arrange(). Change-Id: Ic18d2e7f70becfabb2c651719926e358a4585526 Reviewed-on: https://gerrit.libreoffice.org/26841 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- starmath/CppunitTest_starmath_qa_cppunit.mk | 1 + starmath/qa/cppunit/test_node.cxx | 88 +++++++++++++++++++++++++++++ starmath/source/node.cxx | 29 ++++------ 3 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 starmath/qa/cppunit/test_node.cxx diff --git a/starmath/CppunitTest_starmath_qa_cppunit.mk b/starmath/CppunitTest_starmath_qa_cppunit.mk index b842f536b583..f2e3a6c1b991 100644 --- a/starmath/CppunitTest_starmath_qa_cppunit.mk +++ b/starmath/CppunitTest_starmath_qa_cppunit.mk @@ -51,6 +51,7 @@ $(eval $(call gb_CppunitTest_use_libraries,starmath_qa_cppunit,\ $(eval $(call gb_CppunitTest_add_exception_objects,starmath_qa_cppunit,\ starmath/qa/cppunit/test_cursor \ + starmath/qa/cppunit/test_node \ starmath/qa/cppunit/test_nodetotextvisitors \ starmath/qa/cppunit/test_parse \ starmath/qa/cppunit/test_starmath \ diff --git a/starmath/qa/cppunit/test_node.cxx b/starmath/qa/cppunit/test_node.cxx new file mode 100644 index 000000000000..5f2dca8d3122 --- /dev/null +++ b/starmath/qa/cppunit/test_node.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include + +#include +#include +#include +#include + +#include + +namespace { + +using namespace ::com::sun::star; + +typedef tools::SvRef SmDocShellRef; + +class NodeTest : public test::BootstrapFixture +{ +public: + virtual void setUp() SAL_OVERRIDE; + virtual void tearDown() SAL_OVERRIDE; + +private: + void testTdf47813(); + + CPPUNIT_TEST_SUITE(NodeTest); + CPPUNIT_TEST(testTdf47813); + CPPUNIT_TEST_SUITE_END(); + + SmDocShellRef mxDocShell; +}; + +void NodeTest::setUp() +{ + BootstrapFixture::setUp(); + SmGlobals::ensure(); + mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT | + SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS | + SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); +} + +void NodeTest::tearDown() +{ + if (mxDocShell) + mxDocShell->DoClose(); + BootstrapFixture::tearDown(); +} + +void NodeTest::testTdf47813() +{ + SmParser aParser; +#define MATRIX "matrix {-2#33##4#-5##6,0#7}" + std::unique_ptr pNodeA(aParser.Parse(MATRIX)); + std::unique_ptr pNodeC(aParser.Parse("alignc " MATRIX)); + std::unique_ptr pNodeL(aParser.Parse("alignl " MATRIX)); + std::unique_ptr pNodeR(aParser.Parse("alignr " MATRIX)); +#undef MATRIX + ScopedVclPtrInstance pOutputDevice; + SmFormat aFmt; + (void)pNodeA->Arrange(*pOutputDevice, aFmt); + (void)pNodeC->Arrange(*pOutputDevice, aFmt); + (void)pNodeL->Arrange(*pOutputDevice, aFmt); + (void)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_TEST_SUITE_REGISTRATION(NodeTest); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/starmath/source/node.cxx b/starmath/source/node.cxx index 2d0514b1d3eb..18143d5b9187 100644 --- a/starmath/source/node.cxx +++ b/starmath/source/node.cxx @@ -645,8 +645,10 @@ void SmUnHorNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat) { bool bIsPostfix = GetToken().eType == TFACT; - SmNode *pOper = GetSubNode(bIsPostfix ? 1 : 0), - *pBody = GetSubNode(bIsPostfix ? 0 : 1); + SmNode *pNode0 = GetSubNode(0), + *pNode1 = GetSubNode(1); + SmNode *pOper = bIsPostfix ? pNode1 : pNode0, + *pBody = bIsPostfix ? pNode0 : pNode1; assert(pOper); assert(pBody); @@ -654,25 +656,14 @@ void SmUnHorNode::Arrange(OutputDevice &rDev, const SmFormat &rFormat) pOper->Arrange(rDev, rFormat); pBody->Arrange(rDev, rFormat); - Point aPos = pOper->AlignTo(*pBody, bIsPostfix ? RectPos::Right : RectPos::Left, - RectHorAlign::Center, RectVerAlign::Baseline); - // add a bit space between operator and argument - // (worst case -{1 over 2} where - and over have almost no space inbetween) - long nDelta = pOper->GetFont().GetFontSize().Height() / 20; - if (bIsPostfix) - aPos.X() += nDelta; - else - aPos.X() -= nDelta; - pOper->MoveTo(aPos); - - SmRect::operator = (*pBody); - long nOldBot = GetBottom(); + long nDist = (pOper->GetRect().GetWidth() * rFormat.GetDistance(DIS_HORIZONTAL)) / 100L; - ExtendBy(*pOper, RectCopyMBL::Xor); + SmRect::operator = (*pNode0); - // workaround for Bug 50865: "a^2 a^+2" have different baselines - // for exponents (if size of exponent is large enough) - SetBottom(nOldBot); + Point aPos = pNode1->AlignTo(*this, RectPos::Right, RectHorAlign::Center, RectVerAlign::Baseline); + aPos.X() += nDist; + pNode1->MoveTo(aPos); + ExtendBy(*pNode1, RectCopyMBL::Xor); } -- cgit v1.2.3