1464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5464702f4SAndrew Rist * distributed with this work for additional information 6464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10464702f4SAndrew Rist * 11464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12464702f4SAndrew Rist * 13464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14464702f4SAndrew Rist * software distributed under the License is distributed on an 15464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17464702f4SAndrew Rist * specific language governing permissions and limitations 18464702f4SAndrew Rist * under the License. 19464702f4SAndrew Rist * 20464702f4SAndrew Rist *************************************************************/ 21464702f4SAndrew Rist 22464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <drawinglayer/processor2d/contourextractor2d.hxx> 28cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 29cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 30cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 31cdf0e10cSrcweir #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx> 32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 33cdf0e10cSrcweir #include <drawinglayer/primitive2d/metafileprimitive2d.hxx> 34cdf0e10cSrcweir #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx> 35cdf0e10cSrcweir #include <drawinglayer/primitive2d/maskprimitive2d.hxx> 36cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 37cdf0e10cSrcweir #include <drawinglayer/primitive2d/sceneprimitive2d.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 40cdf0e10cSrcweir 41cdf0e10cSrcweir using namespace com::sun::star; 42cdf0e10cSrcweir 43cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 44cdf0e10cSrcweir 45cdf0e10cSrcweir namespace drawinglayer 46cdf0e10cSrcweir { 47cdf0e10cSrcweir namespace processor2d 48cdf0e10cSrcweir { ContourExtractor2D(const geometry::ViewInformation2D & rViewInformation,bool bExtractFillOnly)49db3fbf26SArmin Le Grand ContourExtractor2D::ContourExtractor2D( 50db3fbf26SArmin Le Grand const geometry::ViewInformation2D& rViewInformation, 51db3fbf26SArmin Le Grand bool bExtractFillOnly) 52cdf0e10cSrcweir : BaseProcessor2D(rViewInformation), 53db3fbf26SArmin Le Grand maExtractedContour(), 54db3fbf26SArmin Le Grand mbExtractFillOnly(bExtractFillOnly) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir } 57cdf0e10cSrcweir ~ContourExtractor2D()58cdf0e10cSrcweir ContourExtractor2D::~ContourExtractor2D() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir } 61cdf0e10cSrcweir processBasePrimitive2D(const primitive2d::BasePrimitive2D & rCandidate)62cdf0e10cSrcweir void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir switch(rCandidate.getPrimitive2DID()) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D : 67cdf0e10cSrcweir { 68db3fbf26SArmin Le Grand if(!mbExtractFillOnly) 69cdf0e10cSrcweir { 70db3fbf26SArmin Le Grand // extract hairline in world coordinates 71db3fbf26SArmin Le Grand const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate)); 72db3fbf26SArmin Le Grand basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon()); 73db3fbf26SArmin Le Grand aLocalPolygon.transform(getViewInformation2D().getObjectTransformation()); 74cdf0e10cSrcweir 75db3fbf26SArmin Le Grand if(aLocalPolygon.isClosed()) 76db3fbf26SArmin Le Grand { 77db3fbf26SArmin Le Grand // line polygons need to be represented as open polygons to differentiate them 78db3fbf26SArmin Le Grand // from filled polygons 79db3fbf26SArmin Le Grand basegfx::tools::openWithGeometryChange(aLocalPolygon); 80db3fbf26SArmin Le Grand } 81db3fbf26SArmin Le Grand 82db3fbf26SArmin Le Grand maExtractedContour.push_back(basegfx::B2DPolyPolygon(aLocalPolygon)); 83db3fbf26SArmin Le Grand } 84cdf0e10cSrcweir break; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D : 87cdf0e10cSrcweir { 88cdf0e10cSrcweir // extract fill in world coordinates 89cdf0e10cSrcweir const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate)); 90cdf0e10cSrcweir basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon()); 91cdf0e10cSrcweir aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation()); 92cdf0e10cSrcweir maExtractedContour.push_back(aLocalPolyPolygon); 93cdf0e10cSrcweir break; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D : 96cdf0e10cSrcweir { 97cdf0e10cSrcweir // extract BoundRect from bitmaps in world coordinates 98cdf0e10cSrcweir const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate)); 99cdf0e10cSrcweir basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform()); 100cdf0e10cSrcweir basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon()); 101cdf0e10cSrcweir aPolygon.transform(aLocalTransform); 102cdf0e10cSrcweir maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon)); 103cdf0e10cSrcweir break; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D : 106cdf0e10cSrcweir { 107cdf0e10cSrcweir // extract BoundRect from MetaFiles in world coordinates 108cdf0e10cSrcweir const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate)); 109cdf0e10cSrcweir basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform()); 110cdf0e10cSrcweir basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon()); 111cdf0e10cSrcweir aPolygon.transform(aLocalTransform); 112cdf0e10cSrcweir maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon)); 113cdf0e10cSrcweir break; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D : 116cdf0e10cSrcweir { 117cdf0e10cSrcweir // sub-transparence group. Look at children 118cdf0e10cSrcweir const primitive2d::TransparencePrimitive2D& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate)); 119cdf0e10cSrcweir process(rTransCandidate.getChildren()); 120cdf0e10cSrcweir break; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir case PRIMITIVE2D_ID_MASKPRIMITIVE2D : 123cdf0e10cSrcweir { 124cdf0e10cSrcweir // extract mask in world coordinates, ignore content 125cdf0e10cSrcweir const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate)); 126cdf0e10cSrcweir basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask()); 127cdf0e10cSrcweir aMask.transform(getViewInformation2D().getObjectTransformation()); 128cdf0e10cSrcweir maExtractedContour.push_back(basegfx::B2DPolyPolygon(aMask)); 129cdf0e10cSrcweir break; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D : 132cdf0e10cSrcweir { 133cdf0e10cSrcweir // remember current ViewInformation2D 134cdf0e10cSrcweir const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate)); 135cdf0e10cSrcweir const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); 136cdf0e10cSrcweir 137cdf0e10cSrcweir // create new local ViewInformation2D 138cdf0e10cSrcweir const geometry::ViewInformation2D aViewInformation2D( 139cdf0e10cSrcweir getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(), 140cdf0e10cSrcweir getViewInformation2D().getViewTransformation(), 141cdf0e10cSrcweir getViewInformation2D().getViewport(), 142cdf0e10cSrcweir getViewInformation2D().getVisualizedPage(), 143cdf0e10cSrcweir getViewInformation2D().getViewTime(), 144cdf0e10cSrcweir getViewInformation2D().getExtendedInformationSequence()); 145cdf0e10cSrcweir updateViewInformation(aViewInformation2D); 146cdf0e10cSrcweir 147*07a3d7f1SPedro Giffuni // process content 148cdf0e10cSrcweir process(rTransformCandidate.getChildren()); 149cdf0e10cSrcweir 150cdf0e10cSrcweir // restore transformations 151cdf0e10cSrcweir updateViewInformation(aLastViewInformation2D); 152cdf0e10cSrcweir 153cdf0e10cSrcweir break; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir case PRIMITIVE2D_ID_SCENEPRIMITIVE2D : 156cdf0e10cSrcweir { 157cdf0e10cSrcweir // 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates 158cdf0e10cSrcweir const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate)); 159cdf0e10cSrcweir const primitive2d::Primitive2DSequence xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D()); 160cdf0e10cSrcweir const primitive2d::Primitive2DSequence xExtracted2DSceneShadow(rScenePrimitive2DCandidate.getShadow2D(getViewInformation2D())); 161cdf0e10cSrcweir 162*07a3d7f1SPedro Giffuni // process content 163cdf0e10cSrcweir if(xExtracted2DSceneGeometry.hasElements()) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir process(xExtracted2DSceneGeometry); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168*07a3d7f1SPedro Giffuni // process content 169cdf0e10cSrcweir if(xExtracted2DSceneShadow.hasElements()) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir process(xExtracted2DSceneShadow); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir break; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D : 177cdf0e10cSrcweir case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D : 178cdf0e10cSrcweir case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D : 179cdf0e10cSrcweir { 180cdf0e10cSrcweir // ignorable primitives 181cdf0e10cSrcweir break; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D : 184cdf0e10cSrcweir case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D : 185cdf0e10cSrcweir { 186cdf0e10cSrcweir // primitives who's BoundRect will be added in world coordinates 187cdf0e10cSrcweir basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D())); 188cdf0e10cSrcweir aRange.transform(getViewInformation2D().getObjectTransformation()); 189cdf0e10cSrcweir maExtractedContour.push_back(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aRange))); 190cdf0e10cSrcweir break; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir default : 193cdf0e10cSrcweir { 194cdf0e10cSrcweir // process recursively 195cdf0e10cSrcweir process(rCandidate.get2DDecomposition(getViewInformation2D())); 196cdf0e10cSrcweir break; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir } 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir } // end of namespace processor2d 202cdf0e10cSrcweir } // end of namespace drawinglayer 203cdf0e10cSrcweir 204cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 205cdf0e10cSrcweir // eof 206