File indexing completed on 2025-01-19 10:49:08

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