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/primitive3d/polypolygonprimitive3d.hxx>
27 #include <basegfx/polygon/b2dpolypolygontools.hxx>
28 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
29 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
30 #include <primitive3d/textureprimitive3d.hxx>
34 namespace drawinglayer::processor3d
36 // as tooling, the process() implementation takes over API handling and calls this
37 // virtual render method when the primitive implementation is BasePrimitive3D-based.
38 void Geometry2DExtractingProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D
& rCandidate
)
40 // it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
41 switch(rCandidate
.getPrimitive3DID())
43 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D
:
45 // transform group. Remember current transformations
46 const primitive3d::TransformPrimitive3D
& rPrimitive
= static_cast< const primitive3d::TransformPrimitive3D
& >(rCandidate
);
47 const geometry::ViewInformation3D
aLastViewInformation3D(getViewInformation3D());
49 // create new transformation; add new object transform from right side
50 const geometry::ViewInformation3D
aNewViewInformation3D(
51 aLastViewInformation3D
.getObjectTransformation() * rPrimitive
.getTransformation(),
52 aLastViewInformation3D
.getOrientation(),
53 aLastViewInformation3D
.getProjection(),
54 aLastViewInformation3D
.getDeviceToView(),
55 aLastViewInformation3D
.getViewTime(),
56 aLastViewInformation3D
.getExtendedInformationSequence());
57 updateViewInformation(aNewViewInformation3D
);
59 // let break down recursively
60 process(rPrimitive
.getChildren());
62 // restore transformations
63 updateViewInformation(aLastViewInformation3D
);
66 case PRIMITIVE3D_ID_MODIFIEDCOLORPRIMITIVE3D
:
68 // ModifiedColorPrimitive3D; push, process and pop
69 const primitive3d::ModifiedColorPrimitive3D
& rModifiedCandidate
= static_cast< const primitive3d::ModifiedColorPrimitive3D
& >(rCandidate
);
70 const primitive3d::Primitive3DContainer
& rSubSequence
= rModifiedCandidate
.getChildren();
72 if(!rSubSequence
.empty())
74 maBColorModifierStack
.push(rModifiedCandidate
.getColorModifier());
75 process(rModifiedCandidate
.getChildren());
76 maBColorModifierStack
.pop();
80 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D
:
82 // PolygonHairlinePrimitive3D
83 const primitive3d::PolygonHairlinePrimitive3D
& rPrimitive
= static_cast< const primitive3d::PolygonHairlinePrimitive3D
& >(rCandidate
);
84 basegfx::B2DPolygon
a2DHairline(basegfx::utils::createB2DPolygonFromB3DPolygon(rPrimitive
.getB3DPolygon(), getViewInformation3D().getObjectToView()));
86 if(a2DHairline
.count())
88 a2DHairline
.transform(getObjectTransformation());
89 const basegfx::BColor
aModifiedColor(maBColorModifierStack
.getModifiedColor(rPrimitive
.getBColor()));
90 const primitive2d::Primitive2DReference
xRef(new primitive2d::PolygonHairlinePrimitive2D(std::move(a2DHairline
), aModifiedColor
));
91 maPrimitive2DSequence
.push_back(xRef
);
95 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D
:
97 // PolyPolygonMaterialPrimitive3D
98 const primitive3d::PolyPolygonMaterialPrimitive3D
& rPrimitive
= static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D
& >(rCandidate
);
99 basegfx::B2DPolyPolygon
a2DFill(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(rPrimitive
.getB3DPolyPolygon(), getViewInformation3D().getObjectToView()));
103 a2DFill
.transform(getObjectTransformation());
104 const basegfx::BColor
aModifiedColor(maBColorModifierStack
.getModifiedColor(rPrimitive
.getMaterial().getColor()));
105 const primitive2d::Primitive2DReference
xRef(new primitive2d::PolyPolygonColorPrimitive2D(std::move(a2DFill
), aModifiedColor
));
106 maPrimitive2DSequence
.push_back(xRef
);
110 case PRIMITIVE3D_ID_GRADIENTTEXTUREPRIMITIVE3D
:
111 case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D
:
112 case PRIMITIVE3D_ID_BITMAPTEXTUREPRIMITIVE3D
:
113 case PRIMITIVE3D_ID_TRANSPARENCETEXTUREPRIMITIVE3D
:
114 case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D
:
116 // TexturePrimitive3D: Process children, do not try to decompose
117 const primitive3d::TexturePrimitive3D
& rTexturePrimitive
= static_cast< const primitive3d::TexturePrimitive3D
& >(rCandidate
);
118 const primitive3d::Primitive3DContainer
& aChildren(rTexturePrimitive
.getChildren());
120 if(!aChildren
.empty())
126 case PRIMITIVE3D_ID_SHADOWPRIMITIVE3D
:
128 // accept but ignore labels and shadow; these should be extracted separately
133 // process recursively
134 process(rCandidate
.get3DDecomposition(getViewInformation3D()));
140 Geometry2DExtractingProcessor::Geometry2DExtractingProcessor(
141 const geometry::ViewInformation3D
& rViewInformation
,
142 basegfx::B2DHomMatrix aObjectTransformation
)
143 : BaseProcessor3D(rViewInformation
),
144 maObjectTransformation(std::move(aObjectTransformation
)),
145 maBColorModifierStack()
149 } // end of namespace
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */