1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10f6e50924SAndrew Rist * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12f6e50924SAndrew Rist * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19f6e50924SAndrew Rist * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrpathobj.hxx> 28cdf0e10cSrcweir #include <svx/svdopath.hxx> 29cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrattributecreator.hxx> 30cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 31cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrpathprimitive2d.hxx> 32cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace sdr 37cdf0e10cSrcweir { 38cdf0e10cSrcweir namespace contact 39cdf0e10cSrcweir { ViewContactOfSdrPathObj(SdrPathObj & rPathObj)40cdf0e10cSrcweir ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj) 41cdf0e10cSrcweir : ViewContactOfTextObj(rPathObj) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir } 44cdf0e10cSrcweir ~ViewContactOfSdrPathObj()45cdf0e10cSrcweir ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj() 46cdf0e10cSrcweir { 47cdf0e10cSrcweir } 48cdf0e10cSrcweir createViewIndependentPrimitive2DSequence() const49cdf0e10cSrcweir drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const 50cdf0e10cSrcweir { 51cdf0e10cSrcweir const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet(); 52cdf0e10cSrcweir const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute( 53cdf0e10cSrcweir drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute( 54cdf0e10cSrcweir rItemSet, 55*4bf7a51aSArmin Le Grand GetPathObj().getText(0), 56*4bf7a51aSArmin Le Grand false)); 57cdf0e10cSrcweir basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly()); 58cdf0e10cSrcweir sal_uInt32 nPolyCount(aUnitPolyPolygon.count()); 59cdf0e10cSrcweir sal_uInt32 nPointCount(0); 60cdf0e10cSrcweir 61cdf0e10cSrcweir for(sal_uInt32 a(0); a < nPolyCount; a++) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count(); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir if(!nPointCount) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir OSL_ENSURE(false, "PolyPolygon object without geometry detected, this should not be created (!)"); 69cdf0e10cSrcweir basegfx::B2DPolygon aFallbackLine; 70cdf0e10cSrcweir aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0)); 71cdf0e10cSrcweir aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0)); 72cdf0e10cSrcweir aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine); 73cdf0e10cSrcweir 74cdf0e10cSrcweir nPolyCount = 1; 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir // prepare object transformation and unit polygon (direct model data) 78cdf0e10cSrcweir basegfx::B2DHomMatrix aObjectMatrix; 79cdf0e10cSrcweir const bool bIsLine( 80cdf0e10cSrcweir !aUnitPolyPolygon.areControlPointsUsed() 81cdf0e10cSrcweir && 1 == nPolyCount 82cdf0e10cSrcweir && 2 == aUnitPolyPolygon.getB2DPolygon(0).count()); 83cdf0e10cSrcweir 84cdf0e10cSrcweir if(bIsLine) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir // special handling for single line mode (2 points) 87cdf0e10cSrcweir const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0)); 88cdf0e10cSrcweir const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0)); 89cdf0e10cSrcweir const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1)); 90cdf0e10cSrcweir const basegfx::B2DVector aLine(aEnd - aStart); 91cdf0e10cSrcweir 92cdf0e10cSrcweir // #i102548# create new unit polygon for line (horizontal) 93cdf0e10cSrcweir basegfx::B2DPolygon aNewPolygon; 94cdf0e10cSrcweir aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0)); 95cdf0e10cSrcweir aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0)); 96cdf0e10cSrcweir aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon); 97cdf0e10cSrcweir 98cdf0e10cSrcweir // #i102548# fill objectMatrix with rotation and offset (no shear for lines) 99cdf0e10cSrcweir aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix( 100cdf0e10cSrcweir aLine.getLength(), 1.0, 101cdf0e10cSrcweir 0.0, 102cdf0e10cSrcweir atan2(aLine.getY(), aLine.getX()), 103cdf0e10cSrcweir aStart.getX(), aStart.getY()); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir else 106cdf0e10cSrcweir { 107cdf0e10cSrcweir // #i102548# create unscaled, unsheared, unrotated and untranslated polygon 108cdf0e10cSrcweir // (unit polygon) by creating the object matrix and back-transforming the polygon 109cdf0e10cSrcweir const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon)); 110cdf0e10cSrcweir const GeoStat& rGeoStat(GetPathObj().GetGeoStat()); 111cdf0e10cSrcweir const double fWidth(aObjectRange.getWidth()); 112cdf0e10cSrcweir const double fHeight(aObjectRange.getHeight()); 113cdf0e10cSrcweir const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth); 114cdf0e10cSrcweir const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight); 115cdf0e10cSrcweir 116cdf0e10cSrcweir aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix( 117cdf0e10cSrcweir fScaleX, fScaleY, 118cdf0e10cSrcweir rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0, 119cdf0e10cSrcweir rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0, 120cdf0e10cSrcweir aObjectRange.getMinX(), aObjectRange.getMinY()); 121cdf0e10cSrcweir 122cdf0e10cSrcweir // ceate unit polygon from object's absolute path 123cdf0e10cSrcweir basegfx::B2DHomMatrix aInverse(aObjectMatrix); 124cdf0e10cSrcweir aInverse.invert(); 125cdf0e10cSrcweir aUnitPolyPolygon.transform(aInverse); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir // create primitive. Always create primitives to allow the decomposition of 129cdf0e10cSrcweir // SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect 130cdf0e10cSrcweir const drawinglayer::primitive2d::Primitive2DReference xReference( 131cdf0e10cSrcweir new drawinglayer::primitive2d::SdrPathPrimitive2D( 132cdf0e10cSrcweir aObjectMatrix, 133cdf0e10cSrcweir aAttribute, 134cdf0e10cSrcweir aUnitPolyPolygon)); 135cdf0e10cSrcweir 136cdf0e10cSrcweir return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } // end of namespace contact 139cdf0e10cSrcweir } // end of namespace sdr 140cdf0e10cSrcweir 141cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 142cdf0e10cSrcweir // eof 143