Rebased ref, commits from common ancestor: commit 97c00895af73a71825a402c3604d5e34e9dbef59 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Jul 18 18:02:28 2023 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 19:10:35 2023 +0900
basegfx: BColorStops shouldn't derive from std::vector Change-Id: I9f246c0d9a5ddc7f8cf428bf7fc8c8957e8584b6 diff --git a/basegfx/source/tools/bgradient.cxx b/basegfx/source/tools/bgradient.cxx index 86e1812d21ac..73767f3cc958 100644 --- a/basegfx/source/tools/bgradient.cxx +++ b/basegfx/source/tools/bgradient.cxx @@ -72,8 +72,8 @@ namespace basegfx // BColorStops for a single StartColor @0.0 & EndColor @1.0 BColorStops::BColorStops(const BColor& rStart, const BColor& rEnd) { - emplace_back(0.0, rStart); - emplace_back(1.0, rEnd); + maStops.emplace_back(0.0, rStart); + maStops.emplace_back(1.0, rEnd); } /* Helper to grep the correct ColorStop out of @@ -85,30 +85,30 @@ BColor BColorStops::getInterpolatedBColor(double fPosition, sal_uInt32 nRequeste BColorStopRange& rLastColorStopRange) const { // no color at all, done - if (empty()) + if (maStops.empty()) return BColor(); // outside range -> at start - const double fMin(front().getStopOffset()); + const double fMin(maStops.front().getStopOffset()); if (fPosition < fMin) - return front().getStopColor(); + return maStops.front().getStopColor(); // outside range -> at end - const double fMax(back().getStopOffset()); + const double fMax(maStops.back().getStopOffset()); if (fPosition > fMax) - return back().getStopColor(); + return maStops.back().getStopColor(); // special case for the 'classic' case with just two colors: // we can optimize that and keep the speed/resources low // by avoiding some calculations and an O(log(N)) array access - if (2 == size()) + if (2 == maStops.size()) { // if same StopOffset use front color if (fTools::equal(fMin, fMax)) - return front().getStopColor(); + return maStops.front().getStopColor(); - const basegfx::BColor aCStart(front().getStopColor()); - const basegfx::BColor aCEnd(back().getStopColor()); + const basegfx::BColor aCStart(maStops.front().getStopColor()); + const basegfx::BColor aCEnd(maStops.back().getStopColor()); // if colors are equal just return one if (aCStart == aCEnd) @@ -145,21 +145,22 @@ BColor BColorStops::getInterpolatedBColor(double fPosition, sal_uInt32 nRequeste // looping/accessing, but that's just due to the extensive // debug test code created by the stl. In a pro version, // all is good/fast as expected - const auto upperBound(std::upper_bound(begin(), end(), BColorStop(fPosition), + const auto upperBound(std::upper_bound(maStops.begin(), maStops.end(), + BColorStop(fPosition), [](const BColorStop& x, const BColorStop& y) { return x.getStopOffset() < y.getStopOffset(); })); // no upper bound, done - if (end() == upperBound) - return back().getStopColor(); + if (maStops.end() == upperBound) + return maStops.back().getStopColor(); // lower bound is one entry back, access that const auto lowerBound(upperBound - 1); // no lower bound, done - if (end() == lowerBound) - return back().getStopColor(); + if (maStops.end() == lowerBound) + return maStops.back().getStopColor(); // we have lower and upper bound, get colors and offsets rLastColorStopRange.maColorStart = lowerBound->getStopColor(); @@ -196,24 +197,24 @@ BColor BColorStops::getInterpolatedBColor(double fPosition, sal_uInt32 nRequeste */ void BColorStops::replaceStartColor(const BColor& rStart) { - BColorStops::iterator a1stNonStartColor(begin()); + auto a1stNonStartColor(maStops.begin()); // search for highest existing non-StartColor - CAUTION, // there might be none, one or multiple with StopOffset 0.0 - while (a1stNonStartColor != end() + while (a1stNonStartColor != maStops.end() && basegfx::fTools::lessOrEqual(a1stNonStartColor->getStopOffset(), 0.0)) a1stNonStartColor++; // create new ColorStops by 1st adding new one and then all // non-StartColor entries - BColorStops aNewColorStops; + std::vector<BColorStop> aNewColorStops; - aNewColorStops.reserve(size() + 1); + aNewColorStops.reserve(maStops.size() + 1); aNewColorStops.emplace_back(0.0, rStart); - aNewColorStops.insert(aNewColorStops.end(), a1stNonStartColor, end()); + aNewColorStops.insert(aNewColorStops.end(), a1stNonStartColor, maStops.end()); // assign & done - *this = aNewColorStops; + maStops = aNewColorStops; } /* Tooling method that allows to replace the EndColor in a @@ -225,11 +226,11 @@ void BColorStops::replaceStartColor(const BColor& rStart) void BColorStops::replaceEndColor(const BColor& rEnd) { // erase all evtl. existing EndColor(s) - while (!empty() && basegfx::fTools::moreOrEqual(back().getStopOffset(), 1.0)) - pop_back(); + while (!maStops.empty() && basegfx::fTools::moreOrEqual(maStops.back().getStopOffset(), 1.0)) + maStops.pop_back(); // add at the end of existing ColorStops - emplace_back(1.0, rEnd); + maStops.emplace_back(1.0, rEnd); } /* Tooling method to linearly blend the Colors contained in @@ -249,7 +250,7 @@ void BColorStops::blendToIntensity(double fStartIntensity, double fEndIntensity, const BColor& rBlendColor) { // no entries, done - if (empty()) + if (maStops.empty()) return; // correct intensities (maybe assert when input was wrong) @@ -261,7 +262,7 @@ void BColorStops::blendToIntensity(double fStartIntensity, double fEndIntensity, return; // blend relative to StopOffset position - for (auto& candidate : *this) + for (auto& candidate : maStops) { const double fOffset(candidate.getStopOffset()); const double fIntensity((fStartIntensity * (1.0 - fOffset)) + (fEndIntensity * fOffset)); @@ -299,18 +300,19 @@ void BColorStops::blendToIntensity(double fStartIntensity, double fEndIntensity, void BColorStops::sortAndCorrect() { // no content, we are done - if (empty()) + if (maStops.empty()) return; - if (1 == size()) + if (1 == maStops.size()) { // no gradient at all, but preserve given color // evtl. correct offset to be in valid range [0.0 .. 1.0] // NOTE: This does not move it to 0.0 or 1.0, it *can* still // be somewhere in-between what is allowed - const BColorStop aEntry(front()); - clear(); - emplace_back(std::max(0.0, std::min(1.0, aEntry.getStopOffset())), aEntry.getStopColor()); + const BColorStop aFirstEntry(maStops.front()); + maStops.clear(); + maStops.emplace_back(std::max(0.0, std::min(1.0, aFirstEntry.getStopOffset())), + aFirstEntry.getStopColor()); // done return; @@ -319,7 +321,7 @@ void BColorStops::sortAndCorrect() // start with sorting the input data. Remember that // this preserves the order of equal entries, where // equal is defined here by offset (see use operator==) - std::sort(begin(), end()); + std::sort(maStops.begin(), maStops.end()); // prepare status values size_t write(0); @@ -328,24 +330,24 @@ void BColorStops::sortAndCorrect() // and write with write <= read all the time. Step over the // data using read and check for valid entry. If valid, decide // how to keep it - for (size_t read(0); read < size(); read++) + for (size_t read(0); read < maStops.size(); read++) { // get offset of entry at read position - double fOff((*this)[read].getStopOffset()); + double fOff(maStops[read].getStopOffset()); - if (basegfx::fTools::less(fOff, 0.0) && read + 1 < size()) + if (basegfx::fTools::less(fOff, 0.0) && read + 1 < maStops.size()) { // value < 0.0 and we have a next entry. check for gradient snippet // containing 0.0 resp. StartColor - const double fOff2((*this)[read + 1].getStopOffset()); + const double fOff2(maStops[read + 1].getStopOffset()); if (basegfx::fTools::more(fOff2, 0.0)) { // read is the start of a gradient snippet containing 0.0. Correct // entry to StartColor, interpolate to correct StartColor - (*this)[read] - = BColorStop(0.0, basegfx::interpolate((*this)[read].getStopColor(), - (*this)[read + 1].getStopColor(), + maStops[read] + = BColorStop(0.0, basegfx::interpolate(maStops[read].getStopColor(), + maStops[read + 1].getStopColor(), (0.0 - fOff) / (fOff2 - fOff))); // adapt fOff @@ -359,19 +361,19 @@ void BColorStops::sortAndCorrect() continue; } - if (basegfx::fTools::less(fOff, 1.0) && read + 1 < size()) + if (basegfx::fTools::less(fOff, 1.0) && read + 1 < maStops.size()) { // value < 1.0 and we have a next entry. check for gradient snippet // containing 1.0 resp. EndColor - const double fOff2((*this)[read + 1].getStopOffset()); + const double fOff2(maStops[read + 1].getStopOffset()); if (basegfx::fTools::more(fOff2, 1.0)) { // read is the start of a gradient snippet containing 1.0. Correct // next entry to EndColor, interpolate to correct EndColor - (*this)[read + 1] - = BColorStop(1.0, basegfx::interpolate((*this)[read].getStopColor(), - (*this)[read + 1].getStopColor(), + maStops[read + 1] + = BColorStop(1.0, basegfx::interpolate(maStops[read].getStopColor(), + maStops[read + 1].getStopColor(), (1.0 - fOff) / (fOff2 - fOff))); // adapt fOff @@ -389,12 +391,12 @@ void BColorStops::sortAndCorrect() // entry is valid value at read position // copy if write target is empty (write at start) or when // write target is different to read in color or offset - if (0 == write || !((*this)[read] == (*this)[write - 1])) + if (0 == write || !(maStops[read] == maStops[write - 1])) { if (write != read) { // copy read to write backwards to close gaps - (*this)[write] = (*this)[read]; + maStops[write] = maStops[read]; } // always forward write position @@ -404,31 +406,31 @@ void BColorStops::sortAndCorrect() // correct size when length is reduced. write is always at // last used position + 1 - if (size() > write) + if (maStops.size() > write) { if (0 == write) { // no valid entries at all, but not empty. This can only happen // when all entries are below 0.0 or above 1.0 (else a gradient // snippet spawning over both would have been detected) - if (basegfx::fTools::less(back().getStopOffset(), 0.0)) + if (basegfx::fTools::less(maStops.back().getStopOffset(), 0.0)) { // all outside too low, rescue last due to being closest to content - const BColor aBackColor(back().getStopColor()); - clear(); - emplace_back(0.0, aBackColor); + const BColor aBackColor(maStops.back().getStopColor()); + maStops.clear(); + maStops.emplace_back(0.0, aBackColor); } else // if (basegfx::fTools::more(front().getStopOffset(), 1.0)) { // all outside too high, rescue first due to being closest to content - const BColor aFrontColor(front().getStopColor()); - clear(); - emplace_back(1.0, aFrontColor); + const BColor aFrontColor(maStops.front().getStopColor()); + maStops.clear(); + maStops.emplace_back(1.0, aFrontColor); } } else { - resize(write); + maStops.resize(write); } } } @@ -436,28 +438,28 @@ void BColorStops::sortAndCorrect() bool BColorStops::checkPenultimate() const { // not needed when no ColorStops - if (empty()) + if (maStops.empty()) return false; // not needed when last ColorStop at the end or outside - if (basegfx::fTools::moreOrEqual(back().getStopOffset(), 1.0)) + if (basegfx::fTools::moreOrEqual(maStops.back().getStopOffset(), 1.0)) return false; // get penultimate entry - const auto penultimate(rbegin() + 1); + const auto penultimate(maStops.rbegin() + 1); // if there is none, we need no correction and are done - if (penultimate == rend()) + if (penultimate == maStops.rend()) return false; // not needed when the last two ColorStops have different offset, then // a visible range will be processed already - if (!basegfx::fTools::equal(back().getStopOffset(), penultimate->getStopOffset())) + if (!basegfx::fTools::equal(maStops.back().getStopOffset(), penultimate->getStopOffset())) return false; // not needed when the last two ColorStops have the same Color, then the // range before solves the problem - if (back().getStopColor() == penultimate->getStopColor()) + if (maStops.back().getStopColor() == penultimate->getStopColor()) return false; return true; @@ -472,21 +474,21 @@ bool BColorStops::checkPenultimate() const */ bool BColorStops::isSingleColor(BColor& rSingleColor) const { - if (empty()) + if (maStops.empty()) { rSingleColor = BColor(); return true; } - if (1 == size()) + if (1 == maStops.size()) { - rSingleColor = front().getStopColor(); + rSingleColor = maStops.front().getStopColor(); return true; } - rSingleColor = front().getStopColor(); + rSingleColor = maStops.front().getStopColor(); - for (auto const& rCandidate : *this) + for (auto const& rCandidate : maStops) { if (rCandidate.getStopColor() != rSingleColor) return false; @@ -501,8 +503,8 @@ bool BColorStops::isSingleColor(BColor& rSingleColor) const void BColorStops::reverseColorStops() { // can use std::reverse, but also need to adapt offset(s) - std::reverse(begin(), end()); - for (auto& candidate : *this) + std::reverse(maStops.begin(), maStops.end()); + for (auto& candidate : maStops) candidate = BColorStop(1.0 - candidate.getStopOffset(), candidate.getStopColor()); } @@ -511,7 +513,7 @@ void BColorStops::reverseColorStops() void BColorStops::createSpaceAtStart(double fOffset) { // nothing to do if empty - if (empty()) + if (maStops.empty()) return; // correct offset to [0.0 .. 1.0] @@ -521,15 +523,15 @@ void BColorStops::createSpaceAtStart(double fOffset) if (basegfx::fTools::equalZero(fOffset)) return; - BColorStops aNewStops; + std::vector<BColorStop> aNewStops; - for (const auto& candidate : *this) + for (const auto& candidate : maStops) { aNewStops.emplace_back(fOffset + (candidate.getStopOffset() * (1.0 - fOffset)), candidate.getStopColor()); } - *this = aNewStops; + maStops = aNewStops; } // removeSpaceAtStart removes fOffset space from start by @@ -538,7 +540,7 @@ void BColorStops::createSpaceAtStart(double fOffset) void BColorStops::removeSpaceAtStart(double fOffset) { // nothing to do if empty - if (empty()) + if (maStops.empty()) return; // correct factor to [0.0 .. 1.0] @@ -548,10 +550,10 @@ void BColorStops::removeSpaceAtStart(double fOffset) if (basegfx::fTools::equalZero(fOffset)) return; - BColorStops aNewStops; + std::vector<BColorStop> aNewStops; const double fMul(basegfx::fTools::equal(fOffset, 1.0) ? 1.0 : 1.0 / (1.0 - fOffset)); - for (const auto& candidate : *this) + for (const auto& candidate : maStops) { if (basegfx::fTools::moreOrEqual(candidate.getStopOffset(), fOffset)) { @@ -560,7 +562,7 @@ void BColorStops::removeSpaceAtStart(double fOffset) } } - *this = aNewStops; + maStops = aNewStops; } // try to detect if an empty/no-color-change area exists @@ -576,14 +578,14 @@ double BColorStops::detectPossibleOffsetAtStart() const // here we know that we have at least two colors, so we have a // color change. Find colors left and right of that first color change - BColorStops::const_iterator aColorR(begin()); - BColorStops::const_iterator aColorL(aColorR++); + auto aColorR(maStops.begin()); + auto aColorL(aColorR++); // aColorR would 1st get equal to end(), so no need to also check aColorL // for end(). Loop as long as same color. Since we *have* a color change // not even aColorR can get equal to end() before color inequality, but // keep for safety - while (aColorR != end() && aColorL->getStopColor() == aColorR->getStopColor()) + while (aColorR != maStops.end() && aColorL->getStopColor() == aColorR->getStopColor()) { aColorL++; aColorR++; @@ -591,7 +593,7 @@ double BColorStops::detectPossibleOffsetAtStart() const // also for safety: access values at aColorL below *only* // if not equal to end(), but can theoretically not happen - if (aColorL == end()) + if (aColorL == maStops.end()) { return 0.0; } @@ -603,13 +605,13 @@ double BColorStops::detectPossibleOffsetAtStart() const // checks whether the color stops are symmetrical in color and offset. bool BColorStops::isSymmetrical() const { - if (empty()) + if (maStops.empty()) return false; - if (1 == size()) - return basegfx::fTools::equal(0.5, front().getStopOffset()); + if (1 == maStops.size()) + return basegfx::fTools::equal(0.5, maStops.front().getStopOffset()); - BColorStops::const_iterator aIter(begin()); // for going forward - BColorStops::const_iterator aRIter(end()); // for going backward + auto aIter(maStops.begin()); // for going forward + auto aRIter(maStops.end()); // for going backward --aRIter; // We have at least two elements, so aIter <= aRIter fails before iterators no longer point to // an element. @@ -625,12 +627,12 @@ bool BColorStops::isSymmetrical() const void BColorStops::doApplyAxial() { // prepare new ColorStops - basegfx::BColorStops aNewColorStops; + std::vector<BColorStop> aNewColorStops; // add gradient stops in reverse order, scaled to [0.0 .. 0.5] - basegfx::BColorStops::const_reverse_iterator aRevCurrColor(rbegin()); + auto aRevCurrColor(maStops.rbegin()); - while (aRevCurrColor != rend()) + while (aRevCurrColor != maStops.rend()) { aNewColorStops.emplace_back((1.0 - aRevCurrColor->getStopOffset()) * 0.5, aRevCurrColor->getStopColor()); @@ -638,7 +640,7 @@ void BColorStops::doApplyAxial() } // prepare non-reverse run - basegfx::BColorStops::const_iterator aCurrColor(begin()); + auto aCurrColor(maStops.begin()); if (basegfx::fTools::equalZero(aCurrColor->getStopOffset())) { @@ -649,7 +651,7 @@ void BColorStops::doApplyAxial() } // add gradient stops in non-reverse order, translated and scaled to [0.5 .. 1.0] - while (aCurrColor != end()) + while (aCurrColor != maStops.end()) { aNewColorStops.emplace_back((aCurrColor->getStopOffset() * 0.5) + 0.5, aCurrColor->getStopColor()); @@ -657,7 +659,7 @@ void BColorStops::doApplyAxial() } // apply color stops - *this = aNewColorStops; + maStops = aNewColorStops; } void BColorStops::doApplySteps(sal_uInt16 nStepCount) @@ -672,11 +674,11 @@ void BColorStops::doApplySteps(sal_uInt16 nStepCount) return; // prepare new color stops, get L/R iterators for segments - basegfx::BColorStops aNewColorStops; - basegfx::BColorStops::const_iterator aColorR(begin()); - basegfx::BColorStops::const_iterator aColorL(aColorR++); + std::vector<BColorStop> aNewColorStops; + auto aColorR(maStops.begin()); + auto aColorL(aColorR++); - while (aColorR != end()) + while (aColorR != maStops.end()) { // get start/end color for segment const double fStart(aColorL->getStopOffset()); @@ -730,7 +732,7 @@ void BColorStops::doApplySteps(sal_uInt16 nStepCount) } // apply the change to color stops - *this = aNewColorStops; + maStops = aNewColorStops; } std::string BGradient::GradientStyleToString(css::awt::GradientStyle eStyle) @@ -779,8 +781,8 @@ BGradient::BGradient() , nIntensEnd(100) , nStepCount(0) { - aColorStops.emplace_back(0.0, BColor(0.0, 0.0, 0.0)); // COL_BLACK - aColorStops.emplace_back(1.0, BColor(1.0, 1.0, 1.0)); // COL_WHITE + aColorStops.addStop(0.0, BColor(0.0, 0.0, 0.0)); // COL_BLACK + aColorStops.addStop(1.0, BColor(1.0, 1.0, 1.0)); // COL_WHITE } BGradient::BGradient(const basegfx::BColorStops& rColorStops, css::awt::GradientStyle eTheStyle, @@ -813,7 +815,7 @@ void BGradient::SetColorStops(const basegfx::BColorStops& rSteps) aColorStops = rSteps; aColorStops.sortAndCorrect(); if (aColorStops.empty()) - aColorStops.emplace_back(0.0, basegfx::BColor()); + aColorStops.addStop(0.0, basegfx::BColor()); } namespace @@ -953,12 +955,12 @@ void BGradient::tryToConvertToAxial() // and collect them in a new color stops vector. BColorStops aAxialColorStops; aAxialColorStops.reserve(std::ceil(GetColorStops().size() / 2.0)); - BColorStops::const_iterator aIter(GetColorStops().begin()); + auto aIter(GetColorStops().begin()); while (basegfx::fTools::lessOrEqual(aIter->getStopOffset(), 0.5)) { - BColorStop aNextStop(std::clamp((*aIter).getStopOffset() * 2.0, 0.0, 1.0), - (*aIter).getStopColor()); - aAxialColorStops.push_back(aNextStop); + BColorStop aNextStop(std::clamp(aIter->getStopOffset() * 2.0, 0.0, 1.0), + aIter->getStopColor()); + aAxialColorStops.addStop(aNextStop); ++aIter; } // Axial gradients have outmost color as last color stop. diff --git a/basegfx/source/tools/gradienttools.cxx b/basegfx/source/tools/gradienttools.cxx index 8f3e8ae83c06..bc8bbedeeeab 100644 --- a/basegfx/source/tools/gradienttools.cxx +++ b/basegfx/source/tools/gradienttools.cxx @@ -345,7 +345,7 @@ namespace basegfx // create fallback synched with existing AlphaStops for (const auto& cand : rAlphaStops) { - rColorStops.emplace_back(cand.getStopOffset(), rSingleColor); + rColorStops.addStop(cand.getStopOffset(), rSingleColor); } } @@ -358,7 +358,7 @@ namespace basegfx // create fallback AlphaStops synched with existing ColorStops using SingleAlpha for (const auto& cand : rColorStops) { - rAlphaStops.emplace_back(cand.getStopOffset(), rSingleAlpha); + rAlphaStops.addStop(cand.getStopOffset(), rSingleAlpha); } // preparations complete, we are done @@ -373,8 +373,8 @@ namespace basegfx if (!bNeedToSyncronize) { // check for same StopOffsets - BColorStops::const_iterator aCurrColor(rColorStops.begin()); - BColorStops::const_iterator aCurrAlpha(rAlphaStops.begin()); + auto aCurrColor(rColorStops.begin()); + auto aCurrAlpha(rAlphaStops.begin()); while (!bNeedToSyncronize && aCurrColor != rColorStops.end() && @@ -395,8 +395,8 @@ namespace basegfx if (bNeedToSyncronize) { // synchronize sizes & StopOffsets - BColorStops::const_iterator aCurrColor(rColorStops.begin()); - BColorStops::const_iterator aCurrAlpha(rAlphaStops.begin()); + auto aCurrColor(rColorStops.begin()); + auto aCurrAlpha(rAlphaStops.begin()); BColorStops aNewColor; BColorStops aNewAlpha; BColorStops::BColorStopRange aColorStopRange; @@ -415,24 +415,24 @@ namespace basegfx if (fTools::less(fColorOff, fAlphaOff)) { // copy color, create alpha - aNewColor.emplace_back(fColorOff, aCurrColor->getStopColor()); - aNewAlpha.emplace_back(fColorOff, rAlphaStops.getInterpolatedBColor(fColorOff, 0, aAlphaStopRange)); + aNewColor.addStop(fColorOff, aCurrColor->getStopColor()); + aNewAlpha.addStop(fColorOff, rAlphaStops.getInterpolatedBColor(fColorOff, 0, aAlphaStopRange)); bRealChange = true; aCurrColor++; } else if (fTools::more(fColorOff, fAlphaOff)) { // copy alpha, create color - aNewColor.emplace_back(fAlphaOff, rColorStops.getInterpolatedBColor(fAlphaOff, 0, aColorStopRange)); - aNewAlpha.emplace_back(fAlphaOff, aCurrAlpha->getStopColor()); + aNewColor.addStop(fAlphaOff, rColorStops.getInterpolatedBColor(fAlphaOff, 0, aColorStopRange)); + aNewAlpha.addStop(fAlphaOff, aCurrAlpha->getStopColor()); bRealChange = true; aCurrAlpha++; } else { // equal: copy both, advance - aNewColor.emplace_back(fColorOff, aCurrColor->getStopColor()); - aNewAlpha.emplace_back(fAlphaOff, aCurrAlpha->getStopColor()); + aNewColor.addStop(fColorOff, aCurrColor->getStopColor()); + aNewAlpha.addStop(fAlphaOff, aCurrAlpha->getStopColor()); aCurrColor++; aCurrAlpha++; } @@ -440,16 +440,16 @@ namespace basegfx else if (bColor) { const double fColorOff(aCurrColor->getStopOffset()); - aNewAlpha.emplace_back(fColorOff, rAlphaStops.getInterpolatedBColor(fColorOff, 0, aAlphaStopRange)); - aNewColor.emplace_back(fColorOff, aCurrColor->getStopColor()); + aNewAlpha.addStop(fColorOff, rAlphaStops.getInterpolatedBColor(fColorOff, 0, aAlphaStopRange)); + aNewColor.addStop(fColorOff, aCurrColor->getStopColor()); bRealChange = true; aCurrColor++; } else if (bAlpha) { const double fAlphaOff(aCurrAlpha->getStopOffset()); - aNewColor.emplace_back(fAlphaOff, rColorStops.getInterpolatedBColor(fAlphaOff, 0, aColorStopRange)); - aNewAlpha.emplace_back(fAlphaOff, aCurrAlpha->getStopColor()); + aNewColor.addStop(fAlphaOff, rColorStops.getInterpolatedBColor(fAlphaOff, 0, aColorStopRange)); + aNewAlpha.addStop(fAlphaOff, aCurrAlpha->getStopColor()); bRealChange = true; aCurrAlpha++; } diff --git a/cui/source/tabpages/tpgradnt.cxx b/cui/source/tabpages/tpgradnt.cxx index df629a154ff4..a5256c8e3a6e 100644 --- a/cui/source/tabpages/tpgradnt.cxx +++ b/cui/source/tabpages/tpgradnt.cxx @@ -652,21 +652,11 @@ sal_Int32 SvxGradientTabPage::SearchGradientList(std::u16string_view rGradientNa basegfx::BColorStops SvxGradientTabPage::createColorStops() { - basegfx::BColorStops aColorStops; + basegfx::BColor aStartColor = m_xLbColorFrom->GetSelectEntryColor().getBColor(); + basegfx::BColor aEndColor = m_xLbColorTo->GetSelectEntryColor().getBColor(); - if(m_aColorStops.size() >= 2) - { - aColorStops = m_aColorStops; - aColorStops.front() = basegfx::BColorStop(m_aColorStops.front().getStopOffset(), - m_xLbColorFrom->GetSelectEntryColor().getBColor()); - aColorStops.back() = basegfx::BColorStop(m_aColorStops.back().getStopOffset(), - m_xLbColorTo->GetSelectEntryColor().getBColor()); - } - else - { - aColorStops.emplace_back(0.0, m_xLbColorFrom->GetSelectEntryColor().getBColor()); - aColorStops.emplace_back(1.0, m_xLbColorTo->GetSelectEntryColor().getBColor()); - } + basegfx::BColorStops aColorStops = m_aColorStops; + aColorStops.setStartAndEndColors(aStartColor, aEndColor); return aColorStops; } diff --git a/cui/source/tabpages/tptrans.cxx b/cui/source/tabpages/tptrans.cxx index 04cbdfb6b24a..f70e464dfec7 100644 --- a/cui/source/tabpages/tptrans.cxx +++ b/cui/source/tabpages/tptrans.cxx @@ -511,23 +511,13 @@ void SvxTransparenceTabPage::InvalidatePreview (bool bEnable) basegfx::BColorStops SvxTransparenceTabPage::createColorStops() { - basegfx::BColorStops aColorStops; basegfx::BColor aStartBColor(m_xMtrTrgrStartValue->get_value(FieldUnit::PERCENT) / 100.0); aStartBColor.clamp(); basegfx::BColor aEndBColor(m_xMtrTrgrEndValue->get_value(FieldUnit::PERCENT) / 100.0); aEndBColor.clamp(); - if(maColorStops.size() >= 2) - { - aColorStops = maColorStops; - aColorStops.front() = basegfx::BColorStop(maColorStops.front().getStopOffset(), aStartBColor); - aColorStops.back() = basegfx::BColorStop(maColorStops.back().getStopOffset(), aEndBColor); - } - else - { - aColorStops.emplace_back(0.0, aStartBColor); - aColorStops.emplace_back(1.0, aEndBColor); - } + basegfx::BColorStops aColorStops = maColorStops; + aColorStops.setStartAndEndColors(aStartBColor, aEndBColor); return aColorStops; } diff --git a/drawinglayer/source/attribute/fillgradientattribute.cxx b/drawinglayer/source/attribute/fillgradientattribute.cxx index e02fdd4a5dad..18c6d758b12b 100644 --- a/drawinglayer/source/attribute/fillgradientattribute.cxx +++ b/drawinglayer/source/attribute/fillgradientattribute.cxx @@ -64,7 +64,7 @@ namespace drawinglayer::attribute // fallback value if (maColorStops.empty()) { - maColorStops.emplace_back(0.0, basegfx::BColor()); + maColorStops.addStop(0.0, basegfx::BColor()); } } @@ -78,7 +78,7 @@ namespace drawinglayer::attribute mnSteps(0) { // always add a fallback color, see above - maColorStops.emplace_back(0.0, basegfx::BColor()); + maColorStops.addStop(0.0, basegfx::BColor()); } // data read access diff --git a/drawinglayer/source/texture/texture.cxx b/drawinglayer/source/texture/texture.cxx index ccfaa13bd8bf..5a10333c7698 100644 --- a/drawinglayer/source/texture/texture.cxx +++ b/drawinglayer/source/texture/texture.cxx @@ -153,7 +153,7 @@ namespace drawinglayer::texture // created gradient geometry. // The simplest way is to temporarily add an entry to the local // ColorStops for this at 1.0 (using same color) - mnColorStops.emplace_back(1.0, mnColorStops.back().getStopColor()); + mnColorStops.addStop(1.0, mnColorStops.back().getStopColor()); } // prepare unit range transform @@ -225,7 +225,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // correct temporary change - mnColorStops.pop_back(); + mnColorStops.getStops().pop_back(); } } @@ -301,7 +301,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // temporarily add a ColorStop entry - mnColorStops.emplace_back(1.0, mnColorStops.back().getStopColor()); + mnColorStops.addStop(1.0, mnColorStops.back().getStopColor()); } // prepare unit range transform @@ -358,7 +358,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // correct temporary change - mnColorStops.pop_back(); + mnColorStops.getStops().pop_back(); } } @@ -421,7 +421,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // temporarily add a ColorStop entry - mnColorStops.emplace_back(1.0, mnColorStops.back().getStopColor()); + mnColorStops.addStop(1.0, mnColorStops.back().getStopColor()); } // outer loop over ColorStops, each is from cs_l to cs_r @@ -462,7 +462,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // correct temporary change - mnColorStops.pop_back(); + mnColorStops.getStops().pop_back(); } } @@ -524,7 +524,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // temporarily add a ColorStop entry - mnColorStops.emplace_back(1.0, mnColorStops.back().getStopColor()); + mnColorStops.addStop(1.0, mnColorStops.back().getStopColor()); } // prepare vars dependent on aspect ratio @@ -572,7 +572,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // correct temporary change - mnColorStops.pop_back(); + mnColorStops.getStops().pop_back(); } } @@ -634,7 +634,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // temporarily add a ColorStop entry - mnColorStops.emplace_back(1.0, mnColorStops.back().getStopColor()); + mnColorStops.addStop(1.0, mnColorStops.back().getStopColor()); } // outer loop over ColorStops, each is from cs_l to cs_r @@ -675,7 +675,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // correct temporary change - mnColorStops.pop_back(); + mnColorStops.getStops().pop_back(); } } @@ -737,7 +737,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // temporarily add a ColorStop entry - mnColorStops.emplace_back(1.0, mnColorStops.back().getStopColor()); + mnColorStops.addStop(1.0, mnColorStops.back().getStopColor()); } // prepare vars dependent on aspect ratio @@ -785,7 +785,7 @@ namespace drawinglayer::texture if (bPenultimateUsed) { // correct temporary change - mnColorStops.pop_back(); + mnColorStops.getStops().pop_back(); } } diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx index 8df58f715f6e..1e5c37910f11 100644 --- a/drawinglayer/source/tools/primitive2dxmldump.cxx +++ b/drawinglayer/source/tools/primitive2dxmldump.cxx @@ -310,14 +310,16 @@ void writeSdrFillAttribute(::tools::XmlWriter& rWriter, { if (0 == a) rWriter.attribute("startColor", - convertColorToString(rColorStops[a].getStopColor())); + convertColorToString(rColorStops.getStops()[a].getStopColor())); else if (rColorStops.size() == a + 1) - rWriter.attribute("endColor", convertColorToString(rColorStops[a].getStopColor())); + rWriter.attribute("endColor", + convertColorToString(rColorStops.getStops()[a].getStopColor())); else { rWriter.startElement("colorStop"); - rWriter.attribute("stopOffset", rColorStops[a].getStopOffset()); - rWriter.attribute("stopColor", convertColorToString(rColorStops[a].getStopColor())); + rWriter.attribute("stopOffset", rColorStops.getStops()[a].getStopOffset()); + rWriter.attribute("stopColor", + convertColorToString(rColorStops.getStops()[a].getStopColor())); rWriter.endElement(); } } @@ -540,7 +542,7 @@ void Primitive2dXmlDump::dump( pStream->ReadBytes(pBuffer.get(), nSize); pBuffer[nSize] = 0; - printf ("%s\n", pBuffer.get()); + printf("%s\n", pBuffer.get()); } namespace diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index e2079304abbc..dbe60fdbbef5 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -2383,8 +2383,8 @@ void SVGActionWriter::ImplWriteGradientLinear( const tools::PolyPolygon& rPolyPo else { // else create color stops with 'old' start/endColor - aColorStops.emplace_back(0.0, rGradient.GetStartColor().getBColor()); - aColorStops.emplace_back(1.0, rGradient.GetEndColor().getBColor()); + aColorStops.addStop(0.0, rGradient.GetStartColor().getBColor()); + aColorStops.addStop(1.0, rGradient.GetEndColor().getBColor()); } // create a basegfx::BGradient with the info to be able to directly @@ -3410,7 +3410,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, aMemStm.ReadDouble(fG); aMemStm.ReadDouble(fB); - aColorStops.emplace_back(fOff, basegfx::BColor(fR, fG, fB)); + aColorStops.addStop(fOff, basegfx::BColor(fR, fG, fB)); } // export with real Color Stops diff --git a/include/basegfx/utils/bgradient.hxx b/include/basegfx/utils/bgradient.hxx index 7d360beee429..cffc87724301 100644 --- a/include/basegfx/utils/bgradient.hxx +++ b/include/basegfx/utils/bgradient.hxx @@ -91,27 +91,22 @@ public: is read-only, this can/will be guaranteed by forcing/checking this in the constructor, see ::FillGradientAttribute */ -class BASEGFX_DLLPUBLIC BColorStops final : public std::vector<BColorStop> +class BASEGFX_DLLPUBLIC BColorStops final { public: - explicit BColorStops() - : vector() - { - } - BColorStops(const BColorStops& other) - : vector(other) + explicit BColorStops() {} + + BColorStops(const BColorStops& rOther) + : maStops(rOther.maStops) { } - BColorStops(BColorStops&& other) noexcept - : vector(std::move(other)) + + BColorStops(BColorStops&& rOther) noexcept + : maStops(std::move(rOther.maStops)) { } BColorStops(std::initializer_list<BColorStop> init) - : vector(init) - { - } - BColorStops(const_iterator first, const_iterator last) - : vector(first, last) + : maStops(init) { } @@ -119,17 +114,65 @@ public: // BColorStops for StartColor @0.0 & EndColor @1.0 BColorStops(const BColor& rStart, const BColor& rEnd); - BColorStops& operator=(const BColorStops& r) + BColorStops& operator=(const BColorStops& rOther) { - vector::operator=(r); + maStops = rOther.maStops; return *this; } - BColorStops& operator=(BColorStops&& r) noexcept + + BColorStops& operator=(BColorStops&& rOther) noexcept { - vector::operator=(std::move(r)); + maStops = std::move(rOther.maStops); return *this; } + void addStop(double fOffset, BColor aColor) { maStops.emplace_back(fOffset, aColor); } + + void addStop(BColorStop aColorStop) { maStops.push_back(aColorStop); } + + BColorStop const& getStop(size_t i) const { return maStops[i]; } + + void reserve(size_t nNumber) { maStops.reserve(nNumber); } + + void clear() { maStops.clear(); } + + bool empty() const { return maStops.empty(); } + + size_type size() const { return maStops.size(); } + + iterator begin() { return maStops.begin(); } + + iterator end() { return maStops.end(); } + + const_iterator begin() const { return maStops.begin(); } + + const_iterator end() const { return maStops.end(); } + + const_reverse_iterator rbegin() const { return maStops.rbegin(); } + + const_reverse_iterator rend() const { return maStops.rend(); } + + const BColorStop& front() const { return maStops.front(); } + + const BColorStop& back() const { return maStops.back(); } + + bool operator==(BColorStops const& rOther) const { return maStops == rOther.maStops; } + + void setStartAndEndColors(BColor aStartColor, BColor aEndColor) + { + if (maStops.size() < 2) + { + maStops.resize(2); + maStops.front() = BColorStop(0.0, aStartColor); + maStops.back() = BColorStop(1.0, aEndColor); + } + else + { + maStops.front() = BColorStop(maStops.front().getStopOffset(), aStartColor); + maStops.back() = BColorStop(maStops.back().getStopOffset(), aEndColor); + } + } + // helper data struct to support buffering entries in // gradient texture mapping, see usages for more info struct BColorStopRange diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index dec9ab9672cc..d549ac42656d 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -461,7 +461,7 @@ void FillProperties::pushToPropMap(ShapePropertyMap& rPropMap, const GraphicHelp for (const auto& rCandidate : maGradientProps.maGradientStops) { const ::Color aColor(rCandidate.second.getColor(rGraphicHelper, nPhClr)); - aColorStops.emplace_back(rCandidate.first, aColor.getBColor()); + aColorStops.addStop(rCandidate.first, aColor.getBColor()); bContainsTransparency = bContainsTransparency || rCandidate.second.hasTransparency(); } @@ -471,7 +471,7 @@ void FillProperties::pushToPropMap(ShapePropertyMap& rPropMap, const GraphicHelp for (const auto& rCandidate : maGradientProps.maGradientStops) { const double fTrans(rCandidate.second.getTransparency() * (1.0/100.0)); - aTransparencyStops.emplace_back(rCandidate.first, basegfx::BColor(fTrans, fTrans, fTrans)); + aTransparencyStops.addStop(rCandidate.first, basegfx::BColor(fTrans, fTrans, fTrans)); } } diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index ebe1df3a72d8..76002bb3f40c 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -830,8 +830,8 @@ void DrawingML::WriteGradientFill( // export GradientStops (with alpha) mpFS->startElementNS(XML_a, XML_gsLst); - basegfx::BColorStops::const_iterator aCurrColor(aColorStops.begin()); - basegfx::BColorStops::const_iterator aCurrAlpha(aAlphaStops.begin()); + auto aCurrColor(aColorStops.begin()); + auto aCurrAlpha(aAlphaStops.begin()); while (aCurrColor != aColorStops.end() && aCurrAlpha != aAlphaStops.end()) { diff --git a/sd/source/ui/sidebar/SlideBackground.cxx b/sd/source/ui/sidebar/SlideBackground.cxx index 6cd8d6b4c858..07978c1c33ed 100644 --- a/sd/source/ui/sidebar/SlideBackground.cxx +++ b/sd/source/ui/sidebar/SlideBackground.cxx @@ -1289,21 +1289,11 @@ IMPL_LINK_NOARG( SlideBackground, ModifyMarginHdl, weld::ComboBox&, void ) basegfx::BColorStops SlideBackground::createColorStops() { - basegfx::BColorStops aColorStops; + basegfx::BColor aStartColor = mxFillGrad1->GetSelectEntryColor().getBColor(); + basegfx::BColor aEndColor = mxFillGrad2->GetSelectEntryColor().getBColor(); - if (maColorStops.size() >= 2) - { - aColorStops = maColorStops; - aColorStops.front() = basegfx::BColorStop(maColorStops.front().getStopOffset(), - mxFillGrad1->GetSelectEntryColor().getBColor()); - aColorStops.back() = basegfx::BColorStop(maColorStops.back().getStopOffset(), - mxFillGrad2->GetSelectEntryColor().getBColor()); - } - else - { - aColorStops.emplace_back(0.0, mxFillGrad1->GetSelectEntryColor().getBColor()); - aColorStops.emplace_back(1.0, mxFillGrad2->GetSelectEntryColor().getBColor()); - } + basegfx::BColorStops aColorStops = maColorStops; + aColorStops.setStartAndEndColors(aStartColor, aEndColor); return aColorStops; } diff --git a/svx/source/sidebar/area/AreaPropertyPanelBase.cxx b/svx/source/sidebar/area/AreaPropertyPanelBase.cxx index 682b83fc8908..eb203c2c583f 100644 --- a/svx/source/sidebar/area/AreaPropertyPanelBase.cxx +++ b/svx/source/sidebar/area/AreaPropertyPanelBase.cxx @@ -1373,23 +1373,13 @@ sal_Int32 AreaPropertyPanelBase::GetSelectedTransparencyTypeIndex() const basegfx::BColorStops AreaPropertyPanelBase::createColorStops() { - basegfx::BColorStops aColorStops; + basegfx::BColor aStartColor = mxLbFillGradFrom->GetSelectEntryColor().getBColor(); + basegfx::BColor aEndColor = mxLbFillGradTo->GetSelectEntryColor().getBColor(); - if (maColorStops.size() >= 2) - { - aColorStops = maColorStops; - aColorStops.front() = basegfx::BColorStop(maColorStops.front().getStopOffset(), - mxLbFillGradFrom->GetSelectEntryColor().getBColor()); - aColorStops.back() = basegfx::BColorStop(maColorStops.back().getStopOffset(), - mxLbFillGradTo->GetSelectEntryColor().getBColor()); - } - else - { - aColorStops.emplace_back(0.0, mxLbFillGradFrom->GetSelectEntryColor().getBColor()); - aColorStops.emplace_back(1.0, mxLbFillGradTo->GetSelectEntryColor().getBColor()); - } + basegfx::BColorStops aColorStops = maColorStops; + aColorStops.setStartAndEndColors(aStartColor, aEndColor); - return aColorStops; + return aColorStops; } void AreaPropertyPanelBase::HandleContextChange( diff --git a/svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx b/svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx index 680cf2cfc4ee..e5f835c8760f 100644 --- a/svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx +++ b/svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx @@ -139,17 +139,8 @@ void AreaTransparencyGradientPopup::ExecuteValueModify() basegfx::BColor aEndBColor(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT) / 100.0); aEndBColor.clamp(); - if (maColorStops.size() >= 2) - { - aColorStops = maColorStops; - aColorStops.front() = basegfx::BColorStop(maColorStops.front().getStopOffset(), aStartBColor); - aColorStops.back() = basegfx::BColorStop(maColorStops.back().getStopOffset(), aEndBColor); - } - else - { - aColorStops.emplace_back(0.0, aStartBColor); - aColorStops.emplace_back(1.0, aEndBColor); - } + aColorStops = maColorStops; + aColorStops.setStartAndEndColors(aStartBColor, aEndBColor); basegfx::BGradient aTmpGradient( aColorStops, diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index c3ec71eaaa30..5ffe1664cddd 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -3741,7 +3741,7 @@ void RtfAttributeOutput::FormatFillGradient(const XFillGradientItem& rFillGradie // assume what was formally GradientStyle_AXIAL, see above and also refer to // FillModel::pushToPropMap 'fFocus' value and usage. // The 2nd color is the in-between color, use it - const Color aEndColor(rColorStops[1].getStopColor()); + const Color aEndColor(rColorStops.getStop(1).getStopColor()); m_aFlyProperties.push_back(std::make_pair<OString, OString>( "fillBackColor", OString::number(wwUtility::RGBToBGR(aEndColor)))); m_aFlyProperties.push_back( diff --git a/vcl/source/filter/svm/SvmReader.cxx b/vcl/source/filter/svm/SvmReader.cxx index 56f2d933bbe9..c006596441a1 100644 --- a/vcl/source/filter/svm/SvmReader.cxx +++ b/vcl/source/filter/svm/SvmReader.cxx @@ -1360,7 +1360,7 @@ rtl::Reference<MetaAction> SvmReader::FloatTransparentHandler(ImplMetaReadData* mrStream.ReadDouble(fG); mrStream.ReadDouble(fB); - aColorStops.emplace_back(fOff, basegfx::BColor(fR, fG, fB)); + aColorStops.addStop(fOff, basegfx::BColor(fR, fG, fB)); } pAction->addSVGTransparencyColorStops(aColorStops); commit 8ff776ef046cc4d41e1f876345c0c4bcca74e939 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Mar 5 18:48:23 2023 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 19:05:48 2023 +0900 svx: use gfx::Length based types directly in SdrTextObj::NbcResize Change-Id: I839430b30685994e1767998b353c63b97f461284 diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx index d2bf4fcaac6e..dc7a0569f2de 100644 --- a/svx/source/svdraw/svdotxtr.cxx +++ b/svx/source/svdraw/svdotxtr.cxx @@ -122,81 +122,102 @@ void SdrTextObj::NbcMove(const Size& rSize) void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) { - bool bNotSheared=maGeo.m_nShearAngle==0_deg100; - bool bRotate90=bNotSheared && maGeo.m_nRotationAngle.get() % 9000 ==0; - bool bXMirr=(xFact.GetNumerator()<0) != (xFact.GetDenominator()<0); - bool bYMirr=(yFact.GetNumerator()<0) != (yFact.GetDenominator()<0); - if (bXMirr || bYMirr) { + bool bNotSheared = maGeo.m_nShearAngle == 0_deg100; + bool bRotate90 = bNotSheared && maGeo.m_nRotationAngle.get() % 9000 == 0; + + bool bXMirrored = (xFact.GetNumerator() < 0) != (xFact.GetDenominator() < 0); + bool bYMirrored = (yFact.GetNumerator() < 0) != (yFact.GetDenominator() < 0); + + double fFactorX = xFact.IsValid() ? double(xFact) : 1.0; + double fFactorY = yFact.IsValid() ? double(yFact) : 1.0; + + if (bXMirrored || bYMirrored) + { Point aRef1(GetSnapRect().Center()); - if (bXMirr) { + if (bXMirrored) + { Point aRef2(aRef1); aRef2.AdjustY( 1 ); NbcMirrorGluePoints(aRef1,aRef2); } - if (bYMirr) { + if (bYMirrored) + { Point aRef2(aRef1); aRef2.AdjustX( 1 ); NbcMirrorGluePoints(aRef1,aRef2); } } - if (maGeo.m_nRotationAngle==0_deg100 && maGeo.m_nShearAngle==0_deg100) { - auto aRectangle = getRectangle(); - ResizeRect(aRectangle, rRef, xFact, yFact); - setRectangle(aRectangle); - if (bYMirr) + if (maGeo.m_nRotationAngle == 0_deg100 && maGeo.m_nShearAngle == 0_deg100) + { + auto eUnit = getSdrModelFromSdrObject().getUnit(); + gfx::Tuple2DL aReference = createTupleFromPoint(rRef, eUnit); + svx::resizeRange(maRectangleRange, aReference, fFactorX, fFactorY); + + if (bYMirrored) { - //maRectangle.Normalize(); - moveRectangle(aRectangle.Right() - aRectangle.Left(), aRectangle.Bottom() - aRectangle.Top()); - maGeo.m_nRotationAngle=18000_deg100; + maRectangleRange.shift(maRectangleRange.getWidth(), maRectangleRange.getHeight()); + maGeo.m_nRotationAngle = 18000_deg100; maGeo.RecalcSinCos(); } } else { - tools::Polygon aPol(Rect2Poly(getRectangle(), maGeo)); + tools::Polygon aPolygon(Rect2Poly(getRectangle(), maGeo)); - for(sal_uInt16 a(0); a < aPol.GetSize(); a++) + for (sal_uInt16 a(0); a < aPolygon.GetSize(); a++) { - ResizePoint(aPol[a], rRef, xFact, yFact); + ResizePoint(aPolygon[a], rRef, xFact, yFact); } - if(bXMirr != bYMirr) + if (bXMirrored != bYMirrored) { // turn polygon and move it a little - tools::Polygon aPol0(aPol); + tools::Polygon aPol0(aPolygon); - aPol[0] = aPol0[1]; - aPol[1] = aPol0[0]; - aPol[2] = aPol0[3]; - aPol[3] = aPol0[2]; - aPol[4] = aPol0[1]; + aPolygon[0] = aPol0[1]; + aPolygon[1] = aPol0[0]; + aPolygon[2] = aPol0[3]; + aPolygon[3] = aPol0[2]; + aPolygon[4] = aPol0[1]; } - tools::Rectangle aRectangle = svx::polygonToRectangle(aPol, maGeo); + tools::Rectangle aRectangle = svx::polygonToRectangle(aPolygon, maGeo); setRectangle(aRectangle); } - if (bRotate90) { - bool bRota90=maGeo.m_nRotationAngle.get() % 9000 ==0; - if (!bRota90) { // there's seems to be a rounding error occurring: correct it - Degree100 a=NormAngle36000(maGeo.m_nRotationAngle); - if (a<4500_deg100) a=0_deg100; - else if (a<13500_deg100) a=9000_deg100; - else if (a<22500_deg100) a=18000_deg100; - else if (a<31500_deg100) a=27000_deg100; - else a=0_deg100; - maGeo.m_nRotationAngle=a; + if (bRotate90) + { + bool bRota90 = maGeo.m_nRotationAngle.get() % 9000 == 0; + if (!bRota90) + { + // there's seems to be a rounding error occurring: correct it + + Degree100 angle = NormAngle36000(maGeo.m_nRotationAngle); + if (angle < 4500_deg100) + angle = 0_deg100; + else if (angle < 13500_deg100) + angle = 9000_deg100; + else if (angle < 22500_deg100) + angle = 18000_deg100; + else if (angle < 31500_deg100) + angle = 27000_deg100; + else + angle = 0_deg100; + + maGeo.m_nRotationAngle = angle; maGeo.RecalcSinCos(); } - if (bNotSheared!=(maGeo.m_nShearAngle==0_deg100)) { // correct a rounding error occurring with Shear - maGeo.m_nShearAngle=0_deg100; + if (bNotSheared != (maGeo.m_nShearAngle == 0_deg100)) + { + // correct a rounding error occurring with Shear + maGeo.m_nShearAngle = 0_deg100; maGeo.RecalcTan(); } } AdaptTextMinSize(); - if(mbTextFrame && !getSdrModelFromSdrObject().IsPasteResize()) + if (mbTextFrame && !getSdrModelFromSdrObject().IsPasteResize()) { NbcAdjustTextFrameWidthAndHeight(); } commit 842446c6624f3b9652e3e59bf161986f9d81f4f6 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Mar 5 14:46:10 2023 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 19:02:42 2023 +0900 svx: use gfx::Length based types directly in SdrTextObj::NbcMove Change-Id: Ib0d4a9f60a2ae7f64d914c7a39aa146fef6a9f74 diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx index 3698e5a18420..d2bf4fcaac6e 100644 --- a/svx/source/svdraw/svdotxtr.cxx +++ b/svx/source/svdraw/svdotxtr.cxx @@ -40,6 +40,18 @@ using namespace com::sun::star; +namespace +{ + +gfx::Tuple2DL createTupleFromPoint(Point const& rPoint, gfx::LengthUnit eUnit = gfx::LengthUnit::hmm) +{ + auto x = gfx::Length::from(eUnit, rPoint.X()); + auto y = gfx::Length::from(eUnit, rPoint.Y()); + return gfx::Tuple2DL(x, y); +} + +} // end anonymous + void SdrTextObj::NbcSetSnapRect(const tools::Rectangle& rRect) { if (maGeo.m_nRotationAngle || maGeo.m_nShearAngle) @@ -95,8 +107,15 @@ Degree100 SdrTextObj::GetShearAngle(bool /*bVertical*/) const void SdrTextObj::NbcMove(const Size& rSize) { - moveRectangle(rSize.Width(), rSize.Height()); - moveOutRectangle(rSize.Width(), rSize.Height()); + gfx::Tuple2DL aDelta = createTupleFromPoint(Point(rSize.Width(), rSize.Height()), getSdrModelFromSdrObject().getUnit()); + gfx::Length xDelta = aDelta.getX(); + gfx::Length yDelta = aDelta.getY(); + + if (xDelta == 0_emu && yDelta == 0_emu) + return; + + maRectangleRange.shift(xDelta, yDelta); + m_aOutterRange.shift(xDelta, yDelta); maSnapRect.Move(rSize); SetBoundAndSnapRectsDirty(true); } @@ -186,19 +205,6 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract SetBoundAndSnapRectsDirty(); } -namespace -{ - -gfx::Tuple2DL createTupleFromPoint(Point const& rPoint, gfx::LengthUnit eUnit = gfx::LengthUnit::hmm) -{ - auto x = gfx::Length::from(eUnit, rPoint.X()); - auto y = gfx::Length::from(eUnit, rPoint.Y()); - return gfx::Tuple2DL(x, y); -} - -} // end anonymous - - void SdrTextObj::NbcRotate(const Point& rRef, Degree100 nAngle, double sn, double cs) { SetGlueReallyAbsolute(true); commit 6a5121eac5ffbe9d7d6477555fc7f5eb13b7aa81 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Mar 4 22:12:51 2023 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 19:02:40 2023 +0900 svx: use gfx::Length based types directly in SdrTextObj::NbcRotate Change-Id: Ic5ee712fa7507e016441595f8847649fd18b50ee diff --git a/include/svx/svdtrans.hxx b/include/svx/svdtrans.hxx index 79ef179c1a8c..62f487fc04df 100644 --- a/include/svx/svdtrans.hxx +++ b/include/svx/svdtrans.hxx @@ -46,13 +46,15 @@ SVXCORE_DLLPUBLIC void ResizeRect(tools::Rectangle& rRect, const Point& rRef, co namespace svx { SVXCORE_DLLPUBLIC void resizeRange(gfx::Range2DLWrap& rRange, gfx::Tuple2DL const& rReference, double fFactorX, double fFactorY); +SVXCORE_DLLPUBLIC gfx::Tuple2DL rotatePoint(gfx::Tuple2DL const& rPoint, gfx::Tuple2DL const& rReference, double sinAngle, double cosAngle); } inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, const Fraction& yFract); void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact); void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact); -inline void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs); +SVXCORE_DLLPUBLIC void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs); + SVXCORE_DLLPUBLIC void RotatePoly(tools::Polygon& rPoly, const Point& rRef, double sn, double cs); void RotateXPoly(XPolygon& rPoly, const Point& rRef, double sn, double cs); void RotateXPoly(XPolyPolygon& rPoly, const Point& rRef, double sn, double cs); @@ -107,14 +109,6 @@ inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, rPnt.setY(rRef.Y() + FRound( (rPnt.Y() - rRef.Y()) * nyFract )); } -inline void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs) -{ - tools::Long dx=rPnt.X()-rRef.X(); - tools::Long dy=rPnt.Y()-rRef.Y(); - rPnt.setX(FRound(rRef.X()+dx*cs+dy*sn)); - rPnt.setY(FRound(rRef.Y()+dy*cs-dx*sn)); -} - inline void ShearPoint(Point& rPnt, const Point& rRef, double tn, bool bVShear) { if (!bVShear) { // Horizontal diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index bce679c01bd6..ba6fb7d986f0 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -560,7 +560,7 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testRectangleObjectMove) pModel->GetItemPool().FreezeIdRanges(); rtl::Reference<SdrPage> pPage(new SdrPage(*pModel, false)); - pPage->setSize({50_cm, 50_cm}); + pPage->setSize({ 50_cm, 50_cm }); pModel->InsertPage(pPage.get(), 0); tools::Rectangle aRect(Point(), Size(100, 100)); @@ -582,7 +582,7 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testRectangleObjectRotate) pModel->GetItemPool().FreezeIdRanges(); rtl::Reference<SdrPage> pPage(new SdrPage(*pModel, false)); - pPage->setSize({50_cm, 50_cm}); + pPage->setSize({ 50_cm, 50_cm }); pModel->InsertPage(pPage.get(), 0); { @@ -780,6 +780,46 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testResizeRect) CPPUNIT_ASSERT_EQUAL(tools::Rectangle(6, 6, 10, 10), aRectangle); } } + +CPPUNIT_TEST_FIXTURE(SvdrawTest, testRotatePoint2D) +{ + { + auto angle = 18000_deg100; + double angleRadians = toRadians(angle); + gfx::Tuple2DL aPoint(2_cm, 1_cm); + gfx::Tuple2DL aReference(1_cm, 1_cm); + aPoint + = svx::rotatePoint(aPoint, aReference, std::sin(angleRadians), std::cos(angleRadians)); + + CPPUNIT_ASSERT_EQUAL(0_cm, aPoint.getX()); + CPPUNIT_ASSERT_EQUAL(1_cm, aPoint.getY()); + } + + { + auto angle = 9000_deg100; + double angleRadians = toRadians(angle); + gfx::Tuple2DL aPoint(2_cm, 1_cm); + gfx::Tuple2DL aReference(1_cm, 1_cm); + aPoint + = svx::rotatePoint(aPoint, aReference, std::sin(angleRadians), std::cos(angleRadians)); + + CPPUNIT_ASSERT_EQUAL(1_cm, aPoint.getX()); + CPPUNIT_ASSERT_EQUAL(0_cm, aPoint.getY()); + } + + { + auto angle = 18000_deg100; + double angleRadians = toRadians(angle); + gfx::Tuple2DL aPoint(1_cm, 1_cm); + gfx::Tuple2DL aReference(2_cm, 2_cm); + aPoint + = svx::rotatePoint(aPoint, aReference, std::sin(angleRadians), std::cos(angleRadians)); + + CPPUNIT_ASSERT_EQUAL(3_cm, aPoint.getX()); + CPPUNIT_ASSERT_EQUAL(3_cm, aPoint.getY()); + } +} + } // end anonymous namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx index ce0671da4e09..3698e5a18420 100644 --- a/svx/source/svdraw/svdotxtr.cxx +++ b/svx/source/svdraw/svdotxtr.cxx @@ -186,28 +186,50 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract SetBoundAndSnapRectsDirty(); } +namespace +{ + +gfx::Tuple2DL createTupleFromPoint(Point const& rPoint, gfx::LengthUnit eUnit = gfx::LengthUnit::hmm) +{ + auto x = gfx::Length::from(eUnit, rPoint.X()); + auto y = gfx::Length::from(eUnit, rPoint.Y()); + return gfx::Tuple2DL(x, y); +} + +} // end anonymous + + void SdrTextObj::NbcRotate(const Point& rRef, Degree100 nAngle, double sn, double cs) { SetGlueReallyAbsolute(true); - tools::Rectangle aRectangle = getRectangle(); - tools::Long dx = aRectangle.Right() - aRectangle.Left(); - tools::Long dy = aRectangle.Bottom() - aRectangle.Top(); - Point aPoint1(aRectangle.TopLeft()); - RotatePoint(aPoint1, rRef, sn, cs); - Point aPoint2(aPoint1.X() + dx, aPoint1.Y() + dy); - aRectangle = tools::Rectangle(aPoint1, aPoint2); - setRectangle(aRectangle); + gfx::Tuple2DL aReference = createTupleFromPoint(rRef, getSdrModelFromSdrObject().getUnit()); - if (maGeo.m_nRotationAngle==0_deg100) { - maGeo.m_nRotationAngle=NormAngle36000(nAngle); - maGeo.mfSinRotationAngle=sn; - maGeo.mfCosRotationAngle=cs; - } else { - maGeo.m_nRotationAngle=NormAngle36000(maGeo.m_nRotationAngle+nAngle); + gfx::Length aWidth = maRectangleRange.getWidth(); + gfx::Length aHeight = maRectangleRange.getHeight(); + + gfx::Tuple2DL aPoint(maRectangleRange.getMinX(), maRectangleRange.getMinY()); + gfx::Tuple2DL aRotated = svx::rotatePoint(aPoint, aReference, sn, cs); + + maRectangleRange = gfx::Range2DLWrap( + aRotated.getX(), + aRotated.getY(), + aRotated.getX() + aWidth, + aRotated.getY() + aHeight); + + if (maGeo.m_nRotationAngle == 0_deg100) + { + maGeo.m_nRotationAngle = NormAngle36000(nAngle); + maGeo.mfSinRotationAngle = sn; + maGeo.mfCosRotationAngle = cs; + } + else + { + maGeo.m_nRotationAngle = NormAngle36000(maGeo.m_nRotationAngle + nAngle); maGeo.RecalcSinCos(); } + SetBoundAndSnapRectsDirty(); - NbcRotateGluePoints(rRef,nAngle,sn,cs); + NbcRotateGluePoints(rRef, nAngle, sn, cs); SetGlueReallyAbsolute(false); } diff --git a/svx/source/svdraw/svdtrans.cxx b/svx/source/svdraw/svdtrans.cxx index d4c6ce015b47..725572cddab4 100644 --- a/svx/source/svdraw/svdtrans.cxx +++ b/svx/source/svdraw/svdtrans.cxx @@ -75,8 +75,24 @@ void resizeRange(gfx::Range2DLWrap& rRange, gfx::Tuple2DL const& rReference, dou rRange = gfx::Range2DLWrap(left, top, right, bottom, rRange.getUnit()); } +gfx::Tuple2DL rotatePoint(gfx::Tuple2DL const& rPoint, gfx::Tuple2DL const& rReference, double sinAngle, double cosAngle) +{ + gfx::Length dx = rPoint.getX() - rReference.getX(); + gfx::Length dy = rPoint.getY() - rReference.getY(); + gfx::Length x = rReference.getX() + dx * cosAngle + dy * sinAngle; + gfx::Length y = rReference.getY() + dy * cosAngle - dx * sinAngle; + return {x, y}; +} + } // end svx namespace +void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs) +{ + tools::Long dx=rPnt.X()-rRef.X(); + tools::Long dy=rPnt.Y()-rRef.Y(); + rPnt.setX(FRound(rRef.X()+dx*cs+dy*sn)); + rPnt.setY(FRound(rRef.Y()+dy*cs-dx*sn)); +} void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact) { commit f53a22fa2b0662d938d50a03384b207947f7aecc Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Feb 21 22:05:02 2023 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 18:59:25 2023 +0900 svx: change SdrObjGeoData aBoundRectangle using gfx::Range2DLWrap Change-Id: I13213ea2bdbfc5badb87d1bbd836192b8ae45e72 diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx index 5b2529183cbe..64f7495ad482 100644 --- a/include/svx/svdobj.hxx +++ b/include/svx/svdobj.hxx @@ -169,8 +169,20 @@ public: */ class SVXCORE_DLLPUBLIC SdrObjGeoData { +private: + gfx::Range2DLWrap maBoundRange; + public: - tools::Rectangle aBoundRect; + gfx::Range2DLWrap const& getBoundRange() const + { + return maBoundRange; + } + + void setBoundRange(gfx::Range2DLWrap const& rRange) + { + maBoundRange = rRange; + } + Point aAnchor; std::unique_ptr<SdrGluePointList> pGPL; @@ -181,7 +193,6 @@ public: bool mbVisible; SdrLayerID mnLayerID; -public: SdrObjGeoData(); virtual ~SdrObjGeoData(); }; @@ -414,6 +425,7 @@ public: // non-useful BoundRects sometimes) i rename that method from GetBoundRect() to // GetCurrentBoundRect(). virtual const tools::Rectangle& GetCurrentBoundRect() const; + virtual const gfx::Range2DLWrap& getCurrentBoundRange() const; // To have a possibility to get the last calculated BoundRect e.g for producing // the first rectangle for repaints (old and new need to be used) without forcing diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index 2a63523a3f08..6e4ecc72d900 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -966,6 +966,13 @@ const tools::Rectangle& SdrObject::GetCurrentBoundRect() const return getOutRectangle(); } +const gfx::Range2DLWrap& SdrObject::getCurrentBoundRange() const +{ + if (m_aOutterRange.isEmpty()) + const_cast<SdrObject*>(this)->RecalcBoundRect(); + return m_aOutterRange; +} + // To have a possibility to get the last calculated BoundRect e.g for producing // the first rectangle for repaints (old and new need to be used) without forcing // a RecalcBoundRect (which may be problematical and expensive sometimes) I add here @@ -1900,7 +1907,7 @@ std::unique_ptr<SdrObjGeoData> SdrObject::NewGeoData() const void SdrObject::SaveGeoData(SdrObjGeoData& rGeo) const { - rGeo.aBoundRect =GetCurrentBoundRect(); + rGeo.setBoundRange(getCurrentBoundRange()); rGeo.aAnchor =m_aAnchor ; rGeo.bMovProt =m_bMovProt ; rGeo.bSizProt =m_bSizProt ; @@ -1924,7 +1931,7 @@ void SdrObject::SaveGeoData(SdrObjGeoData& rGeo) const void SdrObject::RestoreGeoData(const SdrObjGeoData& rGeo) { SetBoundAndSnapRectsDirty(); - setOutRectangle(rGeo.aBoundRect); + m_aOutterRange = rGeo.getBoundRange(); m_aAnchor =rGeo.aAnchor ; m_bMovProt =rGeo.bMovProt ; m_bSizProt =rGeo.bSizProt ; commit 96120afda9889afbae7b4eb70f58e225520e16c4 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Feb 10 18:10:33 2023 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 18:59:25 2023 +0900 svx: refactor SdrObject resize to use m_aOutterRange directly Change-Id: I77aad10b32a53545c7f7bbf8fd87b914395a5bad diff --git a/include/svx/svdtrans.hxx b/include/svx/svdtrans.hxx index ae225426afd6..79ef179c1a8c 100644 --- a/include/svx/svdtrans.hxx +++ b/include/svx/svdtrans.hxx @@ -29,6 +29,9 @@ #include <tools/mapunit.hxx> #include <tools/poly.hxx> +#include <basegfx/units/Range2DLWrap.hxx> +#include <basegfx/units/LengthTypes.hxx> + // That maximum shear angle constexpr Degree100 SDRMAXSHEAR(8900); @@ -39,6 +42,12 @@ inline void MovePoly(tools::Polygon& rPoly, const Size& S) { rPoly.Move(S.W void MoveXPoly(XPolygon& rPoly, const Size& S); SVXCORE_DLLPUBLIC void ResizeRect(tools::Rectangle& rRect, const Point& rRef, const Fraction& xFact, const Fraction& yFact); + +namespace svx +{ +SVXCORE_DLLPUBLIC void resizeRange(gfx::Range2DLWrap& rRange, gfx::Tuple2DL const& rReference, double fFactorX, double fFactorY); +} + inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, const Fraction& yFract); void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact); void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact); diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index 0c09734461e7..bce679c01bd6 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <test/unoapixml_test.hxx> +#include <basegfx/units/Length.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> @@ -38,6 +38,8 @@ #include <sdr/contact/objectcontactofobjlistpainter.hxx> +#include <test/unoapixml_test.hxx> + using namespace ::com::sun::star; namespace @@ -671,6 +673,7 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testRotatePoint) } } +<<<<<<< HEAD CPPUNIT_TEST_FIXTURE(SvdrawTest, testClipVerticalTextOverflow) { // File contains a slide with 4 rectangle shapes with text inside @@ -714,6 +717,69 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testClipVerticalTextOverflow) assertXPath(pDocument, "((//sdrblocktext)[7]//textsimpleportion)[1]", "x", "25417"); assertXPath(pDocument, "((//sdrblocktext)[7]//textsimpleportion)[3]", "x", "23893"); } + +CPPUNIT_TEST_FIXTURE(SvdrawTest, testResizeRect) +{ + { + tools::Rectangle aRectangle(1, 1, 10, 10); + Point aReference(1, 1); + ResizeRect(aRectangle, aReference, Fraction(1, 2), Fraction(1, 2)); + + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(1, 1, 6, 6), aRectangle); + } + + { + tools::Rectangle aRectangle(1, 1, 10, 10); + Point aReference(10, 10); + ResizeRect(aRectangle, aReference, Fraction(1, 2), Fraction(1, 2)); + + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(5, 5, 10, 10), aRectangle); + } + + { + gfx::Range2DLWrap aRange(1_hmm, 1_hmm, 10_hmm, 10_hmm); + CPPUNIT_ASSERT_EQUAL(9_hmm, aRange.getWidth()); + CPPUNIT_ASSERT_EQUAL(9_hmm, aRange.getHeight()); + + gfx::Tuple2DL aReference(1_hmm, 1_hmm); + svx::resizeRange(aRange, aReference, 0.5, 0.5); + + CPPUNIT_ASSERT_EQUAL(false, aRange.isEmpty()); + + CPPUNIT_ASSERT_EQUAL(1_hmm, aRange.getMinX()); + CPPUNIT_ASSERT_EQUAL(5.5_hmm, aRange.getMaxX()); + CPPUNIT_ASSERT_EQUAL(1_hmm, aRange.getMinY()); + CPPUNIT_ASSERT_EQUAL(5.5_hmm, aRange.getMaxY()); + + CPPUNIT_ASSERT_EQUAL(4.5_hmm, aRange.getWidth()); + CPPUNIT_ASSERT_EQUAL(4.5_hmm, aRange.getHeight()); + + auto aRectangle = aRange.toToolsRect(); + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(1, 1, 6, 6), aRectangle); + } + + { + gfx::Range2DLWrap aRange(1_hmm, 1_hmm, 10_hmm, 10_hmm); + CPPUNIT_ASSERT_EQUAL(9_hmm, aRange.getWidth()); + CPPUNIT_ASSERT_EQUAL(9_hmm, aRange.getHeight()); + + gfx::Tuple2DL aReference(10_hmm, 10_hmm); + svx::resizeRange(aRange, aReference, 0.5, 0.5); + + CPPUNIT_ASSERT_EQUAL(false, aRange.isEmpty()); + + CPPUNIT_ASSERT_EQUAL(5.5_hmm, aRange.getMinX()); + CPPUNIT_ASSERT_EQUAL(10_hmm, aRange.getMaxX()); + CPPUNIT_ASSERT_EQUAL(5.5_hmm, aRange.getMinY()); + CPPUNIT_ASSERT_EQUAL(10_hmm, aRange.getMaxY()); + + CPPUNIT_ASSERT_EQUAL(4.5_hmm, aRange.getWidth()); + CPPUNIT_ASSERT_EQUAL(4.5_hmm, aRange.getHeight()); + + auto aRectangle = aRange.toToolsRect(); + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(6, 6, 10, 10), aRectangle); + } +} } // end anonymous namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index cba8f981aa85..2a63523a3f08 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -35,6 +35,7 @@ #include <basegfx/polygon/b2dpolypolygoncutter.hxx> #include <basegfx/polygon/b2dpolypolygontools.hxx> #include <basegfx/units/Range2DLWrap.hxx> +#include <basegfx/units/LengthTypes.hxx> #include <basegfx/range/b2drange.hxx> #include <drawinglayer/processor2d/contourextractor2d.hxx> #include <drawinglayer/processor2d/linegeometryextractor2d.hxx> @@ -980,10 +981,8 @@ void SdrObject::RecalcBoundRect() if ((getSdrModelFromSdrObject().isLocked()) || utl::ConfigManager::IsFuzzing()) return; - auto const& rRectangle = getOutRectangle(); - // central new method which will calculate the BoundRect using primitive geometry - if (!rRectangle.IsEmpty()) + if (!isOutRectangleEmpty()) return; // Use view-independent data - we do not want any connections @@ -1438,24 +1437,32 @@ void SdrObject::NbcMove(const Size& rSize) void SdrObject::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) { - bool bXMirr=(xFact.GetNumerator()<0) != (xFact.GetDenominator()<0); - bool bYMirr=(yFact.GetNumerator()<0) != (yFact.GetDenominator()<0); - if (bXMirr || bYMirr) { + bool bXMirror = (xFact.GetNumerator() < 0) != (xFact.GetDenominator() < 0); + bool bYMirror = (yFact.GetNumerator() < 0) != (yFact.GetDenominator() < 0); + if (bXMirror || bYMirror) + { Point aRef1(GetSnapRect().Center()); - if (bXMirr) { + if (bXMirror) + { Point aRef2(aRef1); aRef2.AdjustY( 1 ); - NbcMirrorGluePoints(aRef1,aRef2); + NbcMirrorGluePoints(aRef1, aRef2); } - if (bYMirr) { + if (bYMirror) + { Point aRef2(aRef1); aRef2.AdjustX( 1 ); - NbcMirrorGluePoints(aRef1,aRef2); + NbcMirrorGluePoints(aRef1, aRef2); } } - auto aRectangle = getOutRectangle(); - ResizeRect(aRectangle, rRef, xFact, yFact); - setOutRectangle(aRectangle); + + auto eUnit = getSdrModelFromSdrObject().getUnit(); + gfx::Tuple2DL aReference{ + gfx::Length::from(eUnit, rRef.X()), + gfx::Length::from(eUnit, rRef.Y())}; + double fFactorX = xFact.IsValid() ? double(xFact) : 1.0; + double fFactorY = yFact.IsValid() ? double(yFact) : 1.0; + svx::resizeRange(m_aOutterRange, aReference, fFactorX, fFactorY); SetBoundAndSnapRectsDirty(); } diff --git a/svx/source/svdraw/svdtrans.cxx b/svx/source/svdraw/svdtrans.cxx index 23c7495ad7d7..d4c6ce015b47 100644 --- a/svx/source/svdraw/svdtrans.cxx +++ b/svx/source/svdraw/svdtrans.cxx @@ -61,6 +61,22 @@ void ResizeRect(tools::Rectangle& rRect, const Point& rRef, const Fraction& rxFa rRect.Normalize(); } +namespace svx +{ + +void resizeRange(gfx::Range2DLWrap& rRange, gfx::Tuple2DL const& rReference, double fFactorX, double fFactorY) +{ + auto left = rReference.getX() + ((rRange.getMinX() - rReference.getX()) * fFactorX); + auto right = rReference.getX() + ((rRange.getMaxX() - rReference.getX()) * fFactorX); + + auto top = rReference.getY() + ((rRange.getMinY() - rReference.getY()) * fFactorY); + auto bottom = rReference.getY() + ((rRange.getMaxY() - rReference.getY()) * fFactorY); + + rRange = gfx::Range2DLWrap(left, top, right, bottom, rRange.getUnit()); +} + +} // end svx namespace + void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact) { commit 7d9b5468efd453a192f60ee3f8bb0ccb46202c0c Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Feb 9 10:03:43 2023 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 18:59:25 2023 +0900 use Range2DLWrap for the main rectangle in SdrTextObject Change-Id: I0d8ac090f9442fe561b4f87aa767185a987874c4 diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx index d9c0908e505b..0dac8fe682a5 100644 --- a/include/svx/svdotext.hxx +++ b/include/svx/svdotext.hxx @@ -28,6 +28,7 @@ #include <tools/datetime.hxx> #include <svl/style.hxx> #include <svx/svdtext.hxx> +#include <svx/svdmodel.hxx> #include <svx/svxdllapi.h> #include <drawinglayer/primitive2d/Primitive2DContainer.hxx> #include <memory> @@ -165,31 +166,44 @@ protected: // The "aRect" is also the rect of RectObj and CircObj. // When mbTextFrame=true the text will be formatted into this rect // When mbTextFrame=false the text will be centered around its middle - tools::Rectangle maRectangle; + gfx::Range2DLWrap maRectangleRange; tools::Rectangle const& getRectangle() const { - return maRectangle; + return maRectangleRange.toToolsRect(); } void setRectangle(tools::Rectangle const& rRectangle) { - maRectangle = rRectangle; + auto eUnit = getSdrModelFromSdrObject().getUnit(); + maRectangleRange = gfx::Range2DLWrap::create(rRectangle, eUnit); } void setRectangleSize(sal_Int32 nWidth, sal_Int32 nHeight) { - maRectangle.SetSize(Size(nWidth, nHeight)); + auto eUnit = getSdrModelFromSdrObject().getUnit(); + auto width = gfx::Length::from(eUnit, nWidth); + auto height = gfx::Length::from(eUnit, nHeight); + maRectangleRange.setSize(width, height); } void moveRectangle(sal_Int32 nXDelta, sal_Int32 nYDelta) { - maRectangle.Move(nXDelta, nYDelta); + if (nXDelta == 0 && nYDelta == 0) + return; + + auto eUnit = getSdrModelFromSdrObject().getUnit(); + auto xDelta = gfx::Length::from(eUnit, nXDelta); + auto yDelta = gfx::Length::from(eUnit, nYDelta); + maRectangleRange.shift(xDelta, yDelta); } void moveRectanglePosition(sal_Int32 nX, sal_Int32 nY) { - maRectangle.SetPos(Point(nX, nY)); + auto eUnit = getSdrModelFromSdrObject().getUnit(); + auto x = gfx::Length::from(eUnit, nX); + auto y = gfx::Length::from(eUnit, nY); + maRectangleRange.setPosition(x, y); } // The GeoStat contains the rotation and shear angles diff --git a/svx/source/svdraw/svdocirc.cxx b/svx/source/svdraw/svdocirc.cxx index becc496c76f1..deafa116328d 100644 --- a/svx/source/svdraw/svdocirc.cxx +++ b/svx/source/svdraw/svdocirc.cxx @@ -706,8 +706,9 @@ bool SdrCircObj::MovCreate(SdrDragStat& rStat) ImpSetCreateParams(rStat); ImpCircUser* pU=static_cast<ImpCircUser*>(rStat.GetUser()); rStat.SetActionRect(pU->aR); - setRectangle(pU->aR); // for ObjName - ImpJustifyRect(maRectangle); + auto aRectangle = pU->aR; + ImpJustifyRect(aRectangle); + setRectangle(aRectangle); // for ObjName nStartAngle=pU->nStart; nEndAngle=pU->nEnd; SetBoundRectDirty(); @@ -1048,8 +1049,9 @@ void SdrCircObj::NbcSetSnapRect(const tools::Rectangle& rRect) NbcResize(maSnapRect.TopLeft(),Fraction(nWdt1,nWdt0),Fraction(nHgt1,nHgt0)); NbcMove(Size(rRect.Left()-aSR0.Left(),rRect.Top()-aSR0.Top())); } else { - setRectangle(rRect); - ImpJustifyRect(maRectangle); + tools::Rectangle aRectangle(rRect); + ImpJustifyRect(aRectangle); + setRectangle(aRectangle); } SetBoundAndSnapRectsDirty(); SetXPolyDirty(); diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx index e88e127e4fa0..cb9e463261d0 100644 --- a/svx/source/svdraw/svdotext.cxx +++ b/svx/source/svdraw/svdotext.cxx @@ -105,7 +105,7 @@ SdrTextObj::SdrTextObj(SdrModel& rSdrModel, SdrTextObj const & rSource) // #i25616# mbSupportTextIndentingOnLineWidthChange = true; - maRectangle = rSource.maRectangle; + maRectangleRange = rSource.maRectangleRange; maGeo = rSource.maGeo; maTextSize = rSource.maTextSize; @@ -205,8 +205,6 @@ SdrTextObj::~SdrTextObj() void SdrTextObj::FitFrameToTextSize() { - ImpJustifyRect(maRectangle); - SdrText* pText = getActiveText(); if(pText==nullptr || !pText->GetOutlinerParaObject()) return; diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx index fbe6b0b3579b..ce0671da4e09 100644 --- a/svx/source/svdraw/svdotxtr.cxx +++ b/svx/source/svdraw/svdotxtr.cxx @@ -56,9 +56,9 @@ void SdrTextObj::NbcSetSnapRect(const tools::Rectangle& rRect) else { // No rotation or shear. - - setRectangle(rRect); - ImpJustifyRect(maRectangle); + tools::Rectangle aRectangle(rRect); + ImpJustifyRect(aRectangle); + setRectangle(aRectangle); AdaptTextMinSize(); @@ -74,8 +74,9 @@ const tools::Rectangle& SdrTextObj::GetLogicRect() const void SdrTextObj::NbcSetLogicRect(const tools::Rectangle& rRect) { - setRectangle(rRect); - ImpJustifyRect(maRectangle); + tools::Rectangle aRectangle(rRect); + ImpJustifyRect(aRectangle); + setRectangle(aRectangle); AdaptTextMinSize(); @@ -126,7 +127,7 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract setRectangle(aRectangle); if (bYMirr) { - maRectangle.Normalize(); + //maRectangle.Normalize(); moveRectangle(aRectangle.Right() - aRectangle.Left(), aRectangle.Bottom() - aRectangle.Top()); maGeo.m_nRotationAngle=18000_deg100; maGeo.RecalcSinCos(); @@ -174,8 +175,6 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract } } - ImpJustifyRect(maRectangle); - AdaptTextMinSize(); if(mbTextFrame && !getSdrModelFromSdrObject().IsPasteResize()) @@ -190,12 +189,13 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract void SdrTextObj::NbcRotate(const Point& rRef, Degree100 nAngle, double sn, double cs) { SetGlueReallyAbsolute(true); - tools::Long dx = getRectangle().Right() - getRectangle().Left(); - tools::Long dy = getRectangle().Bottom() - getRectangle().Top(); - Point aPoint1(getRectangle().TopLeft()); + tools::Rectangle aRectangle = getRectangle(); + tools::Long dx = aRectangle.Right() - aRectangle.Left(); + tools::Long dy = aRectangle.Bottom() - aRectangle.Top(); + Point aPoint1(aRectangle.TopLeft()); RotatePoint(aPoint1, rRef, sn, cs); Point aPoint2(aPoint1.X() + dx, aPoint1.Y() + dy); - tools::Rectangle aRectangle(aPoint1, aPoint2); + aRectangle = tools::Rectangle(aPoint1, aPoint2); setRectangle(aRectangle); if (maGeo.m_nRotationAngle==0_deg100) { @@ -215,16 +215,17 @@ void SdrTextObj::NbcShear(const Point& rRef, Degree100 /*nAngle*/, double tn, bo { SetGlueReallyAbsolute(true); + auto aRectangle = getRectangle(); // when this is a SdrPathObj, aRect may be uninitialized - tools::Polygon aPol(Rect2Poly(getRectangle().IsEmpty() ? GetSnapRect() : getRectangle(), maGeo)); + tools::Polygon aPol(Rect2Poly(aRectangle.IsEmpty() ? GetSnapRect() : aRectangle, maGeo)); sal_uInt16 nPointCount=aPol.GetSize(); for (sal_uInt16 i=0; i<nPointCount; i++) { ShearPoint(aPol[i],rRef,tn,bVShear); } - tools::Rectangle aRectangle = svx::polygonToRectangle(aPol, maGeo); + aRectangle = svx::polygonToRectangle(aPol, maGeo); + ImpJustifyRect(aRectangle); setRectangle(aRectangle); - ImpJustifyRect(maRectangle); if (mbTextFrame) { NbcAdjustTextFrameWidthAndHeight(); @@ -245,7 +246,7 @@ void SdrTextObj::NbcMirror(const Point& rRef1, const Point& rRef2) std::abs(rRef1.X()-rRef2.X())==std::abs(rRef1.Y()-rRef2.Y()))) { bRotate90=maGeo.m_nRotationAngle.get() % 9000 ==0; } - tools::Polygon aPol(Rect2Poly(getRectangle(),maGeo)); + tools::Polygon aPol(Rect2Poly(getRectangle(), maGeo)); sal_uInt16 i; sal_uInt16 nPointCount=aPol.GetSize(); for (i=0; i<nPointCount; i++) { @@ -279,7 +280,6 @@ void SdrTextObj::NbcMirror(const Point& rRef1, const Point& rRef2) maGeo.RecalcTan(); } - ImpJustifyRect(maRectangle); if (mbTextFrame) { NbcAdjustTextFrameWidthAndHeight(); } diff --git a/svx/source/table/svdotable.cxx b/svx/source/table/svdotable.cxx index 9398a2c98460..96bc1ab9c709 100644 --- a/svx/source/table/svdotable.cxx +++ b/svx/source/table/svdotable.cxx @@ -842,7 +842,7 @@ SdrTableObj::SdrTableObj(SdrModel& rSdrModel, SdrTableObj const & rSource) TableModelNotifyGuard aGuard( mpImpl.is() ? mpImpl->mxTable.get() : nullptr ); maLogicRect = rSource.maLogicRect; - maRectangle = rSource.maRectangle; + maRectangleRange = rSource.maRectangleRange; maGeo = rSource.maGeo; meTextKind = rSource.meTextKind; mbTextFrame = rSource.mbTextFrame; commit 08e3bd9ca9372e60e7e45e46834f47b66668e9b1 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Feb 8 10:42:19 2023 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 18:59:23 2023 +0900 use Range2DLWrap for "OutRectangle" in SdrObject Change-Id: I243b44a84bc09991744009ae24ac7657d493c5cf diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx index 631a5973bb7b..5b2529183cbe 100644 --- a/include/svx/svdobj.hxx +++ b/include/svx/svdobj.hxx @@ -34,6 +34,7 @@ #include <tools/link.hxx> #include <tools/gen.hxx> #include <unotools/resmgr.hxx> +#include <basegfx/units/Range2DLWrap.hxx> #include <unordered_set> @@ -880,13 +881,15 @@ public: void ForceMetricToItemPoolMetric(basegfx::B2DPolyPolygon& rPolyPolygon) const noexcept; protected: - const tools::Rectangle& getOutRectangle() const; + tools::Rectangle const& getOutRectangle() const; + bool isOutRectangleEmpty() const; void setOutRectangleConst(tools::Rectangle const& rRectangle) const; // need to do something about this void setOutRectangle(tools::Rectangle const& rRectangle); void resetOutRectangle(); void moveOutRectangle(sal_Int32 nXDelta, sal_Int32 nYDelta); - mutable tools::Rectangle m_aOutRect; // surrounding rectangle for Paint (incl. LineWidth, ...) + mutable gfx::Range2DLWrap m_aOutterRange; // surrounding rectangle for Paint (incl. LineWidth, ...) + Point m_aAnchor; // anchor position (Writer) SdrObjUserCall* m_pUserCall; std::unique_ptr<SdrObjPlusData> diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx index e7c3f2dfb414..4e804567c5e2 100644 --- a/include/svx/svdpage.hxx +++ b/include/svx/svdpage.hxx @@ -406,6 +406,14 @@ public: tools::Long upperUnit() const { return maUpper.as(meUnit); } tools::Long lowerUnit() const { return maLower.as(meUnit); } + bool operator==(Border const& other) const + { + return maLeft == other.maLeft + && maRight == other.maRight + && maUpper == other.maUpper + && maLower == other.maLower; + } + tools::Rectangle toToolsRect() const { return tools::Rectangle(leftUnit(), upperUnit(), rightUnit(), lowerUnit()); @@ -596,10 +604,7 @@ public: return maBorder; } - virtual void setBorder(svx::Border const& rBorder) - { - maBorder = rBorder; - } + virtual void setBorder(svx::Border const& rBorder); virtual void SetBorder(sal_Int32 nLeft, sal_Int32 nUpper, sal_Int32 nRight, sal_Int32 Lower); virtual void SetLeftBorder(sal_Int32 nBorder); diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index c5741f5007c1..cba8f981aa85 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -34,6 +34,7 @@ #include <basegfx/polygon/b2dpolygontools.hxx> #include <basegfx/polygon/b2dpolypolygoncutter.hxx> #include <basegfx/polygon/b2dpolypolygontools.hxx> +#include <basegfx/units/Range2DLWrap.hxx> #include <basegfx/range/b2drange.hxx> #include <drawinglayer/processor2d/contourextractor2d.hxx> #include <drawinglayer/processor2d/linegeometryextractor2d.hxx> @@ -959,13 +960,9 @@ void SdrObject::SetNavigationPosition (const sal_uInt32 nNewPosition) // GetCurrentBoundRect(). const tools::Rectangle& SdrObject::GetCurrentBoundRect() const { - auto const& rRectangle = getOutRectangle(); - if (rRectangle.IsEmpty()) - { - const_cast< SdrObject* >(this)->RecalcBoundRect(); - } - - return rRectangle; + if (isOutRectangleEmpty()) + const_cast<SdrObject*>(this)->RecalcBoundRect(); + return getOutRectangle(); } // To have a possibility to get the last calculated BoundRect e.g for producing @@ -1003,13 +1000,12 @@ void SdrObject::RecalcBoundRect() if (!aRange.isEmpty()) { - tools::Rectangle aNewRectangle( - tools::Long(floor(aRange.getMinX())), - tools::Long(floor(aRange.getMinY())), - tools::Long(ceil(aRange.getMaxX())), - tools::Long(ceil(aRange.getMaxY()))); - setOutRectangle(aNewRectangle); - return; + const basegfx::B2DRange aRoundedRange( + std::floor(aRange.getMinX()), + std::floor(aRange.getMinY()), + std::ceil(aRange.getMaxX()), + std::ceil(aRange.getMaxY())); + m_aOutterRange = gfx::Range2DLWrap::create(aRoundedRange, getSdrModelFromSdrObject().getUnit()); } } @@ -3159,27 +3155,41 @@ void SdrObject::ForceMetricToItemPoolMetric(basegfx::B2DPolyPolygon& rPolyPolygo const tools::Rectangle& SdrObject::getOutRectangle() const { - return m_aOutRect; + return m_aOutterRange.toToolsRect(); +} + +bool SdrObject::isOutRectangleEmpty() const +{ + return getOutRectangle().IsEmpty(); } void SdrObject::setOutRectangleConst(tools::Rectangle const& rRectangle) const { - m_aOutRect = rRectangle; + auto eUnit = getSdrModelFromSdrObject().getUnit(); + m_aOutterRange = gfx::Range2DLWrap::create(rRectangle, eUnit); } void SdrObject::setOutRectangle(tools::Rectangle const& rRectangle) { - m_aOutRect = rRectangle; + auto eUnit = getSdrModelFromSdrObject().getUnit(); + m_aOutterRange = gfx::Range2DLWrap::create(rRectangle, eUnit); } void SdrObject::resetOutRectangle() { - m_aOutRect = tools::Rectangle(); + m_aOutterRange.reset(); } void SdrObject::moveOutRectangle(sal_Int32 nXDelta, sal_Int32 nYDelta) { - m_aOutRect.Move(nXDelta, nYDelta); + if (nXDelta == 0 && nYDelta == 0) + return; + + auto eUnit = getSdrModelFromSdrObject().getUnit(); + auto xDelta = gfx::Length::from(eUnit, nXDelta); + auto yDelta = gfx::Length::from(eUnit, nYDelta); + + m_aOutterRange.shift(xDelta, yDelta); } E3dScene* DynCastE3dScene(SdrObject* pObj) diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index 56504d18999a..584ad43aad32 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -1399,16 +1399,11 @@ rtl::Reference<SdrPage> SdrPage::CloneSdrPage(SdrModel& rTargetModel) const void SdrPage::setSize(gfx::Size2DLWrap const& rSize) { - bool bChanged = false; - - if (maSize != rSize) - { - maSize = rSize; - bChanged = true; - } + if (maSize == rSize) + return; - if (bChanged) - SetChanged(); + maSize = rSize; + SetChanged(); } void SdrPage::SetOrientation(Orientation eOri) @@ -1432,6 +1427,14 @@ Orientation SdrPage::GetOrientation() const return Orientation::Portrait; } +void SdrPage::setBorder(svx::Border const& rBorder) +{ + if (maBorder == rBorder) + return; + + maBorder = rBorder; + SetChanged(); +} void SdrPage::SetBorder(sal_Int32 nLeft, sal_Int32 nUpper, sal_Int32 nRight, sal_Int32 nLower) { diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx index 5c2147ed91a9..abb16cbec672 100644 --- a/sw/source/core/draw/dcontact.cxx +++ b/sw/source/core/draw/dcontact.cxx @@ -2433,10 +2433,8 @@ void SwDrawVirtObj::NbcSetAnchorPos(const Point& rPnt) const tools::Rectangle& SwDrawVirtObj::GetCurrentBoundRect() const { - if (getOutRectangle().IsEmpty()) - { + if (isOutRectangleEmpty()) const_cast<SwDrawVirtObj*>(this)->RecalcBoundRect(); - } return getOutRectangle(); } commit 190f2f55b94271d42cb39598640b1f0164ff0bd9 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Oct 26 20:21:37 2022 +0200 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Oct 28 18:58:24 2023 +0900 svx: change PaperInfo to return gfx::Length paper sizes Change-Id: Ie99a748ab9282893a852278be9793f7379522541 diff --git a/editeng/source/items/paperinf.cxx b/editeng/source/items/paperinf.cxx index 86401e63f387..47dd992b4f02 100644 --- a/editeng/source/items/paperinf.cxx +++ b/editeng/source/items/paperinf.cxx @@ -39,6 +39,12 @@ Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit ) : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit)); } +gfx::Size2DLWrap SvxPaperInfo::getPaperSize(Paper ePaper) +{ + PaperInfo aInfo(ePaper); + return { gfx::Length::hmm(aInfo.getWidth()), gfx::Length::hmm(aInfo.getHeight()) }; +} + /*------------------------------------------------------------------------ Description: Return the paper size of the printer, aligned to our own sizes. If no Printer is set in the system, A4 portrait @@ -108,6 +114,12 @@ Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit ) : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit)); } +gfx::Size2DLWrap SvxPaperInfo::getDefaultPaperSize() +{ + PaperInfo aInfo(PaperInfo::getSystemDefaultPaper()); + return { gfx::Length::hmm(aInfo.getWidth()), gfx::Length::hmm(aInfo.getHeight()) }; +} + /*------------------------------------------------------------------------ Description: String representation for the SV-defines of paper size ------------------------------------------------------------------------*/ diff --git a/include/editeng/paperinf.hxx b/include/editeng/paperinf.hxx index 2ccc8fbf96fa..0d12100e5903 100644 --- a/include/editeng/paperinf.hxx +++ b/include/editeng/paperinf.hxx @@ -25,6 +25,7 @@ #include <tools/mapunit.hxx> #include <i18nutil/paper.hxx> #include <tools/gen.hxx> +#include <basegfx/units/Size2DLWrap.hxx> #include <editeng/editengdllapi.h> // forward --------------------------------------------------------------- @@ -42,6 +43,9 @@ public: static Paper GetSvxPaper( const Size &rSize, MapUnit eUnit ); static tools::Long GetSloppyPaperDimension( tools::Long nSize ); static OUString GetName( Paper ePaper ); + + static gfx::Size2DLWrap getPaperSize(Paper ePaper); + static gfx::Size2DLWrap getDefaultPaperSize(); }; // INLINE ----------------------------------------------------------------- diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx index 1b0eb7628d68..e7c3f2dfb414 100644 --- a/include/svx/svdpage.hxx +++ b/include/svx/svdpage.hxx @@ -384,6 +384,13 @@ public: , meUnit(eUnit) {} + Border(gfx::Length const& nLeft, gfx::Length const& nUpper, gfx::Length const& nRight, gfx::Length const& nLower) + : maLeft(nLeft) + , maRight(nRight) + , maUpper(nUpper) + , maLower(nLower) + {} + gfx::Length const& left() const { return maLeft; } gfx::Length const& right() const { return maRight; } gfx::Length const& upper() const { return maUpper; } diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx index 0ff974766163..3cbc27d585ee 100644 --- a/sd/source/core/drawdoc2.cxx +++ b/sd/source/core/drawdoc2.cxx @@ -497,7 +497,7 @@ void SdDrawDocument::CreateFirstPages( SdDrawDocument const * pRefDocument /* = return; // #i57181# Paper size depends on Language, like in Writer - Size aDefSize = SvxPaperInfo::GetDefaultPaperSize( MapUnit::Map100thMM ); + gfx::Size2DLWrap aDefaultSize = SvxPaperInfo::getDefaultPaperSize(); // Insert handout page rtl::Reference<SdPage> pHandoutPage = AllocSdPage(false); @@ -514,8 +514,8 @@ void SdDrawDocument::CreateFirstPages( SdDrawDocument const * pRefDocument /* = } else { - pHandoutPage->setToolsSize(aDefSize); - pHandoutPage->SetBorder(0, 0, 0, 0); + pHandoutPage->setSize(aDefaultSize); ... etc. - the rest is truncated