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/textaspolygonextractor2d.hxx> 32 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 33 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 34 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 35 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> 36 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 37 38 ////////////////////////////////////////////////////////////////////////////// 39 40 namespace drawinglayer 41 { 42 namespace processor2d 43 { 44 void TextAsPolygonExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) 45 { 46 switch(rCandidate.getPrimitive2DID()) 47 { 48 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D : 49 { 50 // TextDecoratedPortionPrimitive2D can produce the following primitives 51 // when being decomposed: 52 // 53 // - TextSimplePortionPrimitive2D 54 // - PolygonWavePrimitive2D 55 // - PolygonStrokePrimitive2D 56 // - PolygonStrokePrimitive2D 57 // - PolyPolygonColorPrimitive2D 58 // - PolyPolygonHairlinePrimitive2D 59 // - PolygonHairlinePrimitive2D 60 // - ShadowPrimitive2D 61 // - ModifiedColorPrimitive2D 62 // - TransformPrimitive2D 63 // - TextEffectPrimitive2D 64 // - ModifiedColorPrimitive2D 65 // - TransformPrimitive2D 66 // - GroupPrimitive2D 67 68 // encapsulate with flag and use decomposition 69 mnInText++; 70 process(rCandidate.get2DDecomposition(getViewInformation2D())); 71 mnInText--; 72 73 break; 74 } 75 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D : 76 { 77 // TextSimplePortionPrimitive2D can produce the following primitives 78 // when being decomposed: 79 // 80 // - PolyPolygonColorPrimitive2D 81 // - TextEffectPrimitive2D 82 // - ModifiedColorPrimitive2D 83 // - TransformPrimitive2D 84 // - GroupPrimitive2D 85 86 // encapsulate with flag and use decomposition 87 mnInText++; 88 process(rCandidate.get2DDecomposition(getViewInformation2D())); 89 mnInText--; 90 91 break; 92 } 93 94 // as can be seen from the TextSimplePortionPrimitive2D and the 95 // TextDecoratedPortionPrimitive2D, inside of the mnInText marks 96 // the following primitives can occurr containing geometry data 97 // from text decomposition: 98 // 99 // - PolyPolygonColorPrimitive2D 100 // - PolygonHairlinePrimitive2D 101 // - PolyPolygonHairlinePrimitive2D (for convenience) 102 // 103 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D : 104 { 105 if(mnInText) 106 { 107 const primitive2d::PolyPolygonColorPrimitive2D& rPoPoCoCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate)); 108 basegfx::B2DPolyPolygon aPolyPolygon(rPoPoCoCandidate.getB2DPolyPolygon()); 109 110 if(aPolyPolygon.count()) 111 { 112 // transform the PolyPolygon 113 aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation()); 114 115 // get evtl. corrected color 116 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoCoCandidate.getBColor())); 117 118 // add to result vector 119 maTarget.push_back(TextAsPolygonDataNode(aPolyPolygon, aColor, true)); 120 } 121 } 122 123 break; 124 } 125 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D : 126 { 127 if(mnInText) 128 { 129 const primitive2d::PolygonHairlinePrimitive2D& rPoHaCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate)); 130 basegfx::B2DPolygon aPolygon(rPoHaCandidate.getB2DPolygon()); 131 132 if(aPolygon.count()) 133 { 134 // transform the Polygon 135 aPolygon.transform(getViewInformation2D().getObjectToViewTransformation()); 136 137 // get evtl. corrected color 138 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoHaCandidate.getBColor())); 139 140 // add to result vector 141 maTarget.push_back(TextAsPolygonDataNode(basegfx::B2DPolyPolygon(aPolygon), aColor, false)); 142 } 143 } 144 145 break; 146 } 147 case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D : 148 { 149 if(mnInText) 150 { 151 const primitive2d::PolyPolygonHairlinePrimitive2D& rPoPoHaCandidate(static_cast< const primitive2d::PolyPolygonHairlinePrimitive2D& >(rCandidate)); 152 basegfx::B2DPolyPolygon aPolyPolygon(rPoPoHaCandidate.getB2DPolyPolygon()); 153 154 if(aPolyPolygon.count()) 155 { 156 // transform the Polygon 157 aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation()); 158 159 // get evtl. corrected color 160 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoHaCandidate.getBColor())); 161 162 // add to result vector 163 maTarget.push_back(TextAsPolygonDataNode(aPolyPolygon, aColor, false)); 164 } 165 } 166 167 break; 168 } 169 170 // usage of color modification stack is needed 171 case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D : 172 { 173 const primitive2d::ModifiedColorPrimitive2D& rModifiedColorCandidate(static_cast< const primitive2d::ModifiedColorPrimitive2D& >(rCandidate)); 174 175 if(rModifiedColorCandidate.getChildren().hasElements()) 176 { 177 maBColorModifierStack.push(rModifiedColorCandidate.getColorModifier()); 178 process(rModifiedColorCandidate.getChildren()); 179 maBColorModifierStack.pop(); 180 } 181 182 break; 183 } 184 185 // usage of transformation stack is needed 186 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D : 187 { 188 // remember current transformation and ViewInformation 189 const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate)); 190 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); 191 192 // create new transformations for CurrentTransformation and for local ViewInformation2D 193 const geometry::ViewInformation2D aViewInformation2D( 194 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(), 195 getViewInformation2D().getViewTransformation(), 196 getViewInformation2D().getViewport(), 197 getViewInformation2D().getVisualizedPage(), 198 getViewInformation2D().getViewTime(), 199 getViewInformation2D().getExtendedInformationSequence()); 200 updateViewInformation(aViewInformation2D); 201 202 // proccess content 203 process(rTransformCandidate.getChildren()); 204 205 // restore transformations 206 updateViewInformation(aLastViewInformation2D); 207 208 break; 209 } 210 211 // ignorable primitives 212 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D : 213 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D : 214 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D : 215 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D : 216 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D : 217 case PRIMITIVE2D_ID_RENDERGRAPHICPRIMITIVE2D : 218 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D : 219 case PRIMITIVE2D_ID_MASKPRIMITIVE2D : 220 { 221 break; 222 } 223 224 default : 225 { 226 // process recursively 227 process(rCandidate.get2DDecomposition(getViewInformation2D())); 228 break; 229 } 230 } 231 } 232 233 TextAsPolygonExtractor2D::TextAsPolygonExtractor2D(const geometry::ViewInformation2D& rViewInformation) 234 : BaseProcessor2D(rViewInformation), 235 maTarget(), 236 maBColorModifierStack(), 237 mnInText(0) 238 { 239 } 240 241 TextAsPolygonExtractor2D::~TextAsPolygonExtractor2D() 242 { 243 } 244 } // end of namespace processor2d 245 } // end of namespace drawinglayer 246 247 ////////////////////////////////////////////////////////////////////////////// 248 // eof 249