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