calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / tools / emfphelperdata.hxx
blobef870f31e6879e7512a7700a4a4473310997c6de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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>
29 // predefines
30 class SvStream;
31 namespace basegfx { class B2DPolyPolygon; }
33 namespace emfplushelper
35 // EMF+ commands
36 #define EmfPlusRecordTypeHeader 0x4001
37 #define EmfPlusRecordTypeEndOfFile 0x4002
38 #define EmfPlusRecordTypeComment 0x4003
39 #define EmfPlusRecordTypeGetDC 0x4004
40 //TODO EmfPlusRecordTypeMultiFormatStart 0x4005
41 //TODO EmfPlusRecordTypeMultiFormatSection 0x4006
42 //TODO EmfPlusRecordTypeMultiFormatEnd 0x4007
43 #define EmfPlusRecordTypeObject 0x4008
44 //TODO EmfPlusRecordTypeClear 0x4009
45 #define EmfPlusRecordTypeFillRects 0x400A
46 #define EmfPlusRecordTypeDrawRects 0x400B
47 #define EmfPlusRecordTypeFillPolygon 0x400C
48 #define EmfPlusRecordTypeDrawLines 0x400D
49 #define EmfPlusRecordTypeFillEllipse 0x400E
50 #define EmfPlusRecordTypeDrawEllipse 0x400F
51 #define EmfPlusRecordTypeFillPie 0x4010
52 #define EmfPlusRecordTypeDrawPie 0x4011
53 #define EmfPlusRecordTypeDrawArc 0x4012
54 #define EmfPlusRecordTypeFillRegion 0x4013
55 #define EmfPlusRecordTypeFillPath 0x4014
56 #define EmfPlusRecordTypeDrawPath 0x4015
57 #define EmfPlusRecordTypeFillClosedCurve 0x4016
58 #define EmfPlusRecordTypeDrawClosedCurve 0x4017
59 //TODO EmfPlusRecordTypeDrawCurve 0x4018
60 #define EmfPlusRecordTypeDrawBeziers 0x4019
61 #define EmfPlusRecordTypeDrawImage 0x401A
62 #define EmfPlusRecordTypeDrawImagePoints 0x401B
63 #define EmfPlusRecordTypeDrawString 0x401C
64 #define EmfPlusRecordTypeSetRenderingOrigin 0x401D
65 #define EmfPlusRecordTypeSetAntiAliasMode 0x401E
66 #define EmfPlusRecordTypeSetTextRenderingHint 0x401F
67 #define EmfPlusRecordTypeSetTextContrast 0x4020
68 #define EmfPlusRecordTypeSetInterpolationMode 0x4021
69 #define EmfPlusRecordTypeSetPixelOffsetMode 0x4022
70 //TODO EmfPlusRecordTypeSetCompositingMode 0x4023
71 #define EmfPlusRecordTypeSetCompositingQuality 0x4024
72 #define EmfPlusRecordTypeSave 0x4025
73 #define EmfPlusRecordTypeRestore 0x4026
74 #define EmfPlusRecordTypeBeginContainer 0x4027
75 #define EmfPlusRecordTypeBeginContainerNoParams 0x4028
76 #define EmfPlusRecordTypeEndContainer 0x4029
77 #define EmfPlusRecordTypeSetWorldTransform 0x402A
78 #define EmfPlusRecordTypeResetWorldTransform 0x402B
79 #define EmfPlusRecordTypeMultiplyWorldTransform 0x402C
80 #define EmfPlusRecordTypeTranslateWorldTransform 0x402D
81 #define EmfPlusRecordTypeScaleWorldTransform 0x402E
82 #define EmfPlusRecordTypeRotateWorldTransform 0x402F
83 #define EmfPlusRecordTypeSetPageTransform 0x4030
84 #define EmfPlusRecordTypeResetClip 0x4031
85 #define EmfPlusRecordTypeSetClipRect 0x4032
86 #define EmfPlusRecordTypeSetClipPath 0x4033
87 #define EmfPlusRecordTypeSetClipRegion 0x4034
88 #define EmfPlusRecordTypeOffsetClip 0x4035
89 #define EmfPlusRecordTypeDrawDriverString 0x4036
90 //TODO EmfPlusRecordTypeStrokeFillPath 0x4037
91 //TODO EmfPlusRecordTypeSerializableObject 0x4038
92 //TODO EmfPlusRecordTypeSetTSGraphics 0x4039
93 //TODO EmfPlusRecordTypeSetTSClip 0x403A
95 // EMF+object types
96 #define EmfPlusObjectTypeBrush 0x100
97 #define EmfPlusObjectTypePen 0x200
98 #define EmfPlusObjectTypePath 0x300
99 #define EmfPlusObjectTypeRegion 0x400
100 #define EmfPlusObjectTypeImage 0x500
101 #define EmfPlusObjectTypeFont 0x600
102 #define EmfPlusObjectTypeStringFormat 0x700
103 #define EmfPlusObjectTypeImageAttributes 0x800
104 #define EmfPlusObjectTypeCustomLineCap 0x900
106 enum PixelOffsetMode
108 PixelOffsetModeDefault = 0x00,
109 PixelOffsetModeHighSpeed = 0x01,
110 PixelOffsetModeHighQuality = 0x02,
111 PixelOffsetModeNone = 0x03,
112 PixelOffsetModeHalf = 0x04
115 enum SmoothingMode
117 SmoothingModeDefault = 0x00,
118 SmoothingModeHighSpeed = 0x01,
119 SmoothingModeHighQuality = 0x02,
120 SmoothingModeNone = 0x03,
121 SmoothingModeAntiAlias8x4 = 0x04,
122 SmoothingModeAntiAlias8x8 = 0x05
125 enum InterpolationMode
127 InterpolationModeDefault = 0x00,
128 InterpolationModeLowQuality = 0x01,
129 InterpolationModeHighQuality = 0x02,
130 InterpolationModeBilinear = 0x03,
131 InterpolationModeBicubic = 0x04,
132 InterpolationModeNearestNeighbor = 0x05,
133 InterpolationModeHighQualityBilinear = 0x06,
134 InterpolationModeHighQualityBicubic = 0x07
137 enum TextRenderingHint
139 TextRenderingHintSystemDefault = 0x00,
140 TextRenderingHintSingleBitPerPixelGridFit = 0x01,
141 TextRenderingHintSingleBitPerPixel = 0x02,
142 TextRenderingHintAntialiasGridFit = 0x03,
143 TextRenderingHintAntialias = 0x04,
144 TextRenderingHintClearTypeGridFit = 0x05
147 enum UnitType
149 UnitTypeWorld = 0x00,
150 UnitTypeDisplay = 0x01,
151 UnitTypePixel = 0x02,
152 UnitTypePoint = 0x03,
153 UnitTypeInch = 0x04,
154 UnitTypeDocument = 0x05,
155 UnitTypeMillimeter = 0x06
158 enum EmfPlusCombineMode
160 EmfPlusCombineModeReplace = 0x00000000,
161 EmfPlusCombineModeIntersect = 0x00000001,
162 EmfPlusCombineModeUnion = 0x00000002,
163 EmfPlusCombineModeXOR = 0x00000003,
164 EmfPlusCombineModeExclude = 0x00000004,
165 EmfPlusCombineModeComplement = 0x00000005
168 const char* emfTypeToName(sal_uInt16 type);
169 OUString UnitTypeToString(sal_uInt16 nType);
171 struct EMFPObject
173 virtual ~EMFPObject();
176 typedef std::map<int, wmfemfhelper::PropertyHolder> GraphicStateMap;
178 struct EmfPlusHelperData
180 private:
181 /* EMF+ */
182 basegfx::B2DHomMatrix maBaseTransform;
183 basegfx::B2DHomMatrix maWorldTransform;
184 basegfx::B2DHomMatrix maMapTransform;
186 std::unique_ptr<EMFPObject> maEMFPObjects[256];
187 float mfPageScale;
188 sal_Int32 mnOriginX;
189 sal_Int32 mnOriginY;
190 sal_uInt32 mnHDPI;
191 sal_uInt32 mnVDPI;
192 bool mbSetTextContrast;
193 sal_uInt16 mnTextContrast;
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;
205 /* multipart object data */
206 bool mbMultipart;
207 sal_uInt16 mMFlags;
208 SvMemoryStream mMStream;
210 /* emf+ graphic state stack */
211 GraphicStateMap mGSStack;
212 GraphicStateMap mGSContainerStack;
214 /* Performance optimizators */
215 /* Extracted Scale values from Transformation Matrix */
216 double mdExtractedXScale;
217 double mdExtractedYScale;
219 /// data holders
220 wmfemfhelper::TargetHolders& mrTargetHolders;
221 wmfemfhelper::PropertyHolders& mrPropertyHolders;
222 wmfemfhelper::PropertyHolder aGetDCState;
223 bool bIsGetDCProcessing;
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);
229 // internal mapper
230 void mappingChanged();
232 // stack actions
233 void GraphicStatePush(GraphicStateMap& map, sal_Int32 index);
234 void GraphicStatePop(GraphicStateMap& map, sal_Int32 index);
236 drawinglayer::attribute::LineStartEndAttribute CreateLineEnd(const sal_Int32 aCap,
237 const float aPenWidth) const;
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);
244 // helper functions
245 Color EMFPGetBrushColorOrARGBColor(const sal_uInt16 flags, const sal_uInt32 brushIndexOrColor) const;
247 public:
248 EmfPlusHelperData(
249 SvMemoryStream& rMS,
250 wmfemfhelper::TargetHolders& rTargetHolders,
251 wmfemfhelper::PropertyHolders& rPropertyHolders);
252 ~EmfPlusHelperData();
254 void processEmfPlusData(
255 SvMemoryStream& rMS,
256 const drawinglayer::geometry::ViewInformation2D& rViewInformation);
258 // mappers
259 ::basegfx::B2DPoint Map(double ix, double iy) const;
261 // readers
262 static void ReadRectangle(SvStream& s, float& x, float& y, float &width, float& height, bool bCompressed = false);
263 static bool readXForm(SvStream& rIn, basegfx::B2DHomMatrix& rTarget);
264 static ::basegfx::B2DPolyPolygon combineClip(::basegfx::B2DPolyPolygon const & leftPolygon, int combineMode, ::basegfx::B2DPolyPolygon const & rightPolygon);
266 static float getUnitToPixelMultiplier(const UnitType aUnitType, const sal_uInt32 aDPI);
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */