sd/source/ui/view/Outliner.cxx | 61 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 31 deletions(-)
New commits: commit 27c7753fd6d959ed5b49e516e27b965df8b3e2c1 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri May 29 08:33:42 2020 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri May 29 08:33:42 2020 +0200 sd: remove code dupl. when getting PDF text selection for LOK Change-Id: I61d0a9851e9cfe60e9672acec38946b0b25f310f diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx index 28b73bc708b2..e6dfcb27bc0a 100644 --- a/sd/source/ui/view/Outliner.cxx +++ b/sd/source/ui/view/Outliner.cxx @@ -704,11 +704,16 @@ basegfx::B2DRange b2DRectangleFromRectangle( const ::tools::Rectangle& rRect ) rRect.IsHeightEmpty() ? rRect.Top() : rRect.Bottom()); } -void getPDFSelections(std::vector<basegfx::B2DRectangle> & rSubSelections, - std::unique_ptr<VectorGraphicSearch> & rVectorGraphicSearch, - SdrObject* pObject) +basegfx::B2DRectangle getPDFSelection(std::unique_ptr<VectorGraphicSearch> & rVectorGraphicSearch, + SdrObject* pObject) { - basegfx::B2DSize aPdfPageSize = rVectorGraphicSearch->pageSize(); + basegfx::B2DRectangle aSelection; + + auto const & rTextRectangles = rVectorGraphicSearch->getTextRectangles(); + if (rTextRectangles.empty()) + return aSelection; + + basegfx::B2DSize aPdfPageSizeHMM = rVectorGraphicSearch->pageSize(); basegfx::B2DRectangle aObjectB2DRectHMM(b2DRectangleFromRectangle(pObject->GetLogicRect())); @@ -716,23 +721,23 @@ void getPDFSelections(std::vector<basegfx::B2DRectangle> & rSubSelections, // coordinates to the page relative coordinates basegfx::B2DHomMatrix aB2DMatrix; - aB2DMatrix.scale(aObjectB2DRectHMM.getWidth() / aPdfPageSize.getX(), - aObjectB2DRectHMM.getHeight() / aPdfPageSize.getY()); + aB2DMatrix.scale(aObjectB2DRectHMM.getWidth() / aPdfPageSizeHMM.getX(), + aObjectB2DRectHMM.getHeight() / aPdfPageSizeHMM.getY()); aB2DMatrix.translate(aObjectB2DRectHMM.getMinX(), aObjectB2DRectHMM.getMinY()); - basegfx::B2DRectangle aCombined; - for (auto aRectangle : rVectorGraphicSearch->getTextRectangles()) + for (auto aRectangle : rTextRectangles) { aRectangle *= aB2DMatrix; - if (aCombined.isEmpty()) - aCombined = aRectangle; + + if (aSelection.isEmpty()) + aSelection = aRectangle; else - aCombined.expand(aRectangle); + aSelection.expand(aRectangle); } - rSubSelections.push_back(aCombined); + return aSelection; } } // end namespace @@ -744,24 +749,13 @@ void SdOutliner::sendLOKSearchResultCallback(std::shared_ptr<sd::ViewShell> & pV std::vector<::tools::Rectangle> aLogicRects; if (mpImpl->mbCurrentIsVectorGraphic) { - basegfx::B2DSize aPdfPageSize = mpImpl->mpVectorGraphicSearch->pageSize(); - - tools::Rectangle aObjectRectTwip = OutputDevice::LogicToLogic(mpObj->GetLogicRect(), MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); - basegfx::B2DRectangle aObjectB2DRectTwip(b2DRectangleFromRectangle(aObjectRectTwip)); - - // Setup coordinate conversion matrix to convert the inner PDF - // coordinates to the page relative coordinates - basegfx::B2DHomMatrix aB2DMatrix; - - aB2DMatrix.scale(aObjectB2DRectTwip.getWidth() / aPdfPageSize.getX(), - aObjectB2DRectTwip.getHeight() / aPdfPageSize.getY()); - - aB2DMatrix.translate(aObjectB2DRectTwip.getMinX(), aObjectB2DRectTwip.getMinY()); - - for (auto aRectangle : mpImpl->mpVectorGraphicSearch->getTextRectangles()) + basegfx::B2DRectangle aB2DRectangle = getPDFSelection(mpImpl->mpVectorGraphicSearch, mpObj); + if (!aB2DRectangle.isEmpty()) { - aRectangle *= aB2DMatrix; - aLogicRects.emplace_back(Point(aRectangle.getMinX(), aRectangle.getMinY()), Size(aRectangle.getWidth(), aRectangle.getHeight())); + tools::Rectangle aSelection(Point(aB2DRectangle.getMinX(), aB2DRectangle.getMinY()), + Size(aB2DRectangle.getWidth(), aB2DRectangle.getHeight())); + aSelection = OutputDevice::LogicToLogic(aSelection, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); + aLogicRects.push_back(aSelection); } } else @@ -860,7 +854,9 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti mpView->UnmarkAllObj(pPageView); std::vector<basegfx::B2DRectangle> aSubSelections; - getPDFSelections(aSubSelections, mpImpl->mpVectorGraphicSearch, mpObj); + basegfx::B2DRectangle aSubSelection = getPDFSelection(mpImpl->mpVectorGraphicSearch, mpObj); + if (!aSubSelection.isEmpty()) + aSubSelections.push_back(aSubSelection); mpView->MarkObj(mpObj, pPageView, false, false, aSubSelections); } } @@ -1261,7 +1257,10 @@ void SdOutliner::ProvideNextTextObject() mpView->UnmarkAllObj(pPageView); std::vector<basegfx::B2DRectangle> aSubSelections; - getPDFSelections(aSubSelections, mpImpl->mpVectorGraphicSearch, mpObj); + basegfx::B2DRectangle aSubSelection = getPDFSelection(mpImpl->mpVectorGraphicSearch, mpObj); + if (!aSubSelection.isEmpty()) + aSubSelections.push_back(aSubSelection); + mpView->MarkObj(mpObj, pPageView, false, false, aSubSelections); mpDrawDocument->GetDocSh()->SetWaitCursor( false ); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
