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 #ifndef INCLUDED_DRAWINGLAYER_INC_WMFEMFHELPER_HXX
21 #define INCLUDED_DRAWINGLAYER_INC_WMFEMFHELPER_HXX
22 
23 #include <sal/config.h>
24 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
25 #include <vcl/font.hxx>
26 #include <vcl/outdevstate.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <basegfx/polygon/b2dpolypolygon.hxx>
29 #include <memory>
30 
31 // predefines
32 namespace drawinglayer { namespace geometry { class ViewInformation2D; }}
33 class GDIMetaFile;
34 namespace wmfemfhelper { class PropertyHolder; }
35 
36 namespace wmfemfhelper
37 {
38     /** Helper class to buffer and hold a Primitive target vector. It
39     encapsulates the new/delete functionality and allows to work
40     on pointers of the implementation classes. All data will
41     be converted to uno sequences of uno references when accessing the
42     data.
43     */
44     class TargetHolder
45     {
46     private:
47         std::vector< std::unique_ptr<drawinglayer::primitive2d::BasePrimitive2D> > aTargets;
48 
49     public:
50         TargetHolder();
51         ~TargetHolder();
52         sal_uInt32 size() const;
53         void append(std::unique_ptr<drawinglayer::primitive2d::BasePrimitive2D> pCandidate);
54         drawinglayer::primitive2d::Primitive2DContainer getPrimitive2DSequence(const PropertyHolder& rPropertyHolder);
55     };
56 }
57 
58 namespace wmfemfhelper
59 {
60     /** Helper class which builds a stack on the TargetHolder class */
61     class TargetHolders
62     {
63     private:
64         std::vector< TargetHolder* >          maTargetHolders;
65 
66     public:
67         TargetHolders();
68         sal_uInt32 size() const;
69         void Push();
70         void Pop();
71         TargetHolder& Current();
72         ~TargetHolders();
73     };
74 }
75 
76 namespace wmfemfhelper
77 {
78     /** helper class for graphic context
79 
80     This class allows to hold a complete representation of classic
81     VCL OutputDevice state. This data is needed for correct
82     interpretation of the MetaFile action flow.
83     */
84     class PropertyHolder
85     {
86     private:
87         /// current transformation (aka MapMode)
88         basegfx::B2DHomMatrix   maTransformation;
89         MapUnit                 maMapUnit;
90 
91         /// current colors
92         basegfx::BColor         maLineColor;
93         basegfx::BColor         maFillColor;
94         basegfx::BColor         maTextColor;
95         basegfx::BColor         maTextFillColor;
96         basegfx::BColor         maTextLineColor;
97         basegfx::BColor         maOverlineColor;
98 
99         /// clipping
100         basegfx::B2DPolyPolygon maClipPolyPoygon;
101 
102         /// font, etc.
103         vcl::Font               maFont;
104         RasterOp                maRasterOp;
105         ComplexTextLayoutFlags   mnLayoutMode;
106         LanguageType            maLanguageType;
107         PushFlags               mnPushFlags;
108 
109         /// contains all active markers
110         bool                    mbLineColor : 1;
111         bool                    mbFillColor : 1;
112         bool                    mbTextColor : 1;
113         bool                    mbTextFillColor : 1;
114         bool                    mbTextLineColor : 1;
115         bool                    mbOverlineColor : 1;
116         bool                    mbClipPolyPolygonActive : 1;
117 
118     public:
119         PropertyHolder();
120 
121         /// read/write accesses
getTransformation() const122         const basegfx::B2DHomMatrix& getTransformation() const { return maTransformation; }
setTransformation(const basegfx::B2DHomMatrix & rNew)123         void setTransformation(const basegfx::B2DHomMatrix& rNew) { if (rNew != maTransformation) maTransformation = rNew; }
124 
getMapUnit() const125         MapUnit getMapUnit() const { return maMapUnit; }
setMapUnit(MapUnit eNew)126         void setMapUnit(MapUnit eNew) { if (eNew != maMapUnit) maMapUnit = eNew; }
127 
getLineColor() const128         const basegfx::BColor& getLineColor() const { return maLineColor; }
setLineColor(const basegfx::BColor & rNew)129         void setLineColor(const basegfx::BColor& rNew) { if (rNew != maLineColor) maLineColor = rNew; }
getLineColorActive() const130         bool getLineColorActive() const { return mbLineColor; }
setLineColorActive(bool bNew)131         void setLineColorActive(bool bNew) { if (bNew != mbLineColor) mbLineColor = bNew; }
132 
getFillColor() const133         const basegfx::BColor& getFillColor() const { return maFillColor; }
setFillColor(const basegfx::BColor & rNew)134         void setFillColor(const basegfx::BColor& rNew) { if (rNew != maFillColor) maFillColor = rNew; }
getFillColorActive() const135         bool getFillColorActive() const { return mbFillColor; }
setFillColorActive(bool bNew)136         void setFillColorActive(bool bNew) { if (bNew != mbFillColor) mbFillColor = bNew; }
137 
getTextColor() const138         const basegfx::BColor& getTextColor() const { return maTextColor; }
setTextColor(const basegfx::BColor & rNew)139         void setTextColor(const basegfx::BColor& rNew) { if (rNew != maTextColor) maTextColor = rNew; }
getTextColorActive() const140         bool getTextColorActive() const { return mbTextColor; }
setTextColorActive(bool bNew)141         void setTextColorActive(bool bNew) { if (bNew != mbTextColor) mbTextColor = bNew; }
142 
getTextFillColor() const143         const basegfx::BColor& getTextFillColor() const { return maTextFillColor; }
setTextFillColor(const basegfx::BColor & rNew)144         void setTextFillColor(const basegfx::BColor& rNew) { if (rNew != maTextFillColor) maTextFillColor = rNew; }
getTextFillColorActive() const145         bool getTextFillColorActive() const { return mbTextFillColor; }
setTextFillColorActive(bool bNew)146         void setTextFillColorActive(bool bNew) { if (bNew != mbTextFillColor) mbTextFillColor = bNew; }
147 
getTextLineColor() const148         const basegfx::BColor& getTextLineColor() const { return maTextLineColor; }
setTextLineColor(const basegfx::BColor & rNew)149         void setTextLineColor(const basegfx::BColor& rNew) { if (rNew != maTextLineColor) maTextLineColor = rNew; }
getTextLineColorActive() const150         bool getTextLineColorActive() const { return mbTextLineColor; }
setTextLineColorActive(bool bNew)151         void setTextLineColorActive(bool bNew) { if (bNew != mbTextLineColor) mbTextLineColor = bNew; }
152 
getOverlineColor() const153         const basegfx::BColor& getOverlineColor() const { return maOverlineColor; }
setOverlineColor(const basegfx::BColor & rNew)154         void setOverlineColor(const basegfx::BColor& rNew) { if (rNew != maOverlineColor) maOverlineColor = rNew; }
getOverlineColorActive() const155         bool getOverlineColorActive() const { return mbOverlineColor; }
setOverlineColorActive(bool bNew)156         void setOverlineColorActive(bool bNew) { if (bNew != mbOverlineColor) mbOverlineColor = bNew; }
157 
getClipPolyPolygon() const158         const basegfx::B2DPolyPolygon& getClipPolyPolygon() const { return maClipPolyPoygon; }
setClipPolyPolygon(const basegfx::B2DPolyPolygon & rNew)159         void setClipPolyPolygon(const basegfx::B2DPolyPolygon& rNew) { if (rNew != maClipPolyPoygon) maClipPolyPoygon = rNew; }
getClipPolyPolygonActive() const160         bool getClipPolyPolygonActive() const { return mbClipPolyPolygonActive; }
setClipPolyPolygonActive(bool bNew)161         void setClipPolyPolygonActive(bool bNew) { if (bNew != mbClipPolyPolygonActive) mbClipPolyPolygonActive = bNew; }
162 
getFont() const163         const vcl::Font& getFont() const { return maFont; }
setFont(const vcl::Font & rFont)164         void setFont(const vcl::Font& rFont) { if (rFont != maFont) maFont = rFont; }
165 
getRasterOp() const166         const RasterOp& getRasterOp() const { return maRasterOp; }
setRasterOp(const RasterOp & rRasterOp)167         void setRasterOp(const RasterOp& rRasterOp) { if (rRasterOp != maRasterOp) maRasterOp = rRasterOp; }
isRasterOpInvert() const168         bool isRasterOpInvert() const { return (RasterOp::Xor == maRasterOp || RasterOp::Invert == maRasterOp); }
isRasterOpForceBlack() const169         bool isRasterOpForceBlack() const { return RasterOp::N0 == maRasterOp; }
isRasterOpActive() const170         bool isRasterOpActive() const { return isRasterOpInvert() || isRasterOpForceBlack(); }
171 
getLayoutMode() const172         ComplexTextLayoutFlags getLayoutMode() const { return mnLayoutMode; }
setLayoutMode(ComplexTextLayoutFlags nNew)173         void setLayoutMode(ComplexTextLayoutFlags nNew) { if (nNew != mnLayoutMode) mnLayoutMode = nNew; }
174 
getLanguageType() const175         LanguageType getLanguageType() const { return maLanguageType; }
setLanguageType(LanguageType aNew)176         void setLanguageType(LanguageType aNew) { if (aNew != maLanguageType) maLanguageType = aNew; }
177 
getPushFlags() const178         PushFlags getPushFlags() const { return mnPushFlags; }
setPushFlags(PushFlags nNew)179         void setPushFlags(PushFlags nNew) { if (nNew != mnPushFlags) mnPushFlags = nNew; }
180 
getLineOrFillActive() const181         bool getLineOrFillActive() const { return (mbLineColor || mbFillColor); }
182     };
183 }
184 
185 namespace wmfemfhelper
186 {
187     /** stack for properties
188 
189     This class builds a stack based on the PropertyHolder
190     class. It encapsulates the pointer/new/delete usage to
191     make it safe and implements the push/pop as needed by a
192     VCL Metafile interpreter. The critical part here are the
193     flag values VCL OutputDevice uses here; not all stuff is
194     pushed and thus needs to be copied at pop.
195     */
196     class PropertyHolders
197     {
198     private:
199         std::vector< PropertyHolder* >          maPropertyHolders;
200 
201     public:
202         PropertyHolders();
203         void PushDefault();
204         void Push(PushFlags nPushFlags);
205         void Pop();
206         PropertyHolder& Current();
207         ~PropertyHolders();
208     };
209 }
210 
211 namespace wmfemfhelper
212 {
213     drawinglayer::primitive2d::Primitive2DContainer interpretMetafile(
214         const GDIMetaFile& rMetaFile,
215         const drawinglayer::geometry::ViewInformation2D& rViewInformation);
216 
217     void HandleNewClipRegion(
218         const basegfx::B2DPolyPolygon& rClipPolyPolygon,
219         TargetHolders& rTargetHolders,
220         PropertyHolders& rPropertyHolders);
221 }
222 
223 #endif
224 
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
226