From 003434f1e2f4bd7ec08d2428fe2b90c11e680cef Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Tue, 15 Jul 2014 07:25:38 +0200 Subject: fdo#76803: Kill resourcemodel::Fraction, and use Fraction from tools instead. Change-Id: I72d336b8aacf80f9ab6472c0948766ee56fda34f --- 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 --------------------- 6 files changed, 12 insertions(+), 227 deletions(-) delete mode 100644 writerfilter/inc/resourcemodel/Fraction.hxx delete mode 100644 writerfilter/source/resourcemodel/Fraction.cxx diff --git a/writerfilter/Library_writerfilter.mk b/writerfilter/Library_writerfilter.mk index 793d810c5676..0cc5dddd7eb1 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 20293769ffcf..000000000000 --- 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 - - -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 0db80cc68bcc..baffe64bf34c 100644 --- a/writerfilter/qa/cppunittests/misc/misc.cxx +++ b/writerfilter/qa/cppunittests/misc/misc.cxx @@ -22,10 +22,6 @@ #include #include #include -#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 039bf7fe4529..dfed4fb35c10 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 9aa42937cb2c..e7a470d193bd 100644 --- a/writerfilter/source/dmapper/WrapPolygonHandler.hxx +++ b/writerfilter/source/dmapper/WrapPolygonHandler.hxx @@ -23,7 +23,7 @@ #include #include #include -#include +#include 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 ba76985150a4..000000000000 --- 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 - -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(mnNumerator) / static_cast(mnDenominator); -} - -}} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit