File indexing completed on 2025-01-12 10:34:19

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 #include "drawstyle.h"
0008 #include "msodraw.h"
0009 
0010 namespace
0011 {
0012 const MSO::OfficeArtCOLORREF ignore()
0013 {
0014     MSO::OfficeArtCOLORREF w;
0015     w.red = w.green = w.blue = 0xFF;
0016     w.fPaletteIndex = w.fPaletteRGB = w.fSystemRGB = w.fSchemeIndex
0017                                       = w.fSysIndex = true;
0018     return w;
0019 }
0020 const MSO::OfficeArtCOLORREF white()
0021 {
0022     MSO::OfficeArtCOLORREF w;
0023     w.red = w.green = w.blue = 0xFF;
0024     w.fPaletteIndex = w.fPaletteRGB = w.fSystemRGB = w.fSchemeIndex
0025                                       = w.fSysIndex = false;
0026     return w;
0027 }
0028 // The default value for this property is 0x20000000
0029 const MSO::OfficeArtCOLORREF crmodDefault()
0030 {
0031     MSO::OfficeArtCOLORREF w;
0032     w.red = w.green = w.blue = 0x00;
0033     w.fPaletteIndex = w.fPaletteRGB = w.fSchemeIndex = w.fSysIndex = false;
0034     w.fSystemRGB = true;
0035     return w;
0036 }
0037 const MSO::OfficeArtCOLORREF black()
0038 {
0039     MSO::OfficeArtCOLORREF b;
0040     b.red = b.green = b.blue = 0;
0041     b.fPaletteIndex = b.fPaletteRGB = b.fSystemRGB = b.fSchemeIndex
0042                                       = b.fSysIndex = false;
0043     return b;
0044 }
0045 const MSO::OfficeArtCOLORREF gray()
0046 {
0047     MSO::OfficeArtCOLORREF b;
0048     b.red = b.green = b.blue = 0x80;
0049     b.fPaletteIndex = b.fPaletteRGB = b.fSystemRGB = b.fSchemeIndex
0050                                       = b.fSysIndex = false;
0051     return b;
0052 }
0053 const MSO::FixedPoint one()
0054 {
0055     MSO::FixedPoint one;
0056     one.integral = 1;
0057     one.fractional = 0;
0058     return one;
0059 }
0060 const MSO::FixedPoint zero()
0061 {
0062     MSO::FixedPoint zero;
0063     zero.integral = 0;
0064     zero.fractional = 0;
0065     return zero;
0066 }
0067 //NOTE: msohadeDefault is not defined in MS-ODRAW, just guessing
0068 // const MSO::MSOSHADETYPE msoshadeDefault() {
0069 //     MSO::MSOSHADETYPE tmp;
0070 //     tmp.msoshadeNone = 0;
0071 //     tmp.msoshadeGamma = 0;
0072 //     tmp.msoshadeSigma = 0;
0073 //     tmp.msoshadeBand = 0;
0074 //     tmp.msoshadeOneColor = 0;
0075 //     return tmp;
0076 // }
0077 } //namespace
0078 
0079 quint16 DrawStyle::shapeType() const
0080 {
0081     if (!sp) {
0082         return msosptNil;
0083     } else {
0084         return sp->shapeProp.rh.recInstance;
0085     }
0086 }
0087 
0088 #define GETTER(TYPE, FOPT, NAME, DEFAULT) \
0089     TYPE DrawStyle::NAME() const \
0090     { \
0091         const MSO::FOPT* p = 0; \
0092         if (sp) { \
0093             p = get<MSO::FOPT>(*sp); \
0094         } \
0095         if (!p && mastersp) { \
0096             p = get<MSO::FOPT>(*mastersp); \
0097         } \
0098         if (!p && d) { \
0099             p = get<MSO::FOPT>(*d); \
0100         } \
0101         if (p) { \
0102             return p->NAME; \
0103         } \
0104         return DEFAULT; \
0105     }
0106 
0107 //     TYPE                    FOPT                  NAME                  DEFAULT         ODRAW Ref
0108 GETTER(quint32,                HspMaster,            hspMaster,            0)              // 2.3.2.1
0109 GETTER(quint32,                Cxstyle,              cxstyle,              0x00000003)     // 2.3.2.2
0110 GETTER(quint32,                BWMode,               bWMode,               1)              // 2.3.2.3
0111 GETTER(quint32,                PWrapPolygonVertices, pWrapPolygonVertices, 0)              // 2.3.4.7
0112 GETTER(qint32,                 DxWrapDistLeft,       dxWrapDistLeft,       0x0001be7c)     // 2.3.4.9
0113 GETTER(qint32,                 DyWrapDistTop,        dyWrapDistTop,        0)              // 2.3.4.10
0114 GETTER(qint32,                 DxWrapDistRight,      dxWrapDistRight,      0x0001be7c)     // 2.3.4.11
0115 GETTER(qint32,                 DyWrapDistBottom,     dyWrapDistBottom,     0)              // 2.3.4.12
0116 GETTER(quint32,                LidRegroup,           lidRegroup,           0)              // 2.3.4.13
0117 GETTER(quint32,                PosH,                 posH,                 0)              // 2.3.4.19
0118 GETTER(quint32,                PosRelH,              posRelH,              2)              // 2.3.4.20
0119 GETTER(quint32,                PosV,                 posV,                 0)              // 2.3.4.21
0120 GETTER(quint32,                PosRelV,              posRelV,              2)              // 2.3.4.22
0121 GETTER(quint32,                PctHR,                pctHR,                0x000003e8)     // 2.3.4.23
0122 GETTER(quint32,                AlignHR,              alignHR,              0)              // 2.3.4.24
0123 GETTER(qint32,                 DxHeightHR,           dxHeightHR,           0)              // 2.3.4.25
0124 GETTER(qint32,                 DxWidthHR,            dxWidthHR,            0)              // 2.3.4.26
0125 GETTER(MSO::OfficeArtCOLORREF, BorderTopColor,       borderTopColor,       white())        // 2.3.4.32
0126 GETTER(MSO::OfficeArtCOLORREF, BorderLeftColor,      borderLeftColor,      white())        // 2.3.4.33
0127 GETTER(MSO::OfficeArtCOLORREF, BorderBottomColor,    borderBottomColor,    white())        // 2.3.4.34
0128 GETTER(MSO::OfficeArtCOLORREF, BorderRightColor,     borderRightColor,     white())        // 2.3.4.35
0129 GETTER(qint32,                 GeoLeft,              geoLeft,              0)              // 2.3.6.1
0130 GETTER(qint32,                 GeoTop,               geoTop,               0)              // 2.3.6.2
0131 GETTER(qint32,                 GeoRight,             geoRight,             0x00005460)     // 2.3.6.3
0132 GETTER(qint32,                 GeoBottom,            geoBottom,            0x00005460)     // 2.3.6.4
0133 GETTER(quint32,                ShapePath,            shapePath,            0x00000001)     // 2.3.6.5
0134 GETTER(qint32,                 AdjustValue,          adjustvalue,          0)              // 2.3.6.10
0135 GETTER(qint32,                 Adjust2Value,         adjust2value,         0)              // 2.3.6.11
0136 GETTER(qint32,                 Adjust3Value,         adjust3value,         0)              // 2.3.6.12
0137 GETTER(qint32,                 Adjust4Value,         adjust4value,         0)              // 2.3.6.13
0138 GETTER(qint32,                 Adjust5Value,         adjust5value,         0)              // 2.3.6.14
0139 GETTER(qint32,                 Adjust6Value,         adjust6value,         0)              // 2.3.6.15
0140 GETTER(qint32,                 Adjust7Value,         adjust7value,         0)              // 2.3.6.16
0141 GETTER(qint32,                 Adjust8Value,         adjust8value,         0)              // 2.3.6.17
0142 GETTER(quint32,                FillType,             fillType,             0)              // 2.3.7.1
0143 GETTER(MSO::OfficeArtCOLORREF, FillColor,            fillColor,            white())        // 2.3.7.2
0144 GETTER(MSO::FixedPoint,        FillOpacity,          fillOpacity,          one())          // 2.3.7.3
0145 GETTER(MSO::OfficeArtCOLORREF, FillBackColor,        fillBackColor,        white())        // 2.3.7.4
0146 GETTER(MSO::FixedPoint,        FillBackOpacity,      fillBackOpacity,      one())          // 2.3.7.5
0147 GETTER(MSO::OfficeArtCOLORREF, FillCrMod,            fillCrMod,            crmodDefault()) // 2.3.7.6
0148 GETTER(quint32,                FillBlip,             fillBlip,             0)              // 2.3.7.7
0149 GETTER(quint32,                FillBlipName,         fillBlipName,         0)              // 2.3.7.9
0150 GETTER(quint32,                FillBlipFlags,        fillBlipFlags,        0)              // 2.3.7.11
0151 GETTER(qint32,                 FillWidth,            fillWidth,            0)              // 2.3.7.12
0152 GETTER(qint32,                 FillHeight,           fillHeight,           0)              // 2.3.7.13
0153 GETTER(MSO::FixedPoint,        FillAngle,            fillAngle,            zero())         // 2.3.7.14
0154 GETTER(qint32,                 FillFocus,            fillFocus,            0)              // 2.3.7.15
0155 GETTER(MSO::FixedPoint,        FillToLeft,           fillToLeft,           zero())         // 2.3.7.16
0156 GETTER(MSO::FixedPoint,        FillToTop,            fillToTop,            zero())         // 2.3.7.17
0157 GETTER(MSO::FixedPoint,        FillToRight,          fillToRight,          zero())         // 2.3.7.18
0158 GETTER(MSO::FixedPoint,        FillToBottom,         fillToBottom,         zero())         // 2.3.7.19
0159 GETTER(qint32,                 FillRectLeft,         fillRectLeft,         0)              // 2.3.7.20
0160 GETTER(qint32,                 FillRectTop,          fillRectTop,          0)              // 2.3.7.21
0161 GETTER(qint32,                 FillRectRight,        fillRectRight,        0)              // 2.3.7.22
0162 GETTER(qint32,                 FillRectBottom,       fillRectBottom,       0)              // 2.3.7.23
0163 GETTER(qint32,                 FillDztype,           fillDztype,           0)              // 2.3.7.24
0164 GETTER(qint32,                 FillShadePreset,      fillShadePreset,      0)              // 2.3.7.25
0165 GETTER(quint32,                FillShadeColors,      fillShadeColors,      0)              // 2.3.7.26
0166 GETTER(MSO::FixedPoint,        FillOriginX,          fillOriginX,          zero())         // 2.3.7.28
0167 GETTER(MSO::FixedPoint,        FillOriginY,          fillOriginY,          zero())         // 2.3.7.29
0168 GETTER(MSO::FixedPoint,        FillShapeOriginX,     fillShapeOriginX,     zero())         // 2.3.7.30
0169 GETTER(MSO::FixedPoint,        FillShapeOriginY,     fillShapeOriginY,     zero())         // 2.3.7.31
0170 // GETTER(MSO::MSOSHADETYPE,      FillShadeType,        fillShadeType,        msoshadeDefault()) // 2.3.7.32
0171 GETTER(MSO::OfficeArtCOLORREF, FillColorExt,         fillColorExt,         white())        // 2.3.7.33
0172 GETTER(MSO::OfficeArtCOLORREF, FillBackColorExt,     fillBackColorExt,     white())        // 2.3.7.37
0173 GETTER(MSO::OfficeArtCOLORREF, LineColor,            lineColor,            black())        // 2.3.8.1
0174 GETTER(qint32,                 LineOpacity,          lineOpacity,          0x10000)        // 2.3.8.2
0175 GETTER(quint32,                LineWidth,            lineWidth,            0x2535)         // 2.3.8.14
0176 GETTER(quint32,                LineDashing,          lineDashing,          0)              // 2.3.8.17
0177 GETTER(quint32,                LineStartArrowhead,   lineStartArrowhead,   0)              // 2.3.8.20
0178 GETTER(quint32,                LineEndArrowhead,     lineEndArrowhead,     0)              // 2.3.8.21
0179 GETTER(quint32,                LineStartArrowWidth,  lineStartArrowWidth,  1)              // 2.3.8.22
0180 GETTER(quint32,                LineEndArrowWidth,    lineEndArrowWidth,    1)              // 2.3.8.24
0181 GETTER(quint32,                LineEndArrowLength,   lineEndArrowLength,   1)              // 2.3.8.25
0182 GETTER(quint32,                LineJoinStyle,        lineJoinStyle,        2)              // 2.3.8.26
0183 GETTER(quint32,                LineEndCapStyle,      lineEndCapStyle,      2)              // 2.3.8.27
0184 GETTER(quint32,                ShadowType,           shadowType,           0)              // 2.3.13.1
0185 GETTER(MSO::OfficeArtCOLORREF, ShadowColor,          shadowColor,          gray())         // 2.3.13.2
0186 GETTER(MSO::FixedPoint,        ShadowOpacity,        shadowOpacity,        one())          // 2.3.13.5
0187 GETTER(qint32,                 ShadowOffsetX,        shadowOffsetX,        0x6338)         // 2.3.13.6
0188 GETTER(qint32,                 ShadowOffsetY,        shadowOffsetY,        0x6338)         // 2.3.13.7
0189 GETTER(MSO::FixedPoint,        Rotation,             rotation,             zero())         // 2.3.18.5
0190 GETTER(qint32,                 ITxid,                iTxid,                0)              // 2.3.21.1
0191 GETTER(qint32,                 DxTextLeft,           dxTextLeft,           0x00016530)     // 2.3.21.2
0192 GETTER(qint32,                 DyTextTop,            dyTextTop,            0x0000B298)     // 2.3.21.3
0193 GETTER(qint32,                 DxTextRight,          dxTextRight,          0x00016530)     // 2.3.21.4
0194 GETTER(qint32,                 DyTextBottom,         dyTextBottom,         0x0000B298)     // 2.3.21.5
0195 GETTER(quint32,                WrapText,             wrapText,             0)              // 2.3.21.6
0196 GETTER(quint32,                AnchorText,           anchorText,           0)              // 2.3.21.8
0197 GETTER(quint32,                TxflTextFlow,         txflTextFlow,         0)              // 2.3.21.9
0198 GETTER(quint32,                CdirFont,             cdirFont,             0)              // 2.3.21.10
0199 GETTER(quint32,                HspNext,              hspNext,              0)              // 2.3.21.11
0200 GETTER(quint32,                Txdir,                txdir,                0)              // 2.3.21.12
0201 GETTER(MSO::FixedPoint,        CropFromTop,          cropFromTop,          zero())         // 2.3.23.1
0202 GETTER(MSO::FixedPoint,        CropFromBottom,       cropFromBottom,       zero())         // 2.3.23.2
0203 GETTER(MSO::FixedPoint,        CropFromLeft,         cropFromLeft,         zero())         // 2.3.23.3
0204 GETTER(MSO::FixedPoint,        CropFromRight,        cropFromRight,        zero())         // 2.3.23.4
0205 GETTER(quint32,                Pib,                  pib,                  0)              // 2.3.23.5
0206 GETTER(quint32,                PibName,              pibName,              0)              // 2.3.23.7
0207 GETTER(quint32,                PibFlags,             pibFlags,             0)              // 2.3.23.9
0208 GETTER(MSO::OfficeArtCOLORREF, PictureTransparent,   pictureTransparent,   ignore())       // 2.3.23.10
0209 GETTER(qint32,                 PictureContrast,      pictureContrast,      0x00010000)     // 2.3.23.11
0210 GETTER(qint32,                 PictureBrightness,    pictureBrightness,    0)              // 2.3.23.12
0211 #undef GETTER
0212 
0213 #define GETTER(NAME, TEST, DEFAULT) \
0214     bool DrawStyle::NAME() const \
0215     { \
0216         const MSO::FOPT* p = 0; \
0217         if (sp) { \
0218             p = get<MSO::FOPT>(*sp); \
0219             if (p && p->TEST) { \
0220                 return p->NAME; \
0221             } \
0222         } \
0223         if (mastersp) { \
0224             p = get<MSO::FOPT>(*mastersp); \
0225             if (p && p->TEST) { \
0226                 return p->NAME; \
0227             } \
0228         } \
0229         if (d) { \
0230             p = get<MSO::FOPT>(d); \
0231             if (p && p->TEST) { \
0232                 return p->NAME; \
0233             } \
0234         } \
0235         return DEFAULT; \
0236     }
0237 
0238 //TODO: CalloutBooleanProperties, ProtectionBooleanProperties
0239 
0240 // FOPT        NAME           TEST                       DEFAULT
0241 #define FOPT ShapeBooleanProperties
0242 GETTER(fBackground,           fUsefBackground,           false)
0243 GETTER(fInitiator,            fUsefInitiator,            false)
0244 GETTER(fLockShapeType,        fUsefLockShapeType,        false)
0245 GETTER(fPreferRelativeResize, fusePreferrelativeResize,  false)
0246 GETTER(fOleIcon,              fUsefOleIcon,              false)
0247 GETTER(fFlipVOverride,        fUsefFlipVOverride,        false)
0248 GETTER(fFlipHOverride,        fUsefFlipHOverride,        false)
0249 GETTER(fPolicyBarcode,        fUsefPolicyBarcode,        false)
0250 GETTER(fPolicyLabel,          fUsefPolicyLabel,          false)
0251 #undef FOPT
0252 #define FOPT GroupShapeBooleanProperties
0253 GETTER(fPrint,                fUsefPrint,                true)
0254 GETTER(fHidden,               fUsefHidden,               false)
0255 GETTER(fOneD,                 fUsefOneD,                 false)
0256 GETTER(fIsButton,             fUsefIsButton,             false)
0257 GETTER(fOnDblClickNotify,     fUsefOnDblClickNotify,     false)
0258 GETTER(fBehindDocument,       fUsefBehindDocument,       false)
0259 GETTER(fEditedWrap,           fUsefEditedWrap,           false)
0260 GETTER(fScriptAnchor,         fUsefScriptAnchor,         false)
0261 GETTER(fReallyHidden,         fUsefReallyHidden,         false)
0262 GETTER(fAllowOverlap,         fUsefAllowOverlap,         true)
0263 GETTER(fUserDrawn,            fUsefUserDrawn,            false)
0264 GETTER(fHorizRule,            fUsefHorizRule,            false)
0265 GETTER(fNoshadeHR,            fUsefNoshadeHR,            false)
0266 GETTER(fStandardHR,           fUsefStandardHR,           false)
0267 GETTER(fIsBullet,             fUsefIsBullet,             false)
0268 GETTER(fLayoutInCell,         fUsefLayoutInCell,         true)
0269 #undef FOPT
0270 #define FOPT GeometryBooleanProperties
0271 GETTER(fFillOk,                fUsefFillOK,              true)
0272 GETTER(fFillShadeShapeOK,      fUsefFillShadeShapeOK,    false)
0273 GETTER(fGtextOK,               fUsefGtextOK,             false)
0274 GETTER(fLineOK,                fUsefLineOK,              true)
0275 GETTER(f3DOK,                  fUsef3DOK,                true)
0276 GETTER(fShadowOK,              fUsefShadowOK,            true)
0277 #undef FOPT
0278 #define FOPT FillStyleBooleanProperties
0279 GETTER(fNoFillHitTest,        fUseNoFillHitTest,         false)
0280 GETTER(fillUseRect,           fUseFillUseRect,           false)
0281 GETTER(fillShape,             fUseFillShape,             true)
0282 GETTER(fHitTestFill,          fUseHitTestFill,           true)
0283 GETTER(fFilled,               fUseFilled,                true)
0284 GETTER(fUseShapeAnchor,       fUseUseShapeAnchor,        false)
0285 GETTER(fRecolorFillAsPicture, fUsefRecolorFillAsPicture, false)
0286 #undef FOPT
0287 #define FOPT LineStyleBooleanProperties
0288 GETTER(fNoLineDrawDash,       fUseNoLineDrawDash,        false)
0289 GETTER(fLineFillShape,        fUseLineFillShape,         false)
0290 GETTER(fHitTestLine,          fUseHitTestLine,           true)
0291 // GETTER(fLine,                 fUsefLine,                 true)
0292 GETTER(fArrowHeadsOK,         fUsefArrowHeadsOK,         false)
0293 GETTER(fInsetPenOK,           fUseInsetPenOK,            true)
0294 GETTER(fInsetPen,             fUseInsetPen,              false)
0295 GETTER(fLineOpaqueBackColor,  fUsefLineOpaqueBackColor,  false)
0296 #undef FOPT
0297 #define FOPT ShadowStyleBooleanProperties
0298 GETTER(fShadowObscured,       fUsefShadowObscured,       false)
0299 GETTER(fShadow,               fUsefShadow,               false)
0300 #undef FOPT
0301 #define FOPT DiagramBooleanProperties
0302 GETTER(fPseudoInline,         fUsefPseudoInline,         false)
0303 GETTER(fDoLayout,             fUsefDoLayout,             true)
0304 GETTER(fReverse,              fUsefReverse,              false)
0305 GETTER(fDoFormat,             fUsefDoFormat,             false)
0306 #undef FOPT
0307 #define FOPT TextBooleanProperties
0308 GETTER(fFitShapeToText,       fUsefFitShapeToText,       false)
0309 GETTER(fAutoTextMargin,       fUsefAutoTextMargin,       false)
0310 GETTER(fSelectText,           fUsefSelectText,           true)
0311 #undef FOPT
0312 #define FOPT BlipBooleanProperties
0313 GETTER(fPictureActive,        fUsefPictureActive,        false)
0314 GETTER(fPictureBiLevel,       fUsefPictureBiLevel,       false)
0315 GETTER(fPictureGray,          fUsefPictureGray,          false)
0316 GETTER(fNoHitTestPicture,     fUsefNoHitTestPicture,     false)
0317 GETTER(fLooping,              fUsefLooping,              false)
0318 GETTER(fRewind,               fUsefRewind,               false)
0319 GETTER(fPicturePreserveGrays, fUsefPicturePreserveGrays, false)
0320 #undef FOPT
0321 #undef GETTER
0322 
0323 // The override was discussed at Office File Formats Forum:
0324 // http://social.msdn.microsoft.com/Forums/en-US/os_binaryfile/thread/a1cf51a7-fb93-4028-b3ac-3ed2fd77a94b
0325 bool DrawStyle::fLine() const
0326 {
0327     const MSO::LineStyleBooleanProperties* p = 0;
0328     quint16 shapeType = msosptNil;
0329 
0330     if (sp) {
0331         shapeType = sp->shapeProp.rh.recInstance;
0332         p = get<MSO::LineStyleBooleanProperties>(*sp);
0333         if (p && p->fUsefLine) {
0334             return p->fLine;
0335         }
0336     }
0337     if (mastersp) {
0338         p = get<MSO::LineStyleBooleanProperties>(*mastersp);
0339         if (p && p->fUsefLine) {
0340             return p->fLine;
0341         }
0342     }
0343     if (shapeType == msosptPictureFrame) {
0344         return false;
0345     } else {
0346         return true;
0347     }
0348 }
0349 
0350 #define COMPLEX(FOPT, NAME) \
0351     IMsoArray DrawStyle::NAME() const \
0352     { \
0353         IMsoArray a;\
0354         if (sp) { \
0355             a = getComplexData<MSO::FOPT>(*sp); \
0356             return a;\
0357         } \
0358         if (mastersp) { \
0359             a = getComplexData<MSO::FOPT>(*mastersp); \
0360             return a;\
0361         } \
0362         return a;\
0363     }
0364 // FOPT                       NAME
0365 COMPLEX(FillShadeColors,      fillShadeColors_complex)
0366 COMPLEX(PVertices,            pVertices_complex)
0367 COMPLEX(PSegmentInfo,         pSegmentInfo_complex)
0368 COMPLEX(PWrapPolygonVertices, pWrapPolygonVertices_complex)
0369 #undef COMPLEX
0370 
0371 #define COMPLEX_NAME(FOPT, NAME) \
0372     QString DrawStyle::NAME() const \
0373     { \
0374         QString a;\
0375         if (sp) { \
0376             a = getComplexName<MSO::FOPT>(*sp); \
0377             if (!a.isNull()) return a; \
0378         } \
0379         if (mastersp) { \
0380             a = getComplexName<MSO::FOPT>(*mastersp); \
0381             if (!a.isNull()) return a; \
0382         } \
0383         return a;\
0384     }
0385 // FOPT                       NAME
0386 COMPLEX_NAME(PibName,         pibName_complex)
0387 COMPLEX_NAME(FillBlipName,    fillBlipName_complex)
0388 #undef COMPLEX_NAME