/src/libreoffice/drawinglayer/source/tools/emfphelperdata.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <wmfemfhelper.hxx> |
23 | | #include <basegfx/matrix/b2dhommatrix.hxx> |
24 | | #include <drawinglayer/attribute/linestartendattribute.hxx> |
25 | | #include <tools/stream.hxx> |
26 | | #include <basegfx/point/b2dpoint.hxx> |
27 | | #include <map> |
28 | | |
29 | | // predefines |
30 | | namespace basegfx { class B2DPolyPolygon; } |
31 | | |
32 | | namespace emfplushelper |
33 | | { |
34 | | // EMF+ commands |
35 | 0 | #define EmfPlusRecordTypeHeader 0x4001 |
36 | 0 | #define EmfPlusRecordTypeEndOfFile 0x4002 |
37 | 0 | #define EmfPlusRecordTypeComment 0x4003 |
38 | 0 | #define EmfPlusRecordTypeGetDC 0x4004 |
39 | | //TODO EmfPlusRecordTypeMultiFormatStart 0x4005 |
40 | | //TODO EmfPlusRecordTypeMultiFormatSection 0x4006 |
41 | | //TODO EmfPlusRecordTypeMultiFormatEnd 0x4007 |
42 | 0 | #define EmfPlusRecordTypeObject 0x4008 |
43 | | //TODO EmfPlusRecordTypeClear 0x4009 |
44 | 0 | #define EmfPlusRecordTypeFillRects 0x400A |
45 | 0 | #define EmfPlusRecordTypeDrawRects 0x400B |
46 | 0 | #define EmfPlusRecordTypeFillPolygon 0x400C |
47 | 0 | #define EmfPlusRecordTypeDrawLines 0x400D |
48 | 0 | #define EmfPlusRecordTypeFillEllipse 0x400E |
49 | 0 | #define EmfPlusRecordTypeDrawEllipse 0x400F |
50 | 0 | #define EmfPlusRecordTypeFillPie 0x4010 |
51 | 0 | #define EmfPlusRecordTypeDrawPie 0x4011 |
52 | 0 | #define EmfPlusRecordTypeDrawArc 0x4012 |
53 | 0 | #define EmfPlusRecordTypeFillRegion 0x4013 |
54 | 0 | #define EmfPlusRecordTypeFillPath 0x4014 |
55 | 0 | #define EmfPlusRecordTypeDrawPath 0x4015 |
56 | 0 | #define EmfPlusRecordTypeFillClosedCurve 0x4016 |
57 | 0 | #define EmfPlusRecordTypeDrawClosedCurve 0x4017 |
58 | 0 | #define EmfPlusRecordTypeDrawCurve 0x4018 |
59 | 0 | #define EmfPlusRecordTypeDrawBeziers 0x4019 |
60 | 0 | #define EmfPlusRecordTypeDrawImage 0x401A |
61 | 0 | #define EmfPlusRecordTypeDrawImagePoints 0x401B |
62 | 0 | #define EmfPlusRecordTypeDrawString 0x401C |
63 | 0 | #define EmfPlusRecordTypeSetRenderingOrigin 0x401D |
64 | 0 | #define EmfPlusRecordTypeSetAntiAliasMode 0x401E |
65 | 0 | #define EmfPlusRecordTypeSetTextRenderingHint 0x401F |
66 | 0 | #define EmfPlusRecordTypeSetTextContrast 0x4020 |
67 | 0 | #define EmfPlusRecordTypeSetInterpolationMode 0x4021 |
68 | 0 | #define EmfPlusRecordTypeSetPixelOffsetMode 0x4022 |
69 | | //TODO EmfPlusRecordTypeSetCompositingMode 0x4023 |
70 | 0 | #define EmfPlusRecordTypeSetCompositingQuality 0x4024 |
71 | 0 | #define EmfPlusRecordTypeSave 0x4025 |
72 | 0 | #define EmfPlusRecordTypeRestore 0x4026 |
73 | 0 | #define EmfPlusRecordTypeBeginContainer 0x4027 |
74 | 0 | #define EmfPlusRecordTypeBeginContainerNoParams 0x4028 |
75 | 0 | #define EmfPlusRecordTypeEndContainer 0x4029 |
76 | 0 | #define EmfPlusRecordTypeSetWorldTransform 0x402A |
77 | 0 | #define EmfPlusRecordTypeResetWorldTransform 0x402B |
78 | 0 | #define EmfPlusRecordTypeMultiplyWorldTransform 0x402C |
79 | 0 | #define EmfPlusRecordTypeTranslateWorldTransform 0x402D |
80 | 0 | #define EmfPlusRecordTypeScaleWorldTransform 0x402E |
81 | 0 | #define EmfPlusRecordTypeRotateWorldTransform 0x402F |
82 | 0 | #define EmfPlusRecordTypeSetPageTransform 0x4030 |
83 | 0 | #define EmfPlusRecordTypeResetClip 0x4031 |
84 | 0 | #define EmfPlusRecordTypeSetClipRect 0x4032 |
85 | 0 | #define EmfPlusRecordTypeSetClipPath 0x4033 |
86 | 0 | #define EmfPlusRecordTypeSetClipRegion 0x4034 |
87 | 0 | #define EmfPlusRecordTypeOffsetClip 0x4035 |
88 | 0 | #define EmfPlusRecordTypeDrawDriverString 0x4036 |
89 | | //TODO EmfPlusRecordTypeStrokeFillPath 0x4037 |
90 | | //TODO EmfPlusRecordTypeSerializableObject 0x4038 |
91 | | //TODO EmfPlusRecordTypeSetTSGraphics 0x4039 |
92 | | //TODO EmfPlusRecordTypeSetTSClip 0x403A |
93 | | |
94 | | // EMF+object types |
95 | 0 | #define EmfPlusObjectTypeBrush 0x100 |
96 | 0 | #define EmfPlusObjectTypePen 0x200 |
97 | 0 | #define EmfPlusObjectTypePath 0x300 |
98 | 0 | #define EmfPlusObjectTypeRegion 0x400 |
99 | 0 | #define EmfPlusObjectTypeImage 0x500 |
100 | 0 | #define EmfPlusObjectTypeFont 0x600 |
101 | 0 | #define EmfPlusObjectTypeStringFormat 0x700 |
102 | 0 | #define EmfPlusObjectTypeImageAttributes 0x800 |
103 | 0 | #define EmfPlusObjectTypeCustomLineCap 0x900 |
104 | | |
105 | | enum PixelOffsetMode |
106 | | { |
107 | | PixelOffsetModeDefault = 0x00, |
108 | | PixelOffsetModeHighSpeed = 0x01, |
109 | | PixelOffsetModeHighQuality = 0x02, |
110 | | PixelOffsetModeNone = 0x03, |
111 | | PixelOffsetModeHalf = 0x04 |
112 | | }; |
113 | | |
114 | | enum SmoothingMode |
115 | | { |
116 | | SmoothingModeDefault = 0x00, |
117 | | SmoothingModeHighSpeed = 0x01, |
118 | | SmoothingModeHighQuality = 0x02, |
119 | | SmoothingModeNone = 0x03, |
120 | | SmoothingModeAntiAlias8x4 = 0x04, |
121 | | SmoothingModeAntiAlias8x8 = 0x05 |
122 | | }; |
123 | | |
124 | | enum InterpolationMode |
125 | | { |
126 | | InterpolationModeDefault = 0x00, |
127 | | InterpolationModeLowQuality = 0x01, |
128 | | InterpolationModeHighQuality = 0x02, |
129 | | InterpolationModeBilinear = 0x03, |
130 | | InterpolationModeBicubic = 0x04, |
131 | | InterpolationModeNearestNeighbor = 0x05, |
132 | | InterpolationModeHighQualityBilinear = 0x06, |
133 | | InterpolationModeHighQualityBicubic = 0x07 |
134 | | }; |
135 | | |
136 | | enum TextRenderingHint |
137 | | { |
138 | | TextRenderingHintSystemDefault = 0x00, |
139 | | TextRenderingHintSingleBitPerPixelGridFit = 0x01, |
140 | | TextRenderingHintSingleBitPerPixel = 0x02, |
141 | | TextRenderingHintAntialiasGridFit = 0x03, |
142 | | TextRenderingHintAntialias = 0x04, |
143 | | TextRenderingHintClearTypeGridFit = 0x05 |
144 | | }; |
145 | | |
146 | | enum UnitType |
147 | | { |
148 | | UnitTypeWorld = 0x00, |
149 | | UnitTypeDisplay = 0x01, |
150 | | UnitTypePixel = 0x02, |
151 | | UnitTypePoint = 0x03, |
152 | | UnitTypeInch = 0x04, |
153 | | UnitTypeDocument = 0x05, |
154 | | UnitTypeMillimeter = 0x06 |
155 | | }; |
156 | | |
157 | | enum EmfPlusCombineMode |
158 | | { |
159 | | EmfPlusCombineModeReplace = 0x00000000, |
160 | | EmfPlusCombineModeIntersect = 0x00000001, |
161 | | EmfPlusCombineModeUnion = 0x00000002, |
162 | | EmfPlusCombineModeXOR = 0x00000003, |
163 | | EmfPlusCombineModeExclude = 0x00000004, |
164 | | EmfPlusCombineModeComplement = 0x00000005 |
165 | | }; |
166 | | |
167 | | const char* emfTypeToName(sal_uInt16 type); |
168 | | OUString UnitTypeToString(sal_uInt16 nType); |
169 | | |
170 | | struct EMFPObject |
171 | | { |
172 | | virtual ~EMFPObject(); |
173 | | }; |
174 | | |
175 | | typedef std::map<int, wmfemfhelper::PropertyHolder> GraphicStateMap; |
176 | | |
177 | | struct EmfPlusHelperData |
178 | | { |
179 | | private: |
180 | | /* EMF+ */ |
181 | | basegfx::B2DHomMatrix maBaseTransform; |
182 | | basegfx::B2DHomMatrix maWorldTransform; |
183 | | basegfx::B2DHomMatrix maMapTransform; |
184 | | |
185 | | std::unique_ptr<EMFPObject> maEMFPObjects[256]; |
186 | | double mfPageScaleX; |
187 | | double mfPageScaleY; |
188 | | sal_Int32 mnOriginX; |
189 | | sal_Int32 mnOriginY; |
190 | | sal_uInt32 mnHDPI; |
191 | | sal_uInt32 mnVDPI; |
192 | | bool mbSetTextContrast; |
193 | | sal_uInt16 mnTextContrast; |
194 | | |
195 | | /* EMF+ emf header info */ |
196 | | sal_Int32 mnFrameLeft; |
197 | | sal_Int32 mnFrameTop; |
198 | | sal_Int32 mnFrameRight; |
199 | | sal_Int32 mnFrameBottom; |
200 | | sal_Int32 mnPixX; |
201 | | sal_Int32 mnPixY; |
202 | | sal_Int32 mnMmX; |
203 | | sal_Int32 mnMmY; |
204 | | |
205 | | /* multipart object data */ |
206 | | bool mbMultipart; |
207 | | sal_uInt16 mMFlags; |
208 | | SvMemoryStream mMStream; |
209 | | |
210 | | /* emf+ graphic state stack */ |
211 | | GraphicStateMap mGSStack; |
212 | | GraphicStateMap mGSContainerStack; |
213 | | |
214 | | /* Performance optimizators */ |
215 | | /* Extracted Scale values from Transformation Matrix */ |
216 | | double mdExtractedXScale; |
217 | | double mdExtractedYScale; |
218 | | |
219 | | /// data holders |
220 | | wmfemfhelper::TargetHolders& mrTargetHolders; |
221 | | wmfemfhelper::PropertyHolders& mrPropertyHolders; |
222 | | wmfemfhelper::PropertyHolder aGetDCState; |
223 | | bool bIsGetDCProcessing; |
224 | | |
225 | | // readers |
226 | | void processObjectRecord(SvMemoryStream& rObjectStream, sal_uInt16 flags, sal_uInt32 dataSize, bool bUseWholeStream = false); |
227 | | static void ReadPoint(SvStream& s, float& x, float& y, sal_uInt32 flags); |
228 | | |
229 | | // internal mapper |
230 | | void mappingChanged(); |
231 | | |
232 | | // stack actions |
233 | | void GraphicStatePush(GraphicStateMap& map, sal_Int32 index); |
234 | | void GraphicStatePop(GraphicStateMap& map, sal_Int32 index); |
235 | | |
236 | | drawinglayer::attribute::LineStartEndAttribute CreateLineEnd(const sal_Int32 aCap, |
237 | | const float aPenWidth) const; |
238 | | |
239 | | // primitive creators |
240 | | void EMFPPlusDrawPolygon(const ::basegfx::B2DPolyPolygon& polygon, sal_uInt32 penIndex); |
241 | | void EMFPPlusFillPolygon(const ::basegfx::B2DPolyPolygon& polygon, const bool isColor, const sal_uInt32 brushIndexOrColor); |
242 | | void EMFPPlusFillPolygonSolidColor(const ::basegfx::B2DPolyPolygon& polygon, Color const& color); |
243 | | |
244 | | // helper functions |
245 | | Color EMFPGetBrushColorOrARGBColor(const sal_uInt16 flags, const sal_uInt32 brushIndexOrColor) const; |
246 | | |
247 | | enum class Direction |
248 | | { |
249 | | horizontal, |
250 | | vertical |
251 | | }; |
252 | 0 | sal_uInt32 DPI(Direction d) { return d == Direction::horizontal ? mnHDPI : mnVDPI; } |
253 | | double unitToPixel(double n, sal_uInt32 aUnitType, Direction d); |
254 | | |
255 | | public: |
256 | | EmfPlusHelperData( |
257 | | SvMemoryStream& rMS, |
258 | | wmfemfhelper::TargetHolders& rTargetHolders, |
259 | | wmfemfhelper::PropertyHolders& rPropertyHolders); |
260 | | ~EmfPlusHelperData(); |
261 | | |
262 | | void processEmfPlusData( |
263 | | SvMemoryStream& rMS, |
264 | | const drawinglayer::geometry::ViewInformation2D& rViewInformation); |
265 | | |
266 | | // mappers |
267 | | ::basegfx::B2DPoint Map(double ix, double iy) const; |
268 | | |
269 | | // readers |
270 | | static void ReadRectangle(SvStream& s, float& x, float& y, float &width, float& height, bool bCompressed = false); |
271 | | static bool readXForm(SvStream& rIn, basegfx::B2DHomMatrix& rTarget); |
272 | | static ::basegfx::B2DPolyPolygon combineClip(::basegfx::B2DPolyPolygon const & leftPolygon, int combineMode, ::basegfx::B2DPolyPolygon const & rightPolygon); |
273 | | }; |
274 | | } |
275 | | |
276 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |