1 /* This file is part of the KDE project
2    Copyright (C) 2010 KO GmbH <jos.van.den.oever@kogmbh.com>
3    Copyright (C) 2010, 2011 Matus Uzak <matus.uzak@ixonos.com>
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14 
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19 */
20 #include "drawstyle.h"
21 #include "msodraw.h"
22 
23 namespace
24 {
ignore()25 const MSO::OfficeArtCOLORREF ignore()
26 {
27     MSO::OfficeArtCOLORREF w;
28     w.red = w.green = w.blue = 0xFF;
29     w.fPaletteIndex = w.fPaletteRGB = w.fSystemRGB = w.fSchemeIndex
30                                       = w.fSysIndex = true;
31     return w;
32 }
white()33 const MSO::OfficeArtCOLORREF white()
34 {
35     MSO::OfficeArtCOLORREF w;
36     w.red = w.green = w.blue = 0xFF;
37     w.fPaletteIndex = w.fPaletteRGB = w.fSystemRGB = w.fSchemeIndex
38                                       = w.fSysIndex = false;
39     return w;
40 }
41 // The default value for this property is 0x20000000
crmodDefault()42 const MSO::OfficeArtCOLORREF crmodDefault()
43 {
44     MSO::OfficeArtCOLORREF w;
45     w.red = w.green = w.blue = 0x00;
46     w.fPaletteIndex = w.fPaletteRGB = w.fSchemeIndex = w.fSysIndex = false;
47     w.fSystemRGB = true;
48     return w;
49 }
black()50 const MSO::OfficeArtCOLORREF black()
51 {
52     MSO::OfficeArtCOLORREF b;
53     b.red = b.green = b.blue = 0;
54     b.fPaletteIndex = b.fPaletteRGB = b.fSystemRGB = b.fSchemeIndex
55                                       = b.fSysIndex = false;
56     return b;
57 }
gray()58 const MSO::OfficeArtCOLORREF gray()
59 {
60     MSO::OfficeArtCOLORREF b;
61     b.red = b.green = b.blue = 0x80;
62     b.fPaletteIndex = b.fPaletteRGB = b.fSystemRGB = b.fSchemeIndex
63                                       = b.fSysIndex = false;
64     return b;
65 }
one()66 const MSO::FixedPoint one()
67 {
68     MSO::FixedPoint one;
69     one.integral = 1;
70     one.fractional = 0;
71     return one;
72 }
zero()73 const MSO::FixedPoint zero()
74 {
75     MSO::FixedPoint zero;
76     zero.integral = 0;
77     zero.fractional = 0;
78     return zero;
79 }
80 //NOTE: msohadeDefault is not defined in MS-ODRAW, just guessing
81 // const MSO::MSOSHADETYPE msoshadeDefault() {
82 //     MSO::MSOSHADETYPE tmp;
83 //     tmp.msoshadeNone = 0;
84 //     tmp.msoshadeGamma = 0;
85 //     tmp.msoshadeSigma = 0;
86 //     tmp.msoshadeBand = 0;
87 //     tmp.msoshadeOneColor = 0;
88 //     return tmp;
89 // }
90 } //namespace
91 
shapeType() const92 quint16 DrawStyle::shapeType() const
93 {
94     if (!sp) {
95         return msosptNil;
96     } else {
97         return sp->shapeProp.rh.recInstance;
98     }
99 }
100 
101 #define GETTER(TYPE, FOPT, NAME, DEFAULT) \
102     TYPE DrawStyle::NAME() const \
103     { \
104         const MSO::FOPT* p = 0; \
105         if (sp) { \
106             p = get<MSO::FOPT>(*sp); \
107         } \
108         if (!p && mastersp) { \
109             p = get<MSO::FOPT>(*mastersp); \
110         } \
111         if (!p && d) { \
112             p = get<MSO::FOPT>(*d); \
113         } \
114         if (p) { \
115             return p->NAME; \
116         } \
117         return DEFAULT; \
118     }
119 
120 //     TYPE                    FOPT                  NAME                  DEFAULT         ODRAW Ref
121 GETTER(quint32,                HspMaster,            hspMaster,            0)              // 2.3.2.1
122 GETTER(quint32,                Cxstyle,              cxstyle,              0x00000003)     // 2.3.2.2
123 GETTER(quint32,                BWMode,               bWMode,               1)              // 2.3.2.3
124 GETTER(quint32,                PWrapPolygonVertices, pWrapPolygonVertices, 0)              // 2.3.4.7
125 GETTER(qint32,                 DxWrapDistLeft,       dxWrapDistLeft,       0x0001be7c)     // 2.3.4.9
126 GETTER(qint32,                 DyWrapDistTop,        dyWrapDistTop,        0)              // 2.3.4.10
127 GETTER(qint32,                 DxWrapDistRight,      dxWrapDistRight,      0x0001be7c)     // 2.3.4.11
128 GETTER(qint32,                 DyWrapDistBottom,     dyWrapDistBottom,     0)              // 2.3.4.12
129 GETTER(quint32,                LidRegroup,           lidRegroup,           0)              // 2.3.4.13
130 GETTER(quint32,                PosH,                 posH,                 0)              // 2.3.4.19
131 GETTER(quint32,                PosRelH,              posRelH,              2)              // 2.3.4.20
132 GETTER(quint32,                PosV,                 posV,                 0)              // 2.3.4.21
133 GETTER(quint32,                PosRelV,              posRelV,              2)              // 2.3.4.22
134 GETTER(quint32,                PctHR,                pctHR,                0x000003e8)     // 2.3.4.23
135 GETTER(quint32,                AlignHR,              alignHR,              0)              // 2.3.4.24
136 GETTER(qint32,                 DxHeightHR,           dxHeightHR,           0)              // 2.3.4.25
137 GETTER(qint32,                 DxWidthHR,            dxWidthHR,            0)              // 2.3.4.26
GETTER(MSO::OfficeArtCOLORREF,BorderTopColor,borderTopColor,white ())138 GETTER(MSO::OfficeArtCOLORREF, BorderTopColor,       borderTopColor,       white())        // 2.3.4.32
139 GETTER(MSO::OfficeArtCOLORREF, BorderLeftColor,      borderLeftColor,      white())        // 2.3.4.33
140 GETTER(MSO::OfficeArtCOLORREF, BorderBottomColor,    borderBottomColor,    white())        // 2.3.4.34
141 GETTER(MSO::OfficeArtCOLORREF, BorderRightColor,     borderRightColor,     white())        // 2.3.4.35
142 GETTER(qint32,                 GeoLeft,              geoLeft,              0)              // 2.3.6.1
143 GETTER(qint32,                 GeoTop,               geoTop,               0)              // 2.3.6.2
144 GETTER(qint32,                 GeoRight,             geoRight,             0x00005460)     // 2.3.6.3
145 GETTER(qint32,                 GeoBottom,            geoBottom,            0x00005460)     // 2.3.6.4
146 GETTER(quint32,                ShapePath,            shapePath,            0x00000001)     // 2.3.6.5
147 GETTER(qint32,                 AdjustValue,          adjustvalue,          0)              // 2.3.6.10
148 GETTER(qint32,                 Adjust2Value,         adjust2value,         0)              // 2.3.6.11
149 GETTER(qint32,                 Adjust3Value,         adjust3value,         0)              // 2.3.6.12
150 GETTER(qint32,                 Adjust4Value,         adjust4value,         0)              // 2.3.6.13
151 GETTER(qint32,                 Adjust5Value,         adjust5value,         0)              // 2.3.6.14
152 GETTER(qint32,                 Adjust6Value,         adjust6value,         0)              // 2.3.6.15
153 GETTER(qint32,                 Adjust7Value,         adjust7value,         0)              // 2.3.6.16
154 GETTER(qint32,                 Adjust8Value,         adjust8value,         0)              // 2.3.6.17
155 GETTER(quint32,                FillType,             fillType,             0)              // 2.3.7.1
156 GETTER(MSO::OfficeArtCOLORREF, FillColor,            fillColor,            white())        // 2.3.7.2
157 GETTER(MSO::FixedPoint,        FillOpacity,          fillOpacity,          one())          // 2.3.7.3
158 GETTER(MSO::OfficeArtCOLORREF, FillBackColor,        fillBackColor,        white())        // 2.3.7.4
159 GETTER(MSO::FixedPoint,        FillBackOpacity,      fillBackOpacity,      one())          // 2.3.7.5
160 GETTER(MSO::OfficeArtCOLORREF, FillCrMod,            fillCrMod,            crmodDefault()) // 2.3.7.6
161 GETTER(quint32,                FillBlip,             fillBlip,             0)              // 2.3.7.7
162 GETTER(quint32,                FillBlipName,         fillBlipName,         0)              // 2.3.7.9
163 GETTER(quint32,                FillBlipFlags,        fillBlipFlags,        0)              // 2.3.7.11
164 GETTER(qint32,                 FillWidth,            fillWidth,            0)              // 2.3.7.12
165 GETTER(qint32,                 FillHeight,           fillHeight,           0)              // 2.3.7.13
166 GETTER(MSO::FixedPoint,        FillAngle,            fillAngle,            zero())         // 2.3.7.14
167 GETTER(qint32,                 FillFocus,            fillFocus,            0)              // 2.3.7.15
168 GETTER(MSO::FixedPoint,        FillToLeft,           fillToLeft,           zero())         // 2.3.7.16
169 GETTER(MSO::FixedPoint,        FillToTop,            fillToTop,            zero())         // 2.3.7.17
170 GETTER(MSO::FixedPoint,        FillToRight,          fillToRight,          zero())         // 2.3.7.18
171 GETTER(MSO::FixedPoint,        FillToBottom,         fillToBottom,         zero())         // 2.3.7.19
172 GETTER(qint32,                 FillRectLeft,         fillRectLeft,         0)              // 2.3.7.20
173 GETTER(qint32,                 FillRectTop,          fillRectTop,          0)              // 2.3.7.21
174 GETTER(qint32,                 FillRectRight,        fillRectRight,        0)              // 2.3.7.22
175 GETTER(qint32,                 FillRectBottom,       fillRectBottom,       0)              // 2.3.7.23
176 GETTER(qint32,                 FillDztype,           fillDztype,           0)              // 2.3.7.24
177 GETTER(qint32,                 FillShadePreset,      fillShadePreset,      0)              // 2.3.7.25
178 GETTER(quint32,                FillShadeColors,      fillShadeColors,      0)              // 2.3.7.26
179 GETTER(MSO::FixedPoint,        FillOriginX,          fillOriginX,          zero())         // 2.3.7.28
180 GETTER(MSO::FixedPoint,        FillOriginY,          fillOriginY,          zero())         // 2.3.7.29
181 GETTER(MSO::FixedPoint,        FillShapeOriginX,     fillShapeOriginX,     zero())         // 2.3.7.30
182 GETTER(MSO::FixedPoint,        FillShapeOriginY,     fillShapeOriginY,     zero())         // 2.3.7.31
183 // GETTER(MSO::MSOSHADETYPE,      FillShadeType,        fillShadeType,        msoshadeDefault()) // 2.3.7.32
184 GETTER(MSO::OfficeArtCOLORREF, FillColorExt,         fillColorExt,         white())        // 2.3.7.33
185 GETTER(MSO::OfficeArtCOLORREF, FillBackColorExt,     fillBackColorExt,     white())        // 2.3.7.37
186 GETTER(MSO::OfficeArtCOLORREF, LineColor,            lineColor,            black())        // 2.3.8.1
187 GETTER(qint32,                 LineOpacity,          lineOpacity,          0x10000)        // 2.3.8.2
188 GETTER(quint32,                LineWidth,            lineWidth,            0x2535)         // 2.3.8.14
189 GETTER(quint32,                LineDashing,          lineDashing,          0)              // 2.3.8.17
190 GETTER(quint32,                LineStartArrowhead,   lineStartArrowhead,   0)              // 2.3.8.20
191 GETTER(quint32,                LineEndArrowhead,     lineEndArrowhead,     0)              // 2.3.8.21
192 GETTER(quint32,                LineStartArrowWidth,  lineStartArrowWidth,  1)              // 2.3.8.22
193 GETTER(quint32,                LineEndArrowWidth,    lineEndArrowWidth,    1)              // 2.3.8.24
194 GETTER(quint32,                LineEndArrowLength,   lineEndArrowLength,   1)              // 2.3.8.25
195 GETTER(quint32,                LineJoinStyle,        lineJoinStyle,        2)              // 2.3.8.26
196 GETTER(quint32,                LineEndCapStyle,      lineEndCapStyle,      2)              // 2.3.8.27
197 GETTER(quint32,                ShadowType,           shadowType,           0)              // 2.3.13.1
198 GETTER(MSO::OfficeArtCOLORREF, ShadowColor,          shadowColor,          gray())         // 2.3.13.2
199 GETTER(MSO::FixedPoint,        ShadowOpacity,        shadowOpacity,        one())          // 2.3.13.5
200 GETTER(qint32,                 ShadowOffsetX,        shadowOffsetX,        0x6338)         // 2.3.13.6
201 GETTER(qint32,                 ShadowOffsetY,        shadowOffsetY,        0x6338)         // 2.3.13.7
202 GETTER(MSO::FixedPoint,        Rotation,             rotation,             zero())         // 2.3.18.5
203 GETTER(qint32,                 ITxid,                iTxid,                0)              // 2.3.21.1
204 GETTER(qint32,                 DxTextLeft,           dxTextLeft,           0x00016530)     // 2.3.21.2
205 GETTER(qint32,                 DyTextTop,            dyTextTop,            0x0000B298)     // 2.3.21.3
206 GETTER(qint32,                 DxTextRight,          dxTextRight,          0x00016530)     // 2.3.21.4
207 GETTER(qint32,                 DyTextBottom,         dyTextBottom,         0x0000B298)     // 2.3.21.5
208 GETTER(quint32,                WrapText,             wrapText,             0)              // 2.3.21.6
209 GETTER(quint32,                AnchorText,           anchorText,           0)              // 2.3.21.8
210 GETTER(quint32,                TxflTextFlow,         txflTextFlow,         0)              // 2.3.21.9
211 GETTER(quint32,                CdirFont,             cdirFont,             0)              // 2.3.21.10
212 GETTER(quint32,                HspNext,              hspNext,              0)              // 2.3.21.11
213 GETTER(quint32,                Txdir,                txdir,                0)              // 2.3.21.12
214 GETTER(MSO::FixedPoint,        CropFromTop,          cropFromTop,          zero())         // 2.3.23.1
215 GETTER(MSO::FixedPoint,        CropFromBottom,       cropFromBottom,       zero())         // 2.3.23.2
216 GETTER(MSO::FixedPoint,        CropFromLeft,         cropFromLeft,         zero())         // 2.3.23.3
217 GETTER(MSO::FixedPoint,        CropFromRight,        cropFromRight,        zero())         // 2.3.23.4
218 GETTER(quint32,                Pib,                  pib,                  0)              // 2.3.23.5
219 GETTER(quint32,                PibName,              pibName,              0)              // 2.3.23.7
220 GETTER(quint32,                PibFlags,             pibFlags,             0)              // 2.3.23.9
221 GETTER(MSO::OfficeArtCOLORREF, PictureTransparent,   pictureTransparent,   ignore())       // 2.3.23.10
222 GETTER(qint32,                 PictureContrast,      pictureContrast,      0x00010000)     // 2.3.23.11
223 GETTER(qint32,                 PictureBrightness,    pictureBrightness,    0)              // 2.3.23.12
224 #undef GETTER
225 
226 #define GETTER(NAME, TEST, DEFAULT) \
227     bool DrawStyle::NAME() const \
228     { \
229         const MSO::FOPT* p = 0; \
230         if (sp) { \
231             p = get<MSO::FOPT>(*sp); \
232             if (p && p->TEST) { \
233                 return p->NAME; \
234             } \
235         } \
236         if (mastersp) { \
237             p = get<MSO::FOPT>(*mastersp); \
238             if (p && p->TEST) { \
239                 return p->NAME; \
240             } \
241         } \
242         if (d) { \
243             p = get<MSO::FOPT>(d); \
244             if (p && p->TEST) { \
245                 return p->NAME; \
246             } \
247         } \
248         return DEFAULT; \
249     }
250 
251 //TODO: CalloutBooleanProperties, ProtectionBooleanProperties
252 
253 // FOPT        NAME           TEST                       DEFAULT
254 #define FOPT ShapeBooleanProperties
255 GETTER(fBackground,           fUsefBackground,           false)
256 GETTER(fInitiator,            fUsefInitiator,            false)
257 GETTER(fLockShapeType,        fUsefLockShapeType,        false)
258 GETTER(fPreferRelativeResize, fusePreferrelativeResize,  false)
259 GETTER(fOleIcon,              fUsefOleIcon,              false)
260 GETTER(fFlipVOverride,        fUsefFlipVOverride,        false)
261 GETTER(fFlipHOverride,        fUsefFlipHOverride,        false)
262 GETTER(fPolicyBarcode,        fUsefPolicyBarcode,        false)
263 GETTER(fPolicyLabel,          fUsefPolicyLabel,          false)
264 #undef FOPT
265 #define FOPT GroupShapeBooleanProperties
266 GETTER(fPrint,                fUsefPrint,                true)
267 GETTER(fHidden,               fUsefHidden,               false)
268 GETTER(fOneD,                 fUsefOneD,                 false)
269 GETTER(fIsButton,             fUsefIsButton,             false)
270 GETTER(fOnDblClickNotify,     fUsefOnDblClickNotify,     false)
271 GETTER(fBehindDocument,       fUsefBehindDocument,       false)
272 GETTER(fEditedWrap,           fUsefEditedWrap,           false)
273 GETTER(fScriptAnchor,         fUsefScriptAnchor,         false)
274 GETTER(fReallyHidden,         fUsefReallyHidden,         false)
275 GETTER(fAllowOverlap,         fUsefAllowOverlap,         true)
276 GETTER(fUserDrawn,            fUsefUserDrawn,            false)
277 GETTER(fHorizRule,            fUsefHorizRule,            false)
278 GETTER(fNoshadeHR,            fUsefNoshadeHR,            false)
279 GETTER(fStandardHR,           fUsefStandardHR,           false)
280 GETTER(fIsBullet,             fUsefIsBullet,             false)
281 GETTER(fLayoutInCell,         fUsefLayoutInCell,         true)
282 #undef FOPT
283 #define FOPT GeometryBooleanProperties
284 GETTER(fFillOk,                fUsefFillOK,              true)
285 GETTER(fFillShadeShapeOK,      fUsefFillShadeShapeOK,    false)
286 GETTER(fGtextOK,               fUsefGtextOK,             false)
287 GETTER(fLineOK,                fUsefLineOK,              true)
288 GETTER(f3DOK,                  fUsef3DOK,                true)
289 GETTER(fShadowOK,              fUsefShadowOK,            true)
290 #undef FOPT
291 #define FOPT FillStyleBooleanProperties
292 GETTER(fNoFillHitTest,        fUseNoFillHitTest,         false)
293 GETTER(fillUseRect,           fUseFillUseRect,           false)
294 GETTER(fillShape,             fUseFillShape,             true)
295 GETTER(fHitTestFill,          fUseHitTestFill,           true)
296 GETTER(fFilled,               fUseFilled,                true)
297 GETTER(fUseShapeAnchor,       fUseUseShapeAnchor,        false)
298 GETTER(fRecolorFillAsPicture, fUsefRecolorFillAsPicture, false)
299 #undef FOPT
300 #define FOPT LineStyleBooleanProperties
301 GETTER(fNoLineDrawDash,       fUseNoLineDrawDash,        false)
302 GETTER(fLineFillShape,        fUseLineFillShape,         false)
303 GETTER(fHitTestLine,          fUseHitTestLine,           true)
304 // GETTER(fLine,                 fUsefLine,                 true)
305 GETTER(fArrowHeadsOK,         fUsefArrowHeadsOK,         false)
306 GETTER(fInsetPenOK,           fUseInsetPenOK,            true)
307 GETTER(fInsetPen,             fUseInsetPen,              false)
308 GETTER(fLineOpaqueBackColor,  fUsefLineOpaqueBackColor,  false)
309 #undef FOPT
310 #define FOPT ShadowStyleBooleanProperties
311 GETTER(fShadowObscured,       fUsefShadowObscured,       false)
312 GETTER(fShadow,               fUsefShadow,               false)
313 #undef FOPT
314 #define FOPT DiagramBooleanProperties
315 GETTER(fPseudoInline,         fUsefPseudoInline,         false)
316 GETTER(fDoLayout,             fUsefDoLayout,             true)
317 GETTER(fReverse,              fUsefReverse,              false)
318 GETTER(fDoFormat,             fUsefDoFormat,             false)
319 #undef FOPT
320 #define FOPT TextBooleanProperties
321 GETTER(fFitShapeToText,       fUsefFitShapeToText,       false)
322 GETTER(fAutoTextMargin,       fUsefAutoTextMargin,       false)
323 GETTER(fSelectText,           fUsefSelectText,           true)
324 #undef FOPT
325 #define FOPT BlipBooleanProperties
326 GETTER(fPictureActive,        fUsefPictureActive,        false)
327 GETTER(fPictureBiLevel,       fUsefPictureBiLevel,       false)
328 GETTER(fPictureGray,          fUsefPictureGray,          false)
329 GETTER(fNoHitTestPicture,     fUsefNoHitTestPicture,     false)
330 GETTER(fLooping,              fUsefLooping,              false)
331 GETTER(fRewind,               fUsefRewind,               false)
332 GETTER(fPicturePreserveGrays, fUsefPicturePreserveGrays, false)
333 #undef FOPT
334 #undef GETTER
335 
336 // The override was discussed at Office File Formats Forum:
337 // http://social.msdn.microsoft.com/Forums/en-US/os_binaryfile/thread/a1cf51a7-fb93-4028-b3ac-3ed2fd77a94b
338 bool DrawStyle::fLine() const
339 {
340     const MSO::LineStyleBooleanProperties* p = 0;
341     quint16 shapeType = msosptNil;
342 
343     if (sp) {
344         shapeType = sp->shapeProp.rh.recInstance;
345         p = get<MSO::LineStyleBooleanProperties>(*sp);
346         if (p && p->fUsefLine) {
347             return p->fLine;
348         }
349     }
350     if (mastersp) {
351         p = get<MSO::LineStyleBooleanProperties>(*mastersp);
352         if (p && p->fUsefLine) {
353             return p->fLine;
354         }
355     }
356     if (shapeType == msosptPictureFrame) {
357         return false;
358     } else {
359         return true;
360     }
361 }
362 
363 #define COMPLEX(FOPT, NAME) \
364     IMsoArray DrawStyle::NAME() const \
365     { \
366         IMsoArray a;\
367         if (sp) { \
368             a = getComplexData<MSO::FOPT>(*sp); \
369             return a;\
370         } \
371         if (mastersp) { \
372             a = getComplexData<MSO::FOPT>(*mastersp); \
373             return a;\
374         } \
375         return a;\
376     }
377 // FOPT                       NAME
378 COMPLEX(FillShadeColors,      fillShadeColors_complex)
379 COMPLEX(PVertices,            pVertices_complex)
380 COMPLEX(PSegmentInfo,         pSegmentInfo_complex)
381 COMPLEX(PWrapPolygonVertices, pWrapPolygonVertices_complex)
382 #undef COMPLEX
383 
384 #define COMPLEX_NAME(FOPT, NAME) \
385     QString DrawStyle::NAME() const \
386     { \
387         QString a;\
388         if (sp) { \
389             a = getComplexName<MSO::FOPT>(*sp); \
390             if (!a.isNull()) return a; \
391         } \
392         if (mastersp) { \
393             a = getComplexName<MSO::FOPT>(*mastersp); \
394             if (!a.isNull()) return a; \
395         } \
396         return a;\
397     }
398 // FOPT                       NAME
399 COMPLEX_NAME(PibName,         pibName_complex)
400 COMPLEX_NAME(FillBlipName,    fillBlipName_complex)
401 #undef COMPLEX_NAME
402