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 .
22 #include <wmfemfhelper.hxx>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <tools/stream.hxx>
25 #include <basegfx/point/b2dpoint.hxx>
30 namespace basegfx
{ class B2DPolyPolygon
; }
32 namespace emfplushelper
35 #define EmfPlusRecordTypeHeader 0x4001
36 #define EmfPlusRecordTypeEndOfFile 0x4002
37 #define EmfPlusRecordTypeComment 0x4003
38 #define EmfPlusRecordTypeGetDC 0x4004
39 //TODO EmfPlusRecordTypeMultiFormatStart 0x4005
40 //TODO EmfPlusRecordTypeMultiFormatSection 0x4006
41 //TODO EmfPlusRecordTypeMultiFormatEnd 0x4007
42 #define EmfPlusRecordTypeObject 0x4008
43 //TODO EmfPlusRecordTypeClear 0x4009
44 #define EmfPlusRecordTypeFillRects 0x400A
45 #define EmfPlusRecordTypeDrawRects 0x400B
46 #define EmfPlusRecordTypeFillPolygon 0x400C
47 #define EmfPlusRecordTypeDrawLines 0x400D
48 #define EmfPlusRecordTypeFillEllipse 0x400E
49 #define EmfPlusRecordTypeDrawEllipse 0x400F
50 #define EmfPlusRecordTypeFillPie 0x4010
51 #define EmfPlusRecordTypeDrawPie 0x4011
52 #define EmfPlusRecordTypeDrawArc 0x4012
53 #define EmfPlusRecordTypeFillRegion 0x4013
54 #define EmfPlusRecordTypeFillPath 0x4014
55 #define EmfPlusRecordTypeDrawPath 0x4015
56 //TODO EmfPlusRecordTypeFillClosedCurve 0x4016
57 //TODO EmfPlusRecordTypeDrawClosedCurve 0x4017
58 //TODO EmfPlusRecordTypeDrawCurve 0x4018
59 #define EmfPlusRecordTypeDrawBeziers 0x4019
60 #define EmfPlusRecordTypeDrawImage 0x401A
61 #define EmfPlusRecordTypeDrawImagePoints 0x401B
62 #define EmfPlusRecordTypeDrawString 0x401C
63 #define EmfPlusRecordTypeSetRenderingOrigin 0x401D
64 #define EmfPlusRecordTypeSetAntiAliasMode 0x401E
65 #define EmfPlusRecordTypeSetTextRenderingHint 0x401F
66 #define EmfPlusRecordTypeSetTextContrast 0x4020
67 #define EmfPlusRecordTypeSetInterpolationMode 0x4021
68 #define EmfPlusRecordTypeSetPixelOffsetMode 0x4022
69 //TODO EmfPlusRecordTypeSetCompositingMode 0x4023
70 #define EmfPlusRecordTypeSetCompositingQuality 0x4024
71 #define EmfPlusRecordTypeSave 0x4025
72 #define EmfPlusRecordTypeRestore 0x4026
73 #define EmfPlusRecordTypeBeginContainer 0x4027
74 #define EmfPlusRecordTypeBeginContainerNoParams 0x4028
75 #define EmfPlusRecordTypeEndContainer 0x4029
76 #define EmfPlusRecordTypeSetWorldTransform 0x402A
77 #define EmfPlusRecordTypeResetWorldTransform 0x402B
78 #define EmfPlusRecordTypeMultiplyWorldTransform 0x402C
79 #define EmfPlusRecordTypeTranslateWorldTransform 0x402D
80 #define EmfPlusRecordTypeScaleWorldTransform 0x402E
81 #define EmfPlusRecordTypeRotateWorldTransform 0x402F
82 #define EmfPlusRecordTypeSetPageTransform 0x4030
83 #define EmfPlusRecordTypeResetClip 0x4031
84 #define EmfPlusRecordTypeSetClipRect 0x4032
85 #define EmfPlusRecordTypeSetClipPath 0x4033
86 #define EmfPlusRecordTypeSetClipRegion 0x4034
87 #define EmfPlusRecordTypeOffsetClip 0x4035
88 #define EmfPlusRecordTypeDrawDriverString 0x4036
89 //TODO EmfPlusRecordTypeStrokeFillPath 0x4037
90 //TODO EmfPlusRecordTypeSerializableObject 0x4038
91 //TODO EmfPlusRecordTypeSetTSGraphics 0x4039
92 //TODO EmfPlusRecordTypeSetTSClip 0x403A
95 #define EmfPlusObjectTypeBrush 0x100
96 #define EmfPlusObjectTypePen 0x200
97 #define EmfPlusObjectTypePath 0x300
98 #define EmfPlusObjectTypeRegion 0x400
99 #define EmfPlusObjectTypeImage 0x500
100 #define EmfPlusObjectTypeFont 0x600
101 #define EmfPlusObjectTypeStringFormat 0x700
102 #define EmfPlusObjectTypeImageAttributes 0x800
103 #define EmfPlusObjectTypeCustomLineCap 0x900
107 PixelOffsetModeDefault
= 0x00,
108 PixelOffsetModeHighSpeed
= 0x01,
109 PixelOffsetModeHighQuality
= 0x02,
110 PixelOffsetModeNone
= 0x03,
111 PixelOffsetModeHalf
= 0x04
116 SmoothingModeDefault
= 0x00,
117 SmoothingModeHighSpeed
= 0x01,
118 SmoothingModeHighQuality
= 0x02,
119 SmoothingModeNone
= 0x03,
120 SmoothingModeAntiAlias8x4
= 0x04,
121 SmoothingModeAntiAlias8x8
= 0x05
124 enum InterpolationMode
126 InterpolationModeDefault
= 0x00,
127 InterpolationModeLowQuality
= 0x01,
128 InterpolationModeHighQuality
= 0x02,
129 InterpolationModeBilinear
= 0x03,
130 InterpolationModeBicubic
= 0x04,
131 InterpolationModeNearestNeighbor
= 0x05,
132 InterpolationModeHighQualityBilinear
= 0x06,
133 InterpolationModeHighQualityBicubic
= 0x07
136 enum TextRenderingHint
138 TextRenderingHintSystemDefault
= 0x00,
139 TextRenderingHintSingleBitPerPixelGridFit
= 0x01,
140 TextRenderingHintSingleBitPerPixel
= 0x02,
141 TextRenderingHintAntialiasGridFit
= 0x03,
142 TextRenderingHintAntialias
= 0x04,
143 TextRenderingHintClearTypeGridFit
= 0x05
148 UnitTypeWorld
= 0x00,
149 UnitTypeDisplay
= 0x01,
150 UnitTypePixel
= 0x02,
151 UnitTypePoint
= 0x03,
153 UnitTypeDocument
= 0x05,
154 UnitTypeMillimeter
= 0x06
157 enum EmfPlusCombineMode
159 EmfPlusCombineModeReplace
= 0x00000000,
160 EmfPlusCombineModeIntersect
= 0x00000001,
161 EmfPlusCombineModeUnion
= 0x00000002,
162 EmfPlusCombineModeXOR
= 0x00000003,
163 EmfPlusCombineModeExclude
= 0x00000004,
164 EmfPlusCombineModeComplement
= 0x00000005
167 const char* emfTypeToName(sal_uInt16 type
);
168 OUString
UnitTypeToString(sal_uInt16 nType
);
172 virtual ~EMFPObject();
175 typedef std::map
<int, wmfemfhelper::PropertyHolder
> GraphicStateMap
;
177 struct EmfPlusHelperData
181 basegfx::B2DHomMatrix maBaseTransform
;
182 basegfx::B2DHomMatrix maWorldTransform
;
183 basegfx::B2DHomMatrix maMapTransform
;
185 std::unique_ptr
<EMFPObject
> maEMFPObjects
[256];
191 bool mbSetTextContrast
;
192 sal_uInt16 mnTextContrast
;
194 /* EMF+ emf header info */
195 sal_Int32 mnFrameLeft
;
196 sal_Int32 mnFrameTop
;
197 sal_Int32 mnFrameRight
;
198 sal_Int32 mnFrameBottom
;
204 /* multipart object data */
207 SvMemoryStream mMStream
;
209 /* emf+ graphic state stack */
210 GraphicStateMap mGSStack
;
211 GraphicStateMap mGSContainerStack
;
214 wmfemfhelper::TargetHolders
& mrTargetHolders
;
215 wmfemfhelper::PropertyHolders
& mrPropertyHolders
;
216 bool bIsGetDCProcessing
;
219 void processObjectRecord(SvMemoryStream
& rObjectStream
, sal_uInt16 flags
, sal_uInt32 dataSize
, bool bUseWholeStream
= false);
220 static void ReadPoint(SvStream
& s
, float& x
, float& y
, sal_uInt32 flags
);
223 void mappingChanged();
226 void GraphicStatePush(GraphicStateMap
& map
, sal_Int32 index
);
227 void GraphicStatePop (GraphicStateMap
& map
, sal_Int32 index
, wmfemfhelper::PropertyHolder
& rState
);
229 // primitive creators
230 void EMFPPlusDrawPolygon(const ::basegfx::B2DPolyPolygon
& polygon
, sal_uInt32 penIndex
);
231 void EMFPPlusFillPolygon(const ::basegfx::B2DPolyPolygon
& polygon
, const bool isColor
, const sal_uInt32 brushIndexOrColor
);
232 void EMFPPlusFillPolygonSolidColor(const ::basegfx::B2DPolyPolygon
& polygon
, Color
const& color
);
235 Color
EMFPGetBrushColorOrARGBColor(const sal_uInt16 flags
, const sal_uInt32 brushIndexOrColor
) const;
240 wmfemfhelper::TargetHolders
& rTargetHolders
,
241 wmfemfhelper::PropertyHolders
& rPropertyHolders
);
242 ~EmfPlusHelperData();
244 void processEmfPlusData(
246 const drawinglayer::geometry::ViewInformation2D
& rViewInformation
);
249 ::basegfx::B2DPoint
Map(double ix
, double iy
) const;
252 static void ReadRectangle(SvStream
& s
, float& x
, float& y
, float &width
, float& height
, bool bCompressed
= false);
253 static bool readXForm(SvStream
& rIn
, basegfx::B2DHomMatrix
& rTarget
);
254 static ::basegfx::B2DPolyPolygon
combineClip(::basegfx::B2DPolyPolygon
const & leftPolygon
, int combineMode
, ::basegfx::B2DPolyPolygon
const & rightPolygon
);
256 static float getUnitToPixelMultiplier(const UnitType aUnitType
, const sal_uInt32 aDPI
);
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */