1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_drawinglayer.hxx" 30 31 #include <drawinglayer/processor2d/contourextractor2d.hxx> 32 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 33 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 34 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 35 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 36 #include <basegfx/polygon/b2dpolygontools.hxx> 37 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx> 38 #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx> 39 #include <drawinglayer/primitive2d/maskprimitive2d.hxx> 40 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 41 #include <drawinglayer/primitive2d/sceneprimitive2d.hxx> 42 43 ////////////////////////////////////////////////////////////////////////////// 44 45 using namespace com::sun::star; 46 47 ////////////////////////////////////////////////////////////////////////////// 48 49 namespace drawinglayer 50 { 51 namespace processor2d 52 { 53 ContourExtractor2D::ContourExtractor2D(const geometry::ViewInformation2D& rViewInformation) 54 : BaseProcessor2D(rViewInformation), 55 maExtractedContour() 56 { 57 } 58 59 ContourExtractor2D::~ContourExtractor2D() 60 { 61 } 62 63 void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) 64 { 65 switch(rCandidate.getPrimitive2DID()) 66 { 67 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D : 68 { 69 // extract hairline in world coordinates 70 const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate)); 71 basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon()); 72 aLocalPolygon.transform(getViewInformation2D().getObjectTransformation()); 73 74 if(aLocalPolygon.isClosed()) 75 { 76 // line polygons need to be represented as open polygons to differentiate them 77 // from filled polygons 78 basegfx::tools::openWithGeometryChange(aLocalPolygon); 79 } 80 81 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aLocalPolygon)); 82 break; 83 } 84 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D : 85 { 86 // extract fill in world coordinates 87 const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate)); 88 basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon()); 89 aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation()); 90 maExtractedContour.push_back(aLocalPolyPolygon); 91 break; 92 } 93 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D : 94 { 95 // extract BoundRect from bitmaps in world coordinates 96 const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate)); 97 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform()); 98 basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon()); 99 aPolygon.transform(aLocalTransform); 100 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon)); 101 break; 102 } 103 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D : 104 { 105 // extract BoundRect from MetaFiles in world coordinates 106 const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate)); 107 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform()); 108 basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon()); 109 aPolygon.transform(aLocalTransform); 110 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon)); 111 break; 112 } 113 case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D : 114 { 115 // sub-transparence group. Look at children 116 const primitive2d::TransparencePrimitive2D& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate)); 117 process(rTransCandidate.getChildren()); 118 break; 119 } 120 case PRIMITIVE2D_ID_MASKPRIMITIVE2D : 121 { 122 // extract mask in world coordinates, ignore content 123 const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate)); 124 basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask()); 125 aMask.transform(getViewInformation2D().getObjectTransformation()); 126 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aMask)); 127 break; 128 } 129 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D : 130 { 131 // remember current ViewInformation2D 132 const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate)); 133 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); 134 135 // create new local ViewInformation2D 136 const geometry::ViewInformation2D aViewInformation2D( 137 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(), 138 getViewInformation2D().getViewTransformation(), 139 getViewInformation2D().getViewport(), 140 getViewInformation2D().getVisualizedPage(), 141 getViewInformation2D().getViewTime(), 142 getViewInformation2D().getExtendedInformationSequence()); 143 updateViewInformation(aViewInformation2D); 144 145 // proccess content 146 process(rTransformCandidate.getChildren()); 147 148 // restore transformations 149 updateViewInformation(aLastViewInformation2D); 150 151 break; 152 } 153 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D : 154 { 155 // 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates 156 const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate)); 157 const primitive2d::Primitive2DSequence xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D()); 158 const primitive2d::Primitive2DSequence xExtracted2DSceneShadow(rScenePrimitive2DCandidate.getShadow2D(getViewInformation2D())); 159 160 // proccess content 161 if(xExtracted2DSceneGeometry.hasElements()) 162 { 163 process(xExtracted2DSceneGeometry); 164 } 165 166 // proccess content 167 if(xExtracted2DSceneShadow.hasElements()) 168 { 169 process(xExtracted2DSceneShadow); 170 } 171 172 break; 173 } 174 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D : 175 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D : 176 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D : 177 { 178 // ignorable primitives 179 break; 180 } 181 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D : 182 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D : 183 { 184 // primitives who's BoundRect will be added in world coordinates 185 basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D())); 186 aRange.transform(getViewInformation2D().getObjectTransformation()); 187 maExtractedContour.push_back(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aRange))); 188 break; 189 } 190 default : 191 { 192 // process recursively 193 process(rCandidate.get2DDecomposition(getViewInformation2D())); 194 break; 195 } 196 } 197 } 198 199 } // end of namespace processor2d 200 } // end of namespace drawinglayer 201 202 ////////////////////////////////////////////////////////////////////////////// 203 // eof 204