diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-12-04 19:28:20 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-05 07:38:22 +0100 |
commit | b22a0178530f5b41e40b2cc2719d9e6062ea9d1a (patch) | |
tree | 6c0fca86f4be69ed9769055387482ac1032b8be2 | |
parent | 2934472ab888ebfe64a153984af2902fac63a7a0 (diff) |
improve ImpConvertContainedTextToSdrPathObjs
no need to create a temporary container
Change-Id: I60eceec1800ff57c0a600c2b049c157d94aef3b7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126370
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | svx/source/svdraw/svdotxtr.cxx | 177 |
1 files changed, 85 insertions, 92 deletions
diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx index e4cd3b9e9fcc..48a79ffde6a4 100644 --- a/svx/source/svdraw/svdotxtr.cxx +++ b/svx/source/svdraw/svdotxtr.cxx @@ -293,118 +293,111 @@ SdrObjectUniquePtr SdrTextObj::ImpConvertContainedTextToSdrPathObjs(bool bToPoly return nullptr; } - // get primitives - drawinglayer::primitive2d::Primitive2DContainer xSequence; - GetViewContact().getViewIndependentPrimitive2DContainer(xSequence); + // create an extractor with neutral ViewInformation + const drawinglayer::geometry::ViewInformation2D aViewInformation2D; + drawinglayer::processor2d::TextAsPolygonExtractor2D aExtractor(aViewInformation2D); - if(!xSequence.empty()) - { - // create an extractor with neutral ViewInformation - const drawinglayer::geometry::ViewInformation2D aViewInformation2D; - drawinglayer::processor2d::TextAsPolygonExtractor2D aExtractor(aViewInformation2D); + // extract text as polygons + GetViewContact().getViewIndependentPrimitive2DContainer(aExtractor); - // extract text as polygons - aExtractor.process(xSequence); + // get results + const drawinglayer::processor2d::TextAsPolygonDataNodeVector& rResult = aExtractor.getTarget(); + const sal_uInt32 nResultCount(rResult.size()); - // get results - const drawinglayer::processor2d::TextAsPolygonDataNodeVector& rResult = aExtractor.getTarget(); - const sal_uInt32 nResultCount(rResult.size()); + if(nResultCount) + { + // prepare own target + SdrObjGroup* pGroup = new SdrObjGroup(getSdrModelFromSdrObject()); + SdrObjList* pObjectList = pGroup->GetSubList(); - if(nResultCount) + // process results + for(sal_uInt32 a(0); a < nResultCount; a++) { - // prepare own target - SdrObjGroup* pGroup = new SdrObjGroup(getSdrModelFromSdrObject()); - SdrObjList* pObjectList = pGroup->GetSubList(); + const drawinglayer::processor2d::TextAsPolygonDataNode& rCandidate = rResult[a]; + basegfx::B2DPolyPolygon aPolyPolygon(rCandidate.getB2DPolyPolygon()); - // process results - for(sal_uInt32 a(0); a < nResultCount; a++) + if(aPolyPolygon.count()) { - const drawinglayer::processor2d::TextAsPolygonDataNode& rCandidate = rResult[a]; - basegfx::B2DPolyPolygon aPolyPolygon(rCandidate.getB2DPolyPolygon()); - - if(aPolyPolygon.count()) + // take care of wanted polygon type + if(bToPoly) { - // take care of wanted polygon type - if(bToPoly) + if(aPolyPolygon.areControlPointsUsed()) { - if(aPolyPolygon.areControlPointsUsed()) - { - aPolyPolygon = basegfx::utils::adaptiveSubdivideByAngle(aPolyPolygon); - } + aPolyPolygon = basegfx::utils::adaptiveSubdivideByAngle(aPolyPolygon); } - else + } + else + { + if(!aPolyPolygon.areControlPointsUsed()) { - if(!aPolyPolygon.areControlPointsUsed()) - { - aPolyPolygon = basegfx::utils::expandToCurve(aPolyPolygon); - } + aPolyPolygon = basegfx::utils::expandToCurve(aPolyPolygon); } + } - // create ItemSet with object attributes - SfxItemSet aAttributeSet(GetObjectItemSet()); - SdrPathObj* pPathObj = nullptr; + // create ItemSet with object attributes + SfxItemSet aAttributeSet(GetObjectItemSet()); + SdrPathObj* pPathObj = nullptr; - // always clear objectshadow; this is included in the extraction - aAttributeSet.Put(makeSdrShadowItem(false)); + // always clear objectshadow; this is included in the extraction + aAttributeSet.Put(makeSdrShadowItem(false)); - if(rCandidate.getIsFilled()) - { - // set needed items - aAttributeSet.Put(XFillColorItem(OUString(), Color(rCandidate.getBColor()))); - aAttributeSet.Put(XLineStyleItem(drawing::LineStyle_NONE)); - aAttributeSet.Put(XFillStyleItem(drawing::FillStyle_SOLID)); - - // create filled SdrPathObj - pPathObj = new SdrPathObj( - getSdrModelFromSdrObject(), - OBJ_PATHFILL, - aPolyPolygon); - } - else - { - // set needed items - aAttributeSet.Put(XLineColorItem(OUString(), Color(rCandidate.getBColor()))); - aAttributeSet.Put(XLineStyleItem(drawing::LineStyle_SOLID)); - aAttributeSet.Put(XLineWidthItem(0)); - aAttributeSet.Put(XFillStyleItem(drawing::FillStyle_NONE)); - - // create line SdrPathObj - pPathObj = new SdrPathObj( - getSdrModelFromSdrObject(), - OBJ_PATHLINE, - aPolyPolygon); - } + if(rCandidate.getIsFilled()) + { + // set needed items + aAttributeSet.Put(XFillColorItem(OUString(), Color(rCandidate.getBColor()))); + aAttributeSet.Put(XLineStyleItem(drawing::LineStyle_NONE)); + aAttributeSet.Put(XFillStyleItem(drawing::FillStyle_SOLID)); + + // create filled SdrPathObj + pPathObj = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHFILL, + aPolyPolygon); + } + else + { + // set needed items + aAttributeSet.Put(XLineColorItem(OUString(), Color(rCandidate.getBColor()))); + aAttributeSet.Put(XLineStyleItem(drawing::LineStyle_SOLID)); + aAttributeSet.Put(XLineWidthItem(0)); + aAttributeSet.Put(XFillStyleItem(drawing::FillStyle_NONE)); + + // create line SdrPathObj + pPathObj = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aPolyPolygon); + } - // copy basic information from original - pPathObj->ImpSetAnchorPos(GetAnchorPos()); - pPathObj->NbcSetLayer(GetLayer()); - pPathObj->NbcSetStyleSheet(GetStyleSheet(), true); + // copy basic information from original + pPathObj->ImpSetAnchorPos(GetAnchorPos()); + pPathObj->NbcSetLayer(GetLayer()); + pPathObj->NbcSetStyleSheet(GetStyleSheet(), true); - // apply prepared ItemSet and add to target - pPathObj->SetMergedItemSet(aAttributeSet); - pObjectList->InsertObject(pPathObj); - } + // apply prepared ItemSet and add to target + pPathObj->SetMergedItemSet(aAttributeSet); + pObjectList->InsertObject(pPathObj); } + } - // postprocess; if no result and/or only one object, simplify - if(!pObjectList->GetObjCount()) - { - // always use SdrObject::Free(...) for SdrObjects (!) - SdrObject* pTemp(pGroup); - SdrObject::Free(pTemp); - } - else if(1 == pObjectList->GetObjCount()) - { - pRetval.reset(pObjectList->RemoveObject(0)); + // postprocess; if no result and/or only one object, simplify + if(!pObjectList->GetObjCount()) + { + // always use SdrObject::Free(...) for SdrObjects (!) + SdrObject* pTemp(pGroup); + SdrObject::Free(pTemp); + } + else if(1 == pObjectList->GetObjCount()) + { + pRetval.reset(pObjectList->RemoveObject(0)); - // always use SdrObject::Free(...) for SdrObjects (!) - SdrObject* pTemp(pGroup); - SdrObject::Free(pTemp); - } - else - { - pRetval.reset(pGroup); - } + // always use SdrObject::Free(...) for SdrObjects (!) + SdrObject* pTemp(pGroup); + SdrObject::Free(pTemp); + } + else + { + pRetval.reset(pGroup); } } |