Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <drawinglayer/processor2d/contourextractor2d.hxx>
21 : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
23 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.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>
31 :
32 :
33 :
34 : using namespace com::sun::star;
35 :
36 :
37 :
38 : namespace drawinglayer
39 : {
40 : namespace processor2d
41 : {
42 0 : ContourExtractor2D::ContourExtractor2D(
43 : const geometry::ViewInformation2D& rViewInformation,
44 : bool bExtractFillOnly)
45 : : BaseProcessor2D(rViewInformation),
46 : maExtractedContour(),
47 0 : mbExtractFillOnly(bExtractFillOnly)
48 : {
49 0 : }
50 :
51 0 : ContourExtractor2D::~ContourExtractor2D()
52 : {
53 0 : }
54 :
55 0 : void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
56 : {
57 0 : switch(rCandidate.getPrimitive2DID())
58 : {
59 : case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
60 : {
61 0 : if(!mbExtractFillOnly)
62 : {
63 : // extract hairline in world coordinates
64 0 : const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
65 0 : basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
66 0 : aLocalPolygon.transform(getViewInformation2D().getObjectTransformation());
67 :
68 0 : if(aLocalPolygon.isClosed())
69 : {
70 : // line polygons need to be represented as open polygons to differentiate them
71 : // from filled polygons
72 0 : basegfx::tools::openWithGeometryChange(aLocalPolygon);
73 : }
74 :
75 0 : maExtractedContour.push_back(basegfx::B2DPolyPolygon(aLocalPolygon));
76 : }
77 0 : break;
78 : }
79 : case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
80 : {
81 : // extract fill in world coordinates
82 0 : const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
83 0 : basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
84 0 : aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation());
85 0 : maExtractedContour.push_back(aLocalPolyPolygon);
86 0 : break;
87 : }
88 : case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
89 : {
90 : // extract BoundRect from bitmaps in world coordinates
91 0 : const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate));
92 0 : basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform());
93 0 : basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
94 0 : aPolygon.transform(aLocalTransform);
95 0 : maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
96 0 : break;
97 : }
98 : case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
99 : {
100 : // extract BoundRect from MetaFiles in world coordinates
101 0 : const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate));
102 0 : basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform());
103 0 : basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
104 0 : aPolygon.transform(aLocalTransform);
105 0 : maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
106 0 : break;
107 : }
108 : case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D :
109 : {
110 : // sub-transparence group. Look at children
111 0 : const primitive2d::TransparencePrimitive2D& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate));
112 0 : process(rTransCandidate.getChildren());
113 0 : break;
114 : }
115 : case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
116 : {
117 : // extract mask in world coordinates, ignore content
118 0 : const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate));
119 0 : basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
120 0 : aMask.transform(getViewInformation2D().getObjectTransformation());
121 0 : maExtractedContour.push_back(basegfx::B2DPolyPolygon(aMask));
122 0 : break;
123 : }
124 : case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
125 : {
126 : // remember current ViewInformation2D
127 0 : const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
128 0 : const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
129 :
130 : // create new local ViewInformation2D
131 : const geometry::ViewInformation2D aViewInformation2D(
132 0 : getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
133 0 : getViewInformation2D().getViewTransformation(),
134 0 : getViewInformation2D().getViewport(),
135 0 : getViewInformation2D().getVisualizedPage(),
136 0 : getViewInformation2D().getViewTime(),
137 0 : getViewInformation2D().getExtendedInformationSequence());
138 0 : updateViewInformation(aViewInformation2D);
139 :
140 : // proccess content
141 0 : process(rTransformCandidate.getChildren());
142 :
143 : // restore transformations
144 0 : updateViewInformation(aLastViewInformation2D);
145 :
146 0 : break;
147 : }
148 : case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
149 : {
150 : // 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates
151 0 : const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate));
152 0 : const primitive2d::Primitive2DSequence xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D());
153 0 : const primitive2d::Primitive2DSequence xExtracted2DSceneShadow(rScenePrimitive2DCandidate.getShadow2D(getViewInformation2D()));
154 :
155 : // proccess content
156 0 : if(xExtracted2DSceneGeometry.hasElements())
157 : {
158 0 : process(xExtracted2DSceneGeometry);
159 : }
160 :
161 : // proccess content
162 0 : if(xExtracted2DSceneShadow.hasElements())
163 : {
164 0 : process(xExtracted2DSceneShadow);
165 : }
166 :
167 0 : break;
168 : }
169 : case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
170 : case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
171 : case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
172 : {
173 : // ignorable primitives
174 0 : break;
175 : }
176 : case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
177 : case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
178 : {
179 : // primitives who's BoundRect will be added in world coordinates
180 0 : basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D()));
181 0 : aRange.transform(getViewInformation2D().getObjectTransformation());
182 0 : maExtractedContour.push_back(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aRange)));
183 0 : break;
184 : }
185 : default :
186 : {
187 : // process recursively
188 0 : process(rCandidate.get2DDecomposition(getViewInformation2D()));
189 0 : break;
190 : }
191 : }
192 0 : }
193 :
194 : } // end of namespace processor2d
195 : } // end of namespace drawinglayer
196 :
197 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|