1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <processor3d/geometry2dextractor.hxx>
21 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
22 #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
23 #include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx>
24 #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
25 #include <basegfx/polygon/b2dpolygontools.hxx>
26 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
27 #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
28 #include <basegfx/polygon/b2dpolypolygontools.hxx>
29 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
30 #include <primitive3d/textureprimitive3d.hxx>
33 using namespace com::sun::star
;
36 namespace drawinglayer::processor3d
38 // as tooling, the process() implementation takes over API handling and calls this
39 // virtual render method when the primitive implementation is BasePrimitive3D-based.
40 void Geometry2DExtractingProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D
& rCandidate
)
42 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
43 switch(rCandidate
.getPrimitive3DID())
45 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D
:
47 // transform group. Remember current transformations
48 const primitive3d::TransformPrimitive3D
& rPrimitive
= static_cast< const primitive3d::TransformPrimitive3D
& >(rCandidate
);
49 const geometry::ViewInformation3D
aLastViewInformation3D(getViewInformation3D());
51 // create new transformation; add new object transform from right side
52 const geometry::ViewInformation3D
aNewViewInformation3D(
53 aLastViewInformation3D
.getObjectTransformation() * rPrimitive
.getTransformation(),
54 aLastViewInformation3D
.getOrientation(),
55 aLastViewInformation3D
.getProjection(),
56 aLastViewInformation3D
.getDeviceToView(),
57 aLastViewInformation3D
.getViewTime(),
58 aLastViewInformation3D
.getExtendedInformationSequence());
59 updateViewInformation(aNewViewInformation3D
);
61 // let break down recursively
62 process(rPrimitive
.getChildren());
64 // restore transformations
65 updateViewInformation(aLastViewInformation3D
);
68 case PRIMITIVE3D_ID_MODIFIEDCOLORPRIMITIVE3D
:
70 // ModifiedColorPrimitive3D; push, process and pop
71 const primitive3d::ModifiedColorPrimitive3D
& rModifiedCandidate
= static_cast< const primitive3d::ModifiedColorPrimitive3D
& >(rCandidate
);
72 const primitive3d::Primitive3DContainer
& rSubSequence
= rModifiedCandidate
.getChildren();
74 if(!rSubSequence
.empty())
76 maBColorModifierStack
.push(rModifiedCandidate
.getColorModifier());
77 process(rModifiedCandidate
.getChildren());
78 maBColorModifierStack
.pop();
82 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D
:
84 // PolygonHairlinePrimitive3D
85 const primitive3d::PolygonHairlinePrimitive3D
& rPrimitive
= static_cast< const primitive3d::PolygonHairlinePrimitive3D
& >(rCandidate
);
86 basegfx::B2DPolygon
a2DHairline(basegfx::utils::createB2DPolygonFromB3DPolygon(rPrimitive
.getB3DPolygon(), getViewInformation3D().getObjectToView()));
88 if(a2DHairline
.count())
90 a2DHairline
.transform(getObjectTransformation());
91 const basegfx::BColor
aModifiedColor(maBColorModifierStack
.getModifiedColor(rPrimitive
.getBColor()));
92 const primitive2d::Primitive2DReference
xRef(new primitive2d::PolygonHairlinePrimitive2D(a2DHairline
, aModifiedColor
));
93 maPrimitive2DSequence
.push_back(xRef
);
97 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D
:
99 // PolyPolygonMaterialPrimitive3D
100 const primitive3d::PolyPolygonMaterialPrimitive3D
& rPrimitive
= static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D
& >(rCandidate
);
101 basegfx::B2DPolyPolygon
a2DFill(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(rPrimitive
.getB3DPolyPolygon(), getViewInformation3D().getObjectToView()));
105 a2DFill
.transform(getObjectTransformation());
106 const basegfx::BColor
aModifiedColor(maBColorModifierStack
.getModifiedColor(rPrimitive
.getMaterial().getColor()));
107 const primitive2d::Primitive2DReference
xRef(new primitive2d::PolyPolygonColorPrimitive2D(a2DFill
, aModifiedColor
));
108 maPrimitive2DSequence
.push_back(xRef
);
112 case PRIMITIVE3D_ID_GRADIENTTEXTUREPRIMITIVE3D
:
113 case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D
:
114 case PRIMITIVE3D_ID_BITMAPTEXTUREPRIMITIVE3D
:
115 case PRIMITIVE3D_ID_TRANSPARENCETEXTUREPRIMITIVE3D
:
116 case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D
:
118 // TexturePrimitive3D: Process children, do not try to decompose
119 const primitive3d::TexturePrimitive3D
& rTexturePrimitive
= static_cast< const primitive3d::TexturePrimitive3D
& >(rCandidate
);
120 const primitive3d::Primitive3DContainer
& aChildren(rTexturePrimitive
.getChildren());
122 if(!aChildren
.empty())
128 case PRIMITIVE3D_ID_SHADOWPRIMITIVE3D
:
130 // accept but ignore labels and shadow; these should be extracted separately
135 // process recursively
136 process(rCandidate
.get3DDecomposition(getViewInformation3D()));
142 Geometry2DExtractingProcessor::Geometry2DExtractingProcessor(
143 const geometry::ViewInformation3D
& rViewInformation
,
144 const basegfx::B2DHomMatrix
& rObjectTransformation
)
145 : BaseProcessor3D(rViewInformation
),
146 maPrimitive2DSequence(),
147 maObjectTransformation(rObjectTransformation
),
148 maBColorModifierStack()
152 } // end of namespace
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */