summaryrefslogtreecommitdiff
path: root/svx/source/svdraw/svdview.cxx
diff options
context:
space:
mode:
authorArmin Le Grand <Armin.Le.Grand@cib.de>2017-07-31 14:46:03 +0200
committerArmin Le Grand <Armin.Le.Grand@cib.de>2017-07-31 21:26:03 +0200
commitd62d07b3d29014f76c0d676c891cbafa80d0765f (patch)
tree0e5f5c4bcd2348a1ef98ad06142c0573e1c7684b /svx/source/svdraw/svdview.cxx
parent22334f8a003d26c71d772a8e00fc80b7e6d2bef1 (diff)
Corrected HitTest for layouted text
For text layouted using EditEngine the HitTest in SVX is identifying Field like URLs. Thus ist is better to use the anyways more precise primitives for HitTest (rotation/shear/ mirror, ...). This was necessary since the former mechanism which used a combination of primitive-beased HitTest and then using an Outliner to get the position/content of the Field landed on different positions e.g. when the layout needed to use multiple lines for the contained URL, but there could be more cases found. Adapted the text decompositon, the primitive HitTest and the TextHirearchyFieldPrimitive2D accordingly. Change-Id: Ice559e20d02547fdcfcf9783e7cc5481706aab03 Reviewed-on: https://gerrit.libreoffice.org/40591 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de>
Diffstat (limited to 'svx/source/svdraw/svdview.cxx')
-rw-r--r--svx/source/svdraw/svdview.cxx92
1 files changed, 57 insertions, 35 deletions
diff --git a/svx/source/svdraw/svdview.cxx b/svx/source/svdraw/svdview.cxx
index f11e6f6b0055..2ec9a93fef13 100644
--- a/svx/source/svdraw/svdview.cxx
+++ b/svx/source/svdraw/svdview.cxx
@@ -50,6 +50,7 @@
#include <svx/sdrhittesthelper.hxx>
#include <svx/sdr/contact/viewcontact.hxx>
#include <drawinglayer/processor2d/contourextractor2d.hxx>
+#include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx>
SdrViewEvent::SdrViewEvent()
@@ -440,45 +441,66 @@ SdrHitKind SdrView::PickAnything(const Point& rLogicPos, SdrViewEvent& rVEvt) co
SdrTextObj* pTextObj=dynamic_cast<SdrTextObj*>( pHitObj );
if (pTextObj!=nullptr && pTextObj->HasText())
{
- bool bTEHit(pPV &&
- SdrObjectPrimitiveHit(*pTextObj, aLocalLogicPosition, 0, *pPV, &pPV->GetVisibleLayers(), true));
-
- if (bTEHit)
+ // use the primitive-based HitTest which is more accurate anyways. It
+ // will correctly handle rotated/mirrored/sheared/scaled text and can
+ // now return a HitContainer containing the primitive hierarchy of the
+ // primitive that triggered the hit. The first entry is that primitive,
+ // the others are the full stack of primitives leading to that one which
+ // includes grouping primitives (like TextHierarchyPrimitives we deed here)
+ // but also all decomposed ones which lead to the creation of that primitive
+ drawinglayer::primitive2d::Primitive2DContainer aHitContainer;
+ const bool bTEHit(pPV && SdrObjectPrimitiveHit(*pTextObj, aLocalLogicPosition, 0, *pPV, &pPV->GetVisibleLayers(), true, &aHitContainer));
+
+ if (bTEHit && !aHitContainer.empty())
{
- tools::Rectangle aTextRect;
- tools::Rectangle aAnchor;
- SdrOutliner* pOutliner = &pTextObj->ImpGetDrawOutliner();
- if( pTextObj->GetModel() )
- pOutliner = &pTextObj->GetModel()->GetHitTestOutliner();
-
- pTextObj->TakeTextRect( *pOutliner, aTextRect, false, &aAnchor, false );
-
- // #i73628# Use a text-relative position for hit test in hit test outliner
- Point aTemporaryTextRelativePosition(aLocalLogicPosition - aTextRect.TopLeft());
-
- // account for FitToSize
- bool bFitToSize(pTextObj->IsFitToSize());
- if (bFitToSize) {
- Fraction aX(aTextRect.GetWidth()-1,aAnchor.GetWidth()-1);
- Fraction aY(aTextRect.GetHeight()-1,aAnchor.GetHeight()-1);
- ResizePoint(aTemporaryTextRelativePosition,Point(),aX,aY);
+ // search for TextHierarchyFieldPrimitive2D which contains the needed information
+ // about a possible URLField
+ const drawinglayer::primitive2d::TextHierarchyFieldPrimitive2D* pTextHierarchyFieldPrimitive2D = nullptr;
+
+ for (const drawinglayer::primitive2d::Primitive2DReference& xReference : aHitContainer)
+ {
+ if (xReference.is())
+ {
+ // try to cast to drawinglayer::primitive2d::TextHierarchyFieldPrimitive2D implementation
+ pTextHierarchyFieldPrimitive2D = dynamic_cast<const drawinglayer::primitive2d::TextHierarchyFieldPrimitive2D*>(xReference.get());
+
+ if (pTextHierarchyFieldPrimitive2D)
+ {
+ break;
+ }
+ }
}
- // account for rotation
- const GeoStat& rGeo=pTextObj->GetGeoStat();
- if (rGeo.nRotationAngle!=0) RotatePoint(aTemporaryTextRelativePosition,Point(),-rGeo.nSin,rGeo.nCos); // -sin for Unrotate
- // we currently don't account for ticker text
- if(mpActualOutDev && mpActualOutDev->GetOutDevType() == OUTDEV_WINDOW)
+
+ if (nullptr != pTextHierarchyFieldPrimitive2D)
{
- OutlinerView aOLV(pOutliner, static_cast<vcl::Window*>(mpActualOutDev.get()));
- const EditView& aEV=aOLV.GetEditView();
- const SvxFieldItem* pItem=aEV.GetField(aTemporaryTextRelativePosition);
- if (pItem!=nullptr) {
- const SvxFieldData* pFld=pItem->GetField();
- const SvxURLField* pURL=dynamic_cast<const SvxURLField*>( pFld );
- if (pURL!=nullptr) {
- eHit=SdrHitKind::UrlField;
- rVEvt.pURLField=pURL;
+ if (drawinglayer::primitive2d::FieldType::FIELD_TYPE_URL == pTextHierarchyFieldPrimitive2D->getType())
+ {
+ // problem with the old code is that a *pointer* to an instance of
+ // SvxURLField is set in the Event which is per se not good since that
+ // data comes from a temporary EditEngine's data and could vanish any
+ // moment. Have to replace for now with a static instance that gets
+ // filled/initialized from the original data held in the TextHierarchyField-
+ // Primitive2D (see impTextBreakupHandler::impCheckFieldPrimitive).
+ // Unfortunately things like 'TargetFrame' are still used in Calc, so this
+ // can currently not get replaced. For the future the Name/Value vector or
+ // the TextHierarchyFieldPrimitive2D itself should/will be used for handling
+ // that data
+ static SvxURLField aSvxURLField;
+
+ aSvxURLField.SetURL(pTextHierarchyFieldPrimitive2D->getValue("URL"));
+ aSvxURLField.SetRepresentation(pTextHierarchyFieldPrimitive2D->getValue("Representation"));
+ aSvxURLField.SetTargetFrame(pTextHierarchyFieldPrimitive2D->getValue("TargetFrame"));
+ const OUString aFormat(pTextHierarchyFieldPrimitive2D->getValue("SvxURLFormat"));
+
+ if (!aFormat.isEmpty())
+ {
+ aSvxURLField.SetFormat(static_cast<SvxURLFormat>(aFormat.toInt32()));
}
+
+ // set HitKind and pointer to local static instance in the Event
+ // to comply to old stuff
+ eHit = SdrHitKind::UrlField;
+ rVEvt.pURLField = &aSvxURLField;
}
}
}