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 
21 #ifndef DRAWSTYLE_H
22 #define DRAWSTYLE_H
23 
24 #include "generated/simpleParser.h"
25 
26 class IMsoArray
27 {
28 public:
29     quint16 nElems;
30     quint16 nElemsAlloc;
31     quint16 cbElem;
32     QByteArray data;
IMsoArray()33     IMsoArray () :nElems(0), nElemsAlloc(0), cbElem(0) {}
34 };
35 
36 class DrawStyle
37 {
38 private:
39     const MSO::OfficeArtDggContainer* d;
40     const MSO::OfficeArtSpContainer* mastersp;
41     const MSO::OfficeArtSpContainer* sp;
42 public:
43     explicit DrawStyle(const MSO::OfficeArtDggContainer* d_ = 0,
44                        const MSO::OfficeArtSpContainer* mastersp_ = 0,
45                        const MSO::OfficeArtSpContainer* sp_ = 0)
d(d_)46             : d(d_), mastersp(mastersp_), sp(sp_) {}
47 
48     /**
49      * @return the OfficeArtSpContainer record specifying the shape container.
50      */
shapeContainer()51     const MSO::OfficeArtSpContainer* shapeContainer() const { return sp; };
52 
53     /**
54      * @return the shape type that MUST be an MSOSPT enumeration value.
55      */
56     quint16 shapeType() const;
57 
58     // Shape property set
59     quint32 hspMaster() const;
60     quint32 cxstyle() const;
61     quint32 bWMode() const;
62     // Shape Boolean Properties
63     bool fBackground() const;
64     bool fInitiator() const;
65     bool fLockShapeType() const;
66     bool fPreferRelativeResize() const;
67     bool fOleIcon() const;
68     bool fFlipVOverride() const;
69     bool fFlipHOverride() const;
70     bool fPolicyBarcode() const;
71     bool fPolicyLabel() const;
72 
73     // Group Shape property set
74     quint32 pWrapPolygonVertices() const;
75     IMsoArray pWrapPolygonVertices_complex() const;
76     qint32 dxWrapDistLeft() const;
77     qint32 dyWrapDistTop() const;
78     qint32 dxWrapDistRight() const;
79     qint32 dyWrapDistBottom() const;
80     quint32 lidRegroup() const;
81     quint32 posH() const;
82     quint32 posRelH() const;
83     quint32 posV() const;
84     quint32 posRelV() const;
85     quint32 pctHR() const;
86     quint32 alignHR() const;
87     qint32 dxHeightHR() const;
88     qint32 dxWidthHR() const;
89     MSO::OfficeArtCOLORREF borderTopColor() const;
90     MSO::OfficeArtCOLORREF borderLeftColor() const;
91     MSO::OfficeArtCOLORREF borderBottomColor() const;
92     MSO::OfficeArtCOLORREF borderRightColor() const;
93     // Group Shape Boolean Properties
94     bool fPrint() const;
95     bool fHidden() const;
96     bool fOneD() const;
97     bool fIsButton() const;
98     bool fOnDblClickNotify() const;
99     bool fBehindDocument() const;
100     bool fEditedWrap() const;
101     bool fScriptAnchor() const;
102     bool fReallyHidden() const;
103     bool fAllowOverlap() const;
104     bool fUserDrawn() const;
105     bool fHorizRule() const;
106     bool fNoshadeHR() const;
107     bool fStandardHR() const;
108     bool fIsBullet() const;
109     bool fLayoutInCell() const;
110     bool fUsefPrint() const;
111     bool fUsefHidden() const;
112     bool fUsefOneD() const;
113     bool fUsefIsButton() const;
114     bool fUsefOnDblClickNotify() const;
115     bool fUsefBehindDocument() const;
116     bool fUsefEditedWrap() const;
117     bool fUsefScriptAnchor() const;
118     bool fUsefReallyHidden() const;
119     bool fUsefAllowOverlap() const;
120     bool fUsefUserDrawn() const;
121     bool fUsefHorizRule() const;
122     bool fUsefNoshadeHR() const;
123     bool fUsefStandardHR() const;
124     bool fUsefIsBullet() const;
125     bool fUsefLayoutInCell() const;
126 
127     // Geometry property set
128     qint32 geoLeft() const;
129     qint32 geoTop() const;
130     qint32 geoRight() const;
131     qint32 geoBottom() const;
132     quint32 shapePath() const;
133     IMsoArray pVertices_complex() const;
134     IMsoArray pSegmentInfo_complex() const;
135     qint32 adjustvalue() const;
136     qint32 adjust2value() const;
137     qint32 adjust3value() const;
138     qint32 adjust4value() const;
139     qint32 adjust5value() const;
140     qint32 adjust6value() const;
141     qint32 adjust7value() const;
142     qint32 adjust8value() const;
143     // Geometry Boolean Properties
144     bool fFillOk() const;
145     bool fFillShadeShapeOK() const;
146     bool fGtextOK() const;
147     bool fLineOK() const;
148     bool f3DOK() const;
149     bool fShadowOK() const;
150 
151     // Fill Style property set
152     quint32 fillType() const;
153     MSO::OfficeArtCOLORREF fillColor() const;
154     MSO::FixedPoint        fillOpacity() const;
155     MSO::OfficeArtCOLORREF fillBackColor() const;
156     MSO::FixedPoint        fillBackOpacity() const;
157     MSO::OfficeArtCOLORREF fillCrMod() const;
158     quint32 fillBlip() const;
159     quint32 fillBlipName() const;
160     QString fillBlipName_complex() const;
161     quint32 fillBlipFlags() const;
162     qint32 fillWidth() const;
163     qint32 fillHeight() const;
164     qint32 fillFocus() const;
165     MSO::FixedPoint fillAngle() const;
166     MSO::FixedPoint fillToLeft() const;
167     MSO::FixedPoint fillToTop() const;
168     MSO::FixedPoint fillToRight() const;
169     MSO::FixedPoint fillToBottom() const;
170     qint32 fillRectLeft() const;
171     qint32 fillRectTop() const;
172     qint32 fillRectRight() const;
173     qint32 fillRectBottom() const;
174     qint32 fillDztype() const;
175     qint32 fillShadePreset() const;
176     quint32 fillShadeColors() const;
177     IMsoArray fillShadeColors_complex() const;
178     MSO::FixedPoint fillOriginX() const;
179     MSO::FixedPoint fillOriginY() const;
180     MSO::FixedPoint fillShapeOriginX() const;
181     MSO::FixedPoint fillShapeOriginY() const;
182     /*     MSO::MSOSHADETYPE fillShadeType() const; */
183     MSO::OfficeArtCOLORREF fillColorExt() const;
184     MSO::OfficeArtCOLORREF fillBackColorExt() const;
185     // Fill Style Boolean Properties
186     bool fNoFillHitTest() const;
187     bool fillUseRect() const;
188     bool fillShape() const;
189     bool fHitTestFill() const;
190     bool fFilled() const;
191     bool fUseShapeAnchor() const;
192     bool fRecolorFillAsPicture() const;
193 
194     // Line Style property set
195     MSO::OfficeArtCOLORREF lineColor() const;
196     qint32 lineOpacity() const;
197     quint32 lineWidth() const;
198     quint32 lineDashing() const;
199     quint32 lineStartArrowhead() const;
200     quint32 lineEndArrowhead() const;
201     quint32 lineStartArrowWidth() const;
202     quint32 lineEndArrowWidth() const;
203     quint32 lineEndArrowLength() const;
204     quint32 lineJoinStyle() const;
205     quint32 lineEndCapStyle() const;
206     // Line Style Boolean Properties
207     bool fNoLineDrawDash() const;
208     bool fLineFillShape() const;
209     bool fHitTestLine() const;
210     bool fLine() const;
211     bool fArrowHeadsOK() const;
212     bool fInsetPenOK() const;
213     bool fInsetPen() const;
214     bool fLineOpaqueBackColor() const;
215 
216     // Shadow Style property set
217     quint32 shadowType() const;
218     MSO::OfficeArtCOLORREF shadowColor() const;
219     MSO::FixedPoint shadowOpacity() const;
220     qint32 shadowOffsetX() const;
221     qint32 shadowOffsetY() const;
222     // Shadow Style Boolean Properties
223     bool fShadowObscured() const;
224     bool fShadow() const;
225 
226     // Diagram property set
227     // Diagram Boolean Properties
228     bool fPseudoInline() const;
229     bool fDoLayout() const;
230     bool fReverse() const;
231     bool fDoFormat() const;
232 
233     // Transformation property set
234     MSO::FixedPoint rotation() const;
235 
236     // Text property set
237     qint32 iTxid() const;
238     qint32 dxTextLeft() const;
239     qint32 dyTextTop() const;
240     qint32 dxTextRight() const;
241     qint32 dyTextBottom() const;
242     quint32 wrapText() const;
243     quint32 anchorText() const;
244     quint32 txflTextFlow() const;
245     quint32 cdirFont() const;
246     quint32 hspNext() const;
247     quint32 txdir() const;
248     // Text Boolean Properties
249     bool fFitShapeToText() const;
250     bool fAutoTextMargin() const;
251     bool fSelectText() const;
252 
253     // Blip property set
254     MSO::FixedPoint cropFromTop() const;
255     MSO::FixedPoint cropFromBottom() const;
256     MSO::FixedPoint cropFromLeft() const;
257     MSO::FixedPoint cropFromRight() const;
258     quint32 pib() const;
259     quint32 pibName() const;
260     QString pibName_complex() const;
261     quint32 pibFlags() const;
262     MSO::OfficeArtCOLORREF pictureTransparent() const;
263     qint32 pictureContrast() const;
264     qint32 pictureBrightness() const;
265     // Blip Boolean Properties
266     bool fPictureActive() const;
267     bool fPictureBiLevel() const;
268     bool fPictureGray() const;
269     bool fNoHitTestPicture() const;
270     bool fLooping() const;
271     bool fRewind() const;
272     bool fPicturePreserveGrays() const;
273 };
274 
275 /**
276  * Retrieve an option from an options containing class B
277  *
278  * @p b must have a member fopt that is an array of type OfficeArtFOPTEChoice.
279  * A is the type of the required option. The option containers in PPT/DOC have
280  * only one instance of each option in an option container.
281  * @param b class that contains options.
282  * @return pointer to the option of type A or 0 if there is none.
283  */
284 template <typename A, typename B>
285 const A*
get(const B & b)286 get(const B& b)
287 {
288     foreach(const MSO::OfficeArtFOPTEChoice& a, b.fopt) {
289         const A *ptr = a.anon.get<A>();
290         if (ptr) return ptr;
291     }
292     return 0;
293 }
294 /**
295  * Retrieve an option from an OfficeArtSpContainer
296  *
297  * Look in all option containers in @p o for an option of type A.
298  * @param o OfficeArtSpContainer instance which contains options.
299  * @return pointer to the option of type A or 0 if there is none.
300  */
301 template <typename A>
302 const A*
get(const MSO::OfficeArtSpContainer & o)303 get(const MSO::OfficeArtSpContainer& o)
304 {
305     const A* a = 0;
306     if (o.shapePrimaryOptions) a = get<A>(*o.shapePrimaryOptions);
307     if (!a && o.shapeSecondaryOptions1) a = get<A>(*o.shapeSecondaryOptions1);
308     if (!a && o.shapeSecondaryOptions2) a = get<A>(*o.shapeSecondaryOptions2);
309     if (!a && o.shapeTertiaryOptions1) a = get<A>(*o.shapeTertiaryOptions1);
310     if (!a && o.shapeTertiaryOptions2) a = get<A>(*o.shapeTertiaryOptions2);
311     return a;
312 }
313 /**
314  * Retrieve an option from an OfficeArtDggContainer
315  *
316  * Look in all option containers in @p o for an option of type A.
317  * @param o OfficeArtDggContainer instance which contains options.
318  * @return pointer to the option of type A or 0 if there is none.
319  */
320 template <typename A>
321 const A*
get(const MSO::OfficeArtDggContainer & o)322 get(const MSO::OfficeArtDggContainer& o)
323 {
324     const A* a = 0;
325     if (o.drawingPrimaryOptions) {
326         a = get<A>(*o.drawingPrimaryOptions);
327     }
328     if (!a && o.drawingTertiaryOptions) a = get<A>(*o.drawingTertiaryOptions);
329     return a;
330 }
331 /**
332  * Retrieve an option from a container
333  *
334  * Look in all option containers in @p o for an option of type A.
335  * @param o OfficeArtDggContainer instance which contains options.
336  * @return pointer to the option of type A or 0 if there is none.
337  */
338 template <typename A, typename T>
339 const A*
get(const T * o)340 get(const T* o)
341 {
342     return (o) ?get<A>(*o) :0;
343 }
344 /**
345  * Retrieve the complex data from an options containing class B
346  *
347  * @p b must have a member fopt that is an array of type OfficeArtFOPTEChoice.
348  * A is the type of the required option.  The option containers in PPT/DOC have
349  * only one instance of each option in an option container.
350  *
351  * @param b class that contains options.
352  * @return IMsoArray storing complex data
353  */
354 template <typename A, typename B>
355 IMsoArray
getComplexData(const B & b)356 getComplexData(const B& b)
357 {
358     MSO::OfficeArtFOPTE* p = nullptr;
359     IMsoArray a;
360     const char* pData = b.complexData.data();
361     uint offset = 0;
362 
363     foreach(const MSO::OfficeArtFOPTEChoice& _c, b.fopt) {
364         p = (MSO::OfficeArtFOPTE*) _c.anon.data();
365         if (p->opid.fComplex) {
366 
367             // there is wrong offset inside PVertices
368             if (_c.anon.is<MSO::PVertices>()) {
369                 if (_c.anon.get<A>()) {
370                     if (b.complexData.size() - offset >= 6) {
371                         a.nElems = *(quint16 *)(pData + offset);
372                         a.nElemsAlloc = *(quint16 *)(pData + offset +2);
373                         a.cbElem = *(quint16 *)(pData + offset + 4);
374                         a.data = b.complexData.mid(offset+6, p->op);
375                         break;
376                     }
377                 } else {
378                     offset += p->op +6;
379                 }
380             } else {
381                 if (_c.anon.get<A>()) {
382                     if (b.complexData.size() - offset >= 6) {
383                         a.nElems = *(quint16 *)(pData + offset);
384                         a.nElemsAlloc = *(quint16 *)(pData + offset +2);
385                         a.cbElem = *(quint16 *)(pData + offset + 4);
386                         a.data = b.complexData.mid(offset+6, p->op-6);
387                         break;
388                     }
389                 } else {
390                     offset += p->op;
391                 }
392             }
393         }
394     }
395     return a;
396 }
397 
398 /**
399  * Retrieve the complex data, which represent an IMsoArray for an option from
400  * an OfficeArtSpContainer.
401  *
402  * Look in all option containers in @p o for an option of type A.
403  *
404  * @param o OfficeArtSpContainer instance which contains options
405  * @return IMsoArray storing complex data
406  */
407 template <typename A>
408 IMsoArray
getComplexData(const MSO::OfficeArtSpContainer & o)409 getComplexData(const MSO::OfficeArtSpContainer& o)
410 {
411     IMsoArray a;
412     if (o.shapePrimaryOptions) a = getComplexData<A>(*o.shapePrimaryOptions);
413     if (!a.data.size() && o.shapeSecondaryOptions1) a = getComplexData<A>(*o.shapeSecondaryOptions1);
414     if (!a.data.size() && o.shapeSecondaryOptions2) a = getComplexData<A>(*o.shapeSecondaryOptions2);
415     if (!a.data.size() && o.shapeTertiaryOptions1) a = getComplexData<A>(*o.shapeTertiaryOptions1);
416     if (!a.data.size() && o.shapeTertiaryOptions2) a = getComplexData<A>(*o.shapeTertiaryOptions2);
417     return a;
418 }
419 
420 /**
421  * Retrieve the complex data, which represent a null-terminated unicode string
422  * from an options containing class B.
423  *
424  * @p b must have a member fopt that is an array of type OfficeArtFOPTEChoice.
425  * A is the type of the required option.  The option containers in PPT/DOC have
426  * only one instance of each option in an option container.
427  *
428  * @param b class that contains options.
429  * @return QString storing complex data
430  */
431 template <typename A, typename B>
432 QString
getComplexName(const B & b)433 getComplexName(const B& b)
434 {
435     MSO::OfficeArtFOPTE* p = nullptr;
436     uint offset = 0;
437     QString a;
438 
439     foreach(const MSO::OfficeArtFOPTEChoice& _c, b.fopt) {
440         p = (MSO::OfficeArtFOPTE*) _c.anon.data();
441         if (p->opid.fComplex) {
442             if (_c.anon.get<A>()) {
443                 a.append(b.complexData.mid(offset, p->op));
444                 break;
445             } else {
446                 offset += p->op;
447             }
448         }
449     }
450     return a;
451 }
452 
453 /**
454  * Retrieve the complex data, which represent a null-terminated unicode string
455  * for an option from an OfficeArtSpContainer.
456  *
457  * Look in all option containers in @p o for an option of type A.
458  *
459  * @param o OfficeArtSpContainer instance which contains options
460  * @return QString storing complex data
461  */
462 template <typename A>
463 QString
getComplexName(const MSO::OfficeArtSpContainer & o)464 getComplexName(const MSO::OfficeArtSpContainer& o)
465 {
466     QString a;
467     if (o.shapePrimaryOptions) a = getComplexName<A>(*o.shapePrimaryOptions);
468     if (!a.isEmpty() && o.shapeSecondaryOptions1) a = getComplexName<A>(*o.shapeSecondaryOptions1);
469     if (!a.isEmpty() && o.shapeSecondaryOptions2) a = getComplexName<A>(*o.shapeSecondaryOptions2);
470     if (!a.isEmpty() && o.shapeTertiaryOptions1) a = getComplexName<A>(*o.shapeTertiaryOptions1);
471     if (!a.isEmpty() && o.shapeTertiaryOptions2) a = getComplexName<A>(*o.shapeTertiaryOptions2);
472     return a;
473 }
474 
475 #endif
476