calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / processor2d / contourextractor2d.cxx
blob65e8ef86a29ead2c7eb9d9f55a1a10e6dae66921
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/processor2d/contourextractor2d.hxx>
21 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
23 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
24 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
25 #include <basegfx/polygon/b2dpolygontools.hxx>
26 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
27 #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
29 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
30 #include <drawinglayer/primitive2d/sceneprimitive2d.hxx>
33 using namespace com::sun::star;
36 namespace drawinglayer::processor2d
38 ContourExtractor2D::ContourExtractor2D(
39 const geometry::ViewInformation2D& rViewInformation,
40 bool bExtractFillOnly)
41 : BaseProcessor2D(rViewInformation),
42 mbExtractFillOnly(bExtractFillOnly)
46 ContourExtractor2D::~ContourExtractor2D()
50 void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
52 switch(rCandidate.getPrimitive2DID())
54 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
56 if(!mbExtractFillOnly)
58 // extract hairline in world coordinates
59 const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
60 basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
61 aLocalPolygon.transform(getViewInformation2D().getObjectTransformation());
63 if(aLocalPolygon.isClosed())
65 // line polygons need to be represented as open polygons to differentiate them
66 // from filled polygons
67 basegfx::utils::openWithGeometryChange(aLocalPolygon);
70 maExtractedContour.emplace_back(aLocalPolygon);
72 break;
74 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
76 // extract fill in world coordinates
77 const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
78 basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
79 aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation());
80 maExtractedContour.push_back(aLocalPolyPolygon);
81 break;
83 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
85 // extract BoundRect from bitmaps in world coordinates
86 const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate));
87 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform());
88 basegfx::B2DPolygon aPolygon(basegfx::utils::createUnitPolygon());
89 aPolygon.transform(aLocalTransform);
90 maExtractedContour.emplace_back(aPolygon);
91 break;
93 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
95 // extract BoundRect from MetaFiles in world coordinates
96 const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate));
97 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform());
98 basegfx::B2DPolygon aPolygon(basegfx::utils::createUnitPolygon());
99 aPolygon.transform(aLocalTransform);
100 maExtractedContour.emplace_back(aPolygon);
101 break;
103 case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D :
105 // sub-transparence group. Look at children
106 const primitive2d::TransparencePrimitive2D& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate));
107 process(rTransCandidate.getChildren());
108 break;
110 case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
112 // extract mask in world coordinates, ignore content
113 const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate));
114 basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
115 aMask.transform(getViewInformation2D().getObjectTransformation());
116 maExtractedContour.push_back(aMask);
117 break;
119 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
121 // remember current ViewInformation2D
122 const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
123 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
125 // create new local ViewInformation2D
126 geometry::ViewInformation2D aViewInformation2D(getViewInformation2D());
127 aViewInformation2D.setObjectTransformation(getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation());
128 updateViewInformation(aViewInformation2D);
130 // process content
131 process(rTransformCandidate.getChildren());
133 // restore transformations
134 updateViewInformation(aLastViewInformation2D);
136 break;
138 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
140 // 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates
141 const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate));
142 const primitive2d::Primitive2DContainer xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D());
143 const primitive2d::Primitive2DContainer xExtracted2DSceneShadow(rScenePrimitive2DCandidate.getShadow2D());
145 // process content
146 if(!xExtracted2DSceneGeometry.empty())
148 process(xExtracted2DSceneGeometry);
151 // process content
152 if(!xExtracted2DSceneShadow.empty())
154 process(xExtracted2DSceneShadow);
157 break;
159 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
160 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
161 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
163 // ignorable primitives
164 break;
166 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
167 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
169 // primitives who's BoundRect will be added in world coordinates
170 basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D()));
171 if (!aRange.isEmpty())
173 aRange.transform(getViewInformation2D().getObjectTransformation());
174 maExtractedContour.emplace_back(basegfx::utils::createPolygonFromRect(aRange));
176 break;
178 default :
180 // process recursively
181 process(rCandidate);
182 break;
187 } // end of namespace
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */