sw/CppunitTest_sw_ooxmlimport.mk | 1 sw/qa/extras/ooxmlimport/data/fdo76803.docx |binary sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 31 ++++ writerfilter/Library_writerfilter.mk | 1 writerfilter/inc/resourcemodel/Fraction.hxx | 54 ------- writerfilter/qa/cppunittests/misc/misc.cxx | 17 -- writerfilter/source/dmapper/WrapPolygonHandler.cxx | 20 +- writerfilter/source/dmapper/WrapPolygonHandler.hxx | 4 writerfilter/source/resourcemodel/Fraction.cxx | 143 --------------------- 9 files changed, 44 insertions(+), 227 deletions(-)
New commits: commit abc28ffc04067eb24840fbf564c311aaee10f84d Author: Jan Holesovsky <ke...@collabora.com> Date: Tue Jul 15 09:10:10 2014 +0200 fdo#76803: Unit test so that this never regresses. Change-Id: Id0b883b7d7b902c1f8e41bcf39220ef74b3488bf diff --git a/sw/CppunitTest_sw_ooxmlimport.mk b/sw/CppunitTest_sw_ooxmlimport.mk index 7eff1bc..682b31c 100644 --- a/sw/CppunitTest_sw_ooxmlimport.mk +++ b/sw/CppunitTest_sw_ooxmlimport.mk @@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_ooxmlimport, \ )) $(eval $(call gb_CppunitTest_use_libraries,sw_ooxmlimport, \ + basegfx \ comphelper \ cppu \ cppuhelper \ diff --git a/sw/qa/extras/ooxmlimport/data/fdo76803.docx b/sw/qa/extras/ooxmlimport/data/fdo76803.docx new file mode 100644 index 0000000..65fad06 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/fdo76803.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 954dae3..8d85f1d 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -12,6 +12,7 @@ #if !defined(WNT) +#include <basegfx/polygon/b2dpolypolygontools.hxx> #include <com/sun/star/awt/XBitmap.hpp> #include <com/sun/star/awt/FontUnderline.hpp> #include <com/sun/star/awt/FontWeight.hpp> @@ -19,6 +20,7 @@ #include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp> #include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp> +#include <com/sun/star/drawing/PointSequenceSequence.hpp> #include <com/sun/star/drawing/TextVerticalAdjust.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> @@ -2245,6 +2247,35 @@ DECLARE_OOXMLIMPORT_TEST(testFdo80555, "fdo80555.docx") CPPUNIT_ASSERT_EQUAL(sal_Int32(245), xShape->getPosition().Y); } +DECLARE_OOXMLIMPORT_TEST(testFdo76803, "fdo76803.docx") +{ + // The ContourPolyPolygon was wrong + uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY); + + drawing::PointSequenceSequence rContour = getProperty<drawing::PointSequenceSequence>(xPropertySet, "ContourPolyPolygon"); + basegfx::B2DPolyPolygon aPolyPolygon(basegfx::tools::UnoPointSequenceSequenceToB2DPolyPolygon(rContour)); + + // We've got exactly one polygon inside + CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), aPolyPolygon.count()); + + // Now check it deeply + basegfx::B2DPolygon aPolygon(aPolyPolygon.getB2DPolygon(0)); + + CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aPolygon.count()); + + CPPUNIT_ASSERT_EQUAL(double(-163), aPolygon.getB2DPoint(0).getX()); + CPPUNIT_ASSERT_EQUAL(double(0), aPolygon.getB2DPoint(0).getY()); + + CPPUNIT_ASSERT_EQUAL(double(-163), aPolygon.getB2DPoint(1).getX()); + CPPUNIT_ASSERT_EQUAL(double(3661), aPolygon.getB2DPoint(1).getY()); + + CPPUNIT_ASSERT_EQUAL(double(16988), aPolygon.getB2DPoint(2).getX()); + CPPUNIT_ASSERT_EQUAL(double(3661), aPolygon.getB2DPoint(2).getY()); + + CPPUNIT_ASSERT_EQUAL(double(16988), aPolygon.getB2DPoint(3).getX()); + CPPUNIT_ASSERT_EQUAL(double(0), aPolygon.getB2DPoint(3).getY()); +} + #endif CPPUNIT_PLUGIN_IMPLEMENT(); commit 003434f1e2f4bd7ec08d2428fe2b90c11e680cef Author: Jan Holesovsky <ke...@collabora.com> Date: Tue Jul 15 07:25:38 2014 +0200 fdo#76803: Kill resourcemodel::Fraction, and use Fraction from tools instead. Change-Id: I72d336b8aacf80f9ab6472c0948766ee56fda34f diff --git a/writerfilter/Library_writerfilter.mk b/writerfilter/Library_writerfilter.mk index 793d810..0cc5ddd 100644 --- a/writerfilter/Library_writerfilter.mk +++ b/writerfilter/Library_writerfilter.mk @@ -121,7 +121,6 @@ $(eval $(call gb_Library_add_exception_objects,writerfilter,\ writerfilter/source/ooxml/OOXMLParserState \ writerfilter/source/ooxml/OOXMLPropertySetImpl \ writerfilter/source/ooxml/OOXMLStreamImpl \ - writerfilter/source/resourcemodel/Fraction \ writerfilter/source/resourcemodel/LoggedResources \ writerfilter/source/resourcemodel/ResourceModelHelper \ writerfilter/source/resourcemodel/TagLogger \ diff --git a/writerfilter/inc/resourcemodel/Fraction.hxx b/writerfilter/inc/resourcemodel/Fraction.hxx deleted file mode 100644 index 2029376..0000000 --- a/writerfilter/inc/resourcemodel/Fraction.hxx +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_FRACTION_HXX -#define INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_FRACTION_HXX - -#include <sal/types.h> - - -namespace writerfilter { -namespace resourcemodel { - -class Fraction -{ -public: - explicit Fraction(sal_Int32 nNumerator, sal_Int32 nDenominator = 1); - virtual ~Fraction(); - - void init(sal_Int32 nNumerator, sal_Int32 nDenominator); - void assign(const Fraction & rFraction); - - Fraction inverse() const; - - Fraction operator=(const Fraction & rFraction); - Fraction operator+(const Fraction & rFraction) const; - Fraction operator-(const Fraction & rFraction) const; - Fraction operator*(const Fraction & rFraction) const; - Fraction operator/(const Fraction & rFraction) const; - operator sal_Int32() const; - operator float() const; - -private: - sal_Int32 mnNumerator; - sal_Int32 mnDenominator; -}; -}} -#endif // INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_FRACTION_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/misc/misc.cxx b/writerfilter/qa/cppunittests/misc/misc.cxx index 0db80cc..baffe64 100644 --- a/writerfilter/qa/cppunittests/misc/misc.cxx +++ b/writerfilter/qa/cppunittests/misc/misc.cxx @@ -22,10 +22,6 @@ #include <rtl/ustring.hxx> #include <dmapper/ConversionHelper.hxx> #include <dmapper/DomainMapper_Impl.hxx> -#define private public -#include <../../../source/resourcemodel/Fraction.cxx> -#undef private - using namespace std; @@ -39,12 +35,10 @@ public: virtual void tearDown() SAL_OVERRIDE; void testTwipConversions(); - void testFraction(); void testFieldParameters(); CPPUNIT_TEST_SUITE(WriterfilterMiscTest); CPPUNIT_TEST(testTwipConversions); - CPPUNIT_TEST(testFraction); CPPUNIT_TEST(testFieldParameters); CPPUNIT_TEST_SUITE_END(); }; @@ -77,17 +71,6 @@ void WriterfilterMiscTest::testTwipConversions() CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(40000)); } -void WriterfilterMiscTest::testFraction() -{ - using writerfilter::resourcemodel::Fraction; - Fraction f1(-928800, 2717); - CPPUNIT_ASSERT_EQUAL(sal_Int32(-928800), f1.mnNumerator); // became positive - CPPUNIT_ASSERT_EQUAL(sal_Int32(2717), f1.mnDenominator); - Fraction f2(-220869, 1350); - CPPUNIT_ASSERT_EQUAL(sal_Int32(-24541), f2.mnNumerator); // became positive - CPPUNIT_ASSERT_EQUAL(sal_Int32(150), f2.mnDenominator); -} - void WriterfilterMiscTest::testFieldParameters() { using writerfilter::dmapper::lcl_SplitFieldCommand; diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.cxx b/writerfilter/source/dmapper/WrapPolygonHandler.cxx index 039bf7f..dfed4fb 100644 --- a/writerfilter/source/dmapper/WrapPolygonHandler.cxx +++ b/writerfilter/source/dmapper/WrapPolygonHandler.cxx @@ -88,7 +88,7 @@ WrapPolygon::Pointer_t WrapPolygon::move(const awt::Point & rPoint) return pResult; } -WrapPolygon::Pointer_t WrapPolygon::scale(const resourcemodel::Fraction & rFractionX, const resourcemodel::Fraction & rFractionY) +WrapPolygon::Pointer_t WrapPolygon::scale(const Fraction & rFractionX, const Fraction & rFractionY) { WrapPolygon::Pointer_t pResult(new WrapPolygon); @@ -97,7 +97,7 @@ WrapPolygon::Pointer_t WrapPolygon::scale(const resourcemodel::Fraction & rFract while (aIt != aItEnd) { - awt::Point aPoint(resourcemodel::Fraction(aIt->X) * rFractionX, resourcemodel::Fraction(aIt->Y) * rFractionY); + awt::Point aPoint((Fraction(long(aIt->X)) * rFractionX).operator long(), (Fraction(long(aIt->Y)) * rFractionY).operator long()); pResult->addPoint(aPoint); ++aIt; } @@ -109,19 +109,19 @@ WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSr { WrapPolygon::Pointer_t pResult; - const sal_uInt32 nWrap100Percent = 21600; + const long nWrap100Percent = 21600; - resourcemodel::Fraction aMove(nWrap100Percent, rSrcSize.Width); - aMove = aMove * resourcemodel::Fraction(15, 1); - awt::Point aMovePoint(aMove, 0); + Fraction aMove(nWrap100Percent, rSrcSize.Width); + aMove = aMove * Fraction(15, 1); + awt::Point aMovePoint(aMove.operator long(), 0); pResult = move(aMovePoint); - resourcemodel::Fraction aScaleX(nWrap100Percent, resourcemodel::Fraction(nWrap100Percent) + aMove); - resourcemodel::Fraction aScaleY(nWrap100Percent, resourcemodel::Fraction(nWrap100Percent) - aMove); + Fraction aScaleX(nWrap100Percent, Fraction(nWrap100Percent) + aMove); + Fraction aScaleY(nWrap100Percent, Fraction(nWrap100Percent) - aMove); pResult = pResult->scale(aScaleX, aScaleY); - resourcemodel::Fraction aScaleSrcX(rSrcSize.Width, nWrap100Percent); - resourcemodel::Fraction aScaleSrcY(rSrcSize.Height, nWrap100Percent); + Fraction aScaleSrcX(rSrcSize.Width, nWrap100Percent); + Fraction aScaleSrcY(rSrcSize.Height, nWrap100Percent); pResult = pResult->scale(aScaleSrcX, aScaleSrcY); return pResult; diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.hxx b/writerfilter/source/dmapper/WrapPolygonHandler.hxx index 9aa4293..e7a470d 100644 --- a/writerfilter/source/dmapper/WrapPolygonHandler.hxx +++ b/writerfilter/source/dmapper/WrapPolygonHandler.hxx @@ -23,7 +23,7 @@ #include <deque> #include <com/sun/star/drawing/PointSequenceSequence.hpp> #include <resourcemodel/LoggedResources.hxx> -#include <resourcemodel/Fraction.hxx> +#include <tools/fract.hxx> namespace writerfilter { namespace dmapper { @@ -51,7 +51,7 @@ public: size_t size() const; WrapPolygon::Pointer_t move(const css::awt::Point & rMove); - WrapPolygon::Pointer_t scale(const resourcemodel::Fraction & rFractionX, const resourcemodel::Fraction & rFractionY); + WrapPolygon::Pointer_t scale(const Fraction & rFractionX, const Fraction & rFractionY); WrapPolygon::Pointer_t correctWordWrapPolygon(const css::awt::Size & rSrcSize); css::drawing::PointSequenceSequence getPointSequenceSequence() const; }; diff --git a/writerfilter/source/resourcemodel/Fraction.cxx b/writerfilter/source/resourcemodel/Fraction.cxx deleted file mode 100644 index ba76985..0000000 --- a/writerfilter/source/resourcemodel/Fraction.cxx +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <resourcemodel/Fraction.hxx> - -namespace writerfilter { -namespace resourcemodel { - -// Stein's binary GCD for non-negative integers -// https://en.wikipedia.org/wiki/Binary_GCD_algorithm -static sal_uInt32 gcd(sal_uInt32 a, sal_uInt32 b) -{ - if (a == 0 || b == 0) - return a | b; - - sal_uInt32 nShift = 0; - while (((a | b) & 1) == 0) - { - a >>= 1; - b >>= 1; - ++nShift; - } - - while ((a & 1) == 0) - a >>= 1; - - do - { - while ((b & 1) == 0) - b >>= 1; - - if (a < b) - { - b -= a; - } - else - { - sal_uInt32 nDiff = a - b; - a = b; - b = nDiff; - } - - b >>= 1; - } - while (b != 0); - - return a << nShift; -} - -static sal_uInt32 lcm(sal_Int32 a, sal_Int32 b) -{ - return abs(a * b) / gcd(abs(a), abs(b)); -} - -Fraction::Fraction(sal_Int32 nNumerator, sal_Int32 nDenominator) -{ - init(nNumerator, nDenominator); -} - -Fraction::~Fraction() -{ -} - -void Fraction::init(sal_Int32 nNumerator, sal_Int32 nDenominator) -{ - // fdo#41068 pass non-negative numbers to gcd - sal_Int32 const nGCD = gcd(abs(nNumerator), abs(nDenominator)); - - // fdo#76803 do signed division - mnNumerator = nNumerator / nGCD; - mnDenominator = nDenominator / nGCD; -} - -void Fraction::assign(const Fraction & rFraction) -{ - init(rFraction.mnNumerator, rFraction.mnDenominator); -} - -Fraction Fraction::inverse() const -{ - return Fraction(mnDenominator, mnNumerator); -} - -Fraction Fraction::operator + (const Fraction & rFraction) const -{ - sal_uInt32 nLCM = lcm(mnDenominator, rFraction.mnDenominator); - - return Fraction(mnNumerator * nLCM / mnDenominator + rFraction.mnNumerator * nLCM / rFraction.mnDenominator, nLCM); -} - -Fraction Fraction::operator - (const Fraction & rFraction) const -{ - sal_uInt32 nLCM = lcm(mnDenominator, rFraction.mnDenominator); - - return Fraction(mnNumerator * nLCM / mnDenominator - rFraction.mnNumerator * nLCM / rFraction.mnDenominator, nLCM); -} - -Fraction Fraction::operator * (const Fraction & rFraction) const -{ - return Fraction(mnNumerator * rFraction.mnNumerator, mnDenominator * rFraction.mnDenominator); -} - -Fraction Fraction::operator / (const Fraction & rFraction) const -{ - return *this * rFraction.inverse(); -} - -Fraction Fraction::operator = (const Fraction & rFraction) -{ - assign(rFraction); - - return *this; -} - -Fraction::operator sal_Int32() const -{ - return mnNumerator / mnDenominator; -} - -Fraction::operator float() const -{ - return static_cast<float>(mnNumerator) / static_cast<float>(mnDenominator); -} - -}} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits