File indexing completed on 2024-12-08 12:55:54

0001 /* This file is part of the KDE project
0002    Copyright (C) 2010 KO GmbH <jos.van.den.oever@kogmbh.com>
0003    Copyright (C) 2010, 2011 Matus Uzak <matus.uzak@ixonos.com>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef DRAWSTYLE_H
0022 #define DRAWSTYLE_H
0023 
0024 #include "generated/simpleParser.h"
0025 
0026 class IMsoArray
0027 {
0028 public:
0029     quint16 nElems;
0030     quint16 nElemsAlloc;
0031     quint16 cbElem;
0032     QByteArray data;
0033     IMsoArray () :nElems(0), nElemsAlloc(0), cbElem(0) {}
0034 };
0035 
0036 class DrawStyle
0037 {
0038 private:
0039     const MSO::OfficeArtDggContainer* d;
0040     const MSO::OfficeArtSpContainer* mastersp;
0041     const MSO::OfficeArtSpContainer* sp;
0042 public:
0043     explicit DrawStyle(const MSO::OfficeArtDggContainer* d_ = 0,
0044                        const MSO::OfficeArtSpContainer* mastersp_ = 0,
0045                        const MSO::OfficeArtSpContainer* sp_ = 0)
0046             : d(d_), mastersp(mastersp_), sp(sp_) {}
0047 
0048     /**
0049      * @return the OfficeArtSpContainer record specifying the shape container.
0050      */
0051     const MSO::OfficeArtSpContainer* shapeContainer() const { return sp; };
0052 
0053     /**
0054      * @return the shape type that MUST be an MSOSPT enumeration value.
0055      */
0056     quint16 shapeType() const;
0057 
0058     // Shape property set
0059     quint32 hspMaster() const;
0060     quint32 cxstyle() const;
0061     quint32 bWMode() const;
0062     // Shape Boolean Properties
0063     bool fBackground() const;
0064     bool fInitiator() const;
0065     bool fLockShapeType() const;
0066     bool fPreferRelativeResize() const;
0067     bool fOleIcon() const;
0068     bool fFlipVOverride() const;
0069     bool fFlipHOverride() const;
0070     bool fPolicyBarcode() const;
0071     bool fPolicyLabel() const;
0072 
0073     // Group Shape property set
0074     quint32 pWrapPolygonVertices() const;
0075     IMsoArray pWrapPolygonVertices_complex() const;
0076     qint32 dxWrapDistLeft() const;
0077     qint32 dyWrapDistTop() const;
0078     qint32 dxWrapDistRight() const;
0079     qint32 dyWrapDistBottom() const;
0080     quint32 lidRegroup() const;
0081     quint32 posH() const;
0082     quint32 posRelH() const;
0083     quint32 posV() const;
0084     quint32 posRelV() const;
0085     quint32 pctHR() const;
0086     quint32 alignHR() const;
0087     qint32 dxHeightHR() const;
0088     qint32 dxWidthHR() const;
0089     MSO::OfficeArtCOLORREF borderTopColor() const;
0090     MSO::OfficeArtCOLORREF borderLeftColor() const;
0091     MSO::OfficeArtCOLORREF borderBottomColor() const;
0092     MSO::OfficeArtCOLORREF borderRightColor() const;
0093     // Group Shape Boolean Properties
0094     bool fPrint() const;
0095     bool fHidden() const;
0096     bool fOneD() const;
0097     bool fIsButton() const;
0098     bool fOnDblClickNotify() const;
0099     bool fBehindDocument() const;
0100     bool fEditedWrap() const;
0101     bool fScriptAnchor() const;
0102     bool fReallyHidden() const;
0103     bool fAllowOverlap() const;
0104     bool fUserDrawn() const;
0105     bool fHorizRule() const;
0106     bool fNoshadeHR() const;
0107     bool fStandardHR() const;
0108     bool fIsBullet() const;
0109     bool fLayoutInCell() const;
0110     bool fUsefPrint() const;
0111     bool fUsefHidden() const;
0112     bool fUsefOneD() const;
0113     bool fUsefIsButton() const;
0114     bool fUsefOnDblClickNotify() const;
0115     bool fUsefBehindDocument() const;
0116     bool fUsefEditedWrap() const;
0117     bool fUsefScriptAnchor() const;
0118     bool fUsefReallyHidden() const;
0119     bool fUsefAllowOverlap() const;
0120     bool fUsefUserDrawn() const;
0121     bool fUsefHorizRule() const;
0122     bool fUsefNoshadeHR() const;
0123     bool fUsefStandardHR() const;
0124     bool fUsefIsBullet() const;
0125     bool fUsefLayoutInCell() const;
0126 
0127     // Geometry property set
0128     qint32 geoLeft() const;
0129     qint32 geoTop() const;
0130     qint32 geoRight() const;
0131     qint32 geoBottom() const;
0132     quint32 shapePath() const;
0133     IMsoArray pVertices_complex() const;
0134     IMsoArray pSegmentInfo_complex() const;
0135     qint32 adjustvalue() const;
0136     qint32 adjust2value() const;
0137     qint32 adjust3value() const;
0138     qint32 adjust4value() const;
0139     qint32 adjust5value() const;
0140     qint32 adjust6value() const;
0141     qint32 adjust7value() const;
0142     qint32 adjust8value() const;
0143     // Geometry Boolean Properties
0144     bool fFillOk() const;
0145     bool fFillShadeShapeOK() const;
0146     bool fGtextOK() const;
0147     bool fLineOK() const;
0148     bool f3DOK() const;
0149     bool fShadowOK() const;
0150 
0151     // Fill Style property set
0152     quint32 fillType() const;
0153     MSO::OfficeArtCOLORREF fillColor() const;
0154     MSO::FixedPoint        fillOpacity() const;
0155     MSO::OfficeArtCOLORREF fillBackColor() const;
0156     MSO::FixedPoint        fillBackOpacity() const;
0157     MSO::OfficeArtCOLORREF fillCrMod() const;
0158     quint32 fillBlip() const;
0159     quint32 fillBlipName() const;
0160     QString fillBlipName_complex() const;
0161     quint32 fillBlipFlags() const;
0162     qint32 fillWidth() const;
0163     qint32 fillHeight() const;
0164     qint32 fillFocus() const;
0165     MSO::FixedPoint fillAngle() const;
0166     MSO::FixedPoint fillToLeft() const;
0167     MSO::FixedPoint fillToTop() const;
0168     MSO::FixedPoint fillToRight() const;
0169     MSO::FixedPoint fillToBottom() const;
0170     qint32 fillRectLeft() const;
0171     qint32 fillRectTop() const;
0172     qint32 fillRectRight() const;
0173     qint32 fillRectBottom() const;
0174     qint32 fillDztype() const;
0175     qint32 fillShadePreset() const;
0176     quint32 fillShadeColors() const;
0177     IMsoArray fillShadeColors_complex() const;
0178     MSO::FixedPoint fillOriginX() const;
0179     MSO::FixedPoint fillOriginY() const;
0180     MSO::FixedPoint fillShapeOriginX() const;
0181     MSO::FixedPoint fillShapeOriginY() const;
0182     /*     MSO::MSOSHADETYPE fillShadeType() const; */
0183     MSO::OfficeArtCOLORREF fillColorExt() const;
0184     MSO::OfficeArtCOLORREF fillBackColorExt() const;
0185     // Fill Style Boolean Properties
0186     bool fNoFillHitTest() const;
0187     bool fillUseRect() const;
0188     bool fillShape() const;
0189     bool fHitTestFill() const;
0190     bool fFilled() const;
0191     bool fUseShapeAnchor() const;
0192     bool fRecolorFillAsPicture() const;
0193 
0194     // Line Style property set
0195     MSO::OfficeArtCOLORREF lineColor() const;
0196     qint32 lineOpacity() const;
0197     quint32 lineWidth() const;
0198     quint32 lineDashing() const;
0199     quint32 lineStartArrowhead() const;
0200     quint32 lineEndArrowhead() const;
0201     quint32 lineStartArrowWidth() const;
0202     quint32 lineEndArrowWidth() const;
0203     quint32 lineEndArrowLength() const;
0204     quint32 lineJoinStyle() const;
0205     quint32 lineEndCapStyle() const;
0206     // Line Style Boolean Properties
0207     bool fNoLineDrawDash() const;
0208     bool fLineFillShape() const;
0209     bool fHitTestLine() const;
0210     bool fLine() const;
0211     bool fArrowHeadsOK() const;
0212     bool fInsetPenOK() const;
0213     bool fInsetPen() const;
0214     bool fLineOpaqueBackColor() const;
0215 
0216     // Shadow Style property set
0217     quint32 shadowType() const;
0218     MSO::OfficeArtCOLORREF shadowColor() const;
0219     MSO::FixedPoint shadowOpacity() const;
0220     qint32 shadowOffsetX() const;
0221     qint32 shadowOffsetY() const;
0222     // Shadow Style Boolean Properties
0223     bool fShadowObscured() const;
0224     bool fShadow() const;
0225 
0226     // Diagram property set
0227     // Diagram Boolean Properties
0228     bool fPseudoInline() const;
0229     bool fDoLayout() const;
0230     bool fReverse() const;
0231     bool fDoFormat() const;
0232 
0233     // Transformation property set
0234     MSO::FixedPoint rotation() const;
0235 
0236     // Text property set
0237     qint32 iTxid() const;
0238     qint32 dxTextLeft() const;
0239     qint32 dyTextTop() const;
0240     qint32 dxTextRight() const;
0241     qint32 dyTextBottom() const;
0242     quint32 wrapText() const;
0243     quint32 anchorText() const;
0244     quint32 txflTextFlow() const;
0245     quint32 cdirFont() const;
0246     quint32 hspNext() const;
0247     quint32 txdir() const;
0248     // Text Boolean Properties
0249     bool fFitShapeToText() const;
0250     bool fAutoTextMargin() const;
0251     bool fSelectText() const;
0252 
0253     // Blip property set
0254     MSO::FixedPoint cropFromTop() const;
0255     MSO::FixedPoint cropFromBottom() const;
0256     MSO::FixedPoint cropFromLeft() const;
0257     MSO::FixedPoint cropFromRight() const;
0258     quint32 pib() const;
0259     quint32 pibName() const;
0260     QString pibName_complex() const;
0261     quint32 pibFlags() const;
0262     MSO::OfficeArtCOLORREF pictureTransparent() const;
0263     qint32 pictureContrast() const;
0264     qint32 pictureBrightness() const;
0265     // Blip Boolean Properties
0266     bool fPictureActive() const;
0267     bool fPictureBiLevel() const;
0268     bool fPictureGray() const;
0269     bool fNoHitTestPicture() const;
0270     bool fLooping() const;
0271     bool fRewind() const;
0272     bool fPicturePreserveGrays() const;
0273 };
0274 
0275 /**
0276  * Retrieve an option from an options containing class B
0277  *
0278  * @p b must have a member fopt that is an array of type OfficeArtFOPTEChoice.
0279  * A is the type of the required option. The option containers in PPT/DOC have
0280  * only one instance of each option in an option container.
0281  * @param b class that contains options.
0282  * @return pointer to the option of type A or 0 if there is none.
0283  */
0284 template <typename A, typename B>
0285 const A*
0286 get(const B& b)
0287 {
0288     foreach(const MSO::OfficeArtFOPTEChoice& a, b.fopt) {
0289         const A *ptr = a.anon.get<A>();
0290         if (ptr) return ptr;
0291     }
0292     return 0;
0293 }
0294 /**
0295  * Retrieve an option from an OfficeArtSpContainer
0296  *
0297  * Look in all option containers in @p o for an option of type A.
0298  * @param o OfficeArtSpContainer instance which contains options.
0299  * @return pointer to the option of type A or 0 if there is none.
0300  */
0301 template <typename A>
0302 const A*
0303 get(const MSO::OfficeArtSpContainer& o)
0304 {
0305     const A* a = 0;
0306     if (o.shapePrimaryOptions) a = get<A>(*o.shapePrimaryOptions);
0307     if (!a && o.shapeSecondaryOptions1) a = get<A>(*o.shapeSecondaryOptions1);
0308     if (!a && o.shapeSecondaryOptions2) a = get<A>(*o.shapeSecondaryOptions2);
0309     if (!a && o.shapeTertiaryOptions1) a = get<A>(*o.shapeTertiaryOptions1);
0310     if (!a && o.shapeTertiaryOptions2) a = get<A>(*o.shapeTertiaryOptions2);
0311     return a;
0312 }
0313 /**
0314  * Retrieve an option from an OfficeArtDggContainer
0315  *
0316  * Look in all option containers in @p o for an option of type A.
0317  * @param o OfficeArtDggContainer instance which contains options.
0318  * @return pointer to the option of type A or 0 if there is none.
0319  */
0320 template <typename A>
0321 const A*
0322 get(const MSO::OfficeArtDggContainer& o)
0323 {
0324     const A* a = 0;
0325     if (o.drawingPrimaryOptions) {
0326         a = get<A>(*o.drawingPrimaryOptions);
0327     }
0328     if (!a && o.drawingTertiaryOptions) a = get<A>(*o.drawingTertiaryOptions);
0329     return a;
0330 }
0331 /**
0332  * Retrieve an option from a container
0333  *
0334  * Look in all option containers in @p o for an option of type A.
0335  * @param o OfficeArtDggContainer instance which contains options.
0336  * @return pointer to the option of type A or 0 if there is none.
0337  */
0338 template <typename A, typename T>
0339 const A*
0340 get(const T* o)
0341 {
0342     return (o) ?get<A>(*o) :0;
0343 }
0344 /**
0345  * Retrieve the complex data from an options containing class B
0346  *
0347  * @p b must have a member fopt that is an array of type OfficeArtFOPTEChoice.
0348  * A is the type of the required option.  The option containers in PPT/DOC have
0349  * only one instance of each option in an option container.
0350  *
0351  * @param b class that contains options.
0352  * @return IMsoArray storing complex data
0353  */
0354 template <typename A, typename B>
0355 IMsoArray
0356 getComplexData(const B& b)
0357 {
0358     MSO::OfficeArtFOPTE* p = nullptr;
0359     IMsoArray a;
0360     const char* pData = b.complexData.data();
0361     uint offset = 0;
0362 
0363     foreach(const MSO::OfficeArtFOPTEChoice& _c, b.fopt) {
0364         p = (MSO::OfficeArtFOPTE*) _c.anon.data();
0365         if (p->opid.fComplex) {
0366 
0367             // there is wrong offset inside PVertices
0368             if (_c.anon.is<MSO::PVertices>()) {
0369                 if (_c.anon.get<A>()) {
0370                     if (b.complexData.size() - offset >= 6) {
0371                         a.nElems = *(quint16 *)(pData + offset);
0372                         a.nElemsAlloc = *(quint16 *)(pData + offset +2);
0373                         a.cbElem = *(quint16 *)(pData + offset + 4);
0374                         a.data = b.complexData.mid(offset+6, p->op);
0375                         break;
0376                     }
0377                 } else {
0378                     offset += p->op +6;
0379                 }
0380             } else {
0381                 if (_c.anon.get<A>()) {
0382                     if (b.complexData.size() - offset >= 6) {
0383                         a.nElems = *(quint16 *)(pData + offset);
0384                         a.nElemsAlloc = *(quint16 *)(pData + offset +2);
0385                         a.cbElem = *(quint16 *)(pData + offset + 4);
0386                         a.data = b.complexData.mid(offset+6, p->op-6);
0387                         break;
0388                     }
0389                 } else {
0390                     offset += p->op;
0391                 }
0392             }
0393         }
0394     }
0395     return a;
0396 }
0397 
0398 /**
0399  * Retrieve the complex data, which represent an IMsoArray for an option from
0400  * an OfficeArtSpContainer.
0401  *
0402  * Look in all option containers in @p o for an option of type A.
0403  *
0404  * @param o OfficeArtSpContainer instance which contains options
0405  * @return IMsoArray storing complex data
0406  */
0407 template <typename A>
0408 IMsoArray
0409 getComplexData(const MSO::OfficeArtSpContainer& o)
0410 {
0411     IMsoArray a;
0412     if (o.shapePrimaryOptions) a = getComplexData<A>(*o.shapePrimaryOptions);
0413     if (!a.data.size() && o.shapeSecondaryOptions1) a = getComplexData<A>(*o.shapeSecondaryOptions1);
0414     if (!a.data.size() && o.shapeSecondaryOptions2) a = getComplexData<A>(*o.shapeSecondaryOptions2);
0415     if (!a.data.size() && o.shapeTertiaryOptions1) a = getComplexData<A>(*o.shapeTertiaryOptions1);
0416     if (!a.data.size() && o.shapeTertiaryOptions2) a = getComplexData<A>(*o.shapeTertiaryOptions2);
0417     return a;
0418 }
0419 
0420 /**
0421  * Retrieve the complex data, which represent a null-terminated unicode string
0422  * from an options containing class B.
0423  *
0424  * @p b must have a member fopt that is an array of type OfficeArtFOPTEChoice.
0425  * A is the type of the required option.  The option containers in PPT/DOC have
0426  * only one instance of each option in an option container.
0427  *
0428  * @param b class that contains options.
0429  * @return QString storing complex data
0430  */
0431 template <typename A, typename B>
0432 QString
0433 getComplexName(const B& b)
0434 {
0435     MSO::OfficeArtFOPTE* p = nullptr;
0436     uint offset = 0;
0437     QString a;
0438 
0439     foreach(const MSO::OfficeArtFOPTEChoice& _c, b.fopt) {
0440         p = (MSO::OfficeArtFOPTE*) _c.anon.data();
0441         if (p->opid.fComplex) {
0442             if (_c.anon.get<A>()) {
0443                 a.append(b.complexData.mid(offset, p->op));
0444                 break;
0445             } else {
0446                 offset += p->op;
0447             }
0448         }
0449     }
0450     return a;
0451 }
0452 
0453 /**
0454  * Retrieve the complex data, which represent a null-terminated unicode string
0455  * for an option from an OfficeArtSpContainer.
0456  *
0457  * Look in all option containers in @p o for an option of type A.
0458  *
0459  * @param o OfficeArtSpContainer instance which contains options
0460  * @return QString storing complex data
0461  */
0462 template <typename A>
0463 QString
0464 getComplexName(const MSO::OfficeArtSpContainer& o)
0465 {
0466     QString a;
0467     if (o.shapePrimaryOptions) a = getComplexName<A>(*o.shapePrimaryOptions);
0468     if (!a.isEmpty() && o.shapeSecondaryOptions1) a = getComplexName<A>(*o.shapeSecondaryOptions1);
0469     if (!a.isEmpty() && o.shapeSecondaryOptions2) a = getComplexName<A>(*o.shapeSecondaryOptions2);
0470     if (!a.isEmpty() && o.shapeTertiaryOptions1) a = getComplexName<A>(*o.shapeTertiaryOptions1);
0471     if (!a.isEmpty() && o.shapeTertiaryOptions2) a = getComplexName<A>(*o.shapeTertiaryOptions2);
0472     return a;
0473 }
0474 
0475 #endif