1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_SVGIO_INC_SVGSTYLEATTRIBUTES_HXX 21 #define INCLUDED_SVGIO_INC_SVGSTYLEATTRIBUTES_HXX 22 23 #include "svgpaint.hxx" 24 #include "svgnode.hxx" 25 #include <vcl/vclenum.hxx> 26 #include <tools/fontenum.hxx> 27 #include <basegfx/polygon/b2dpolypolygontools.hxx> 28 29 30 // predefines 31 32 namespace svgio { namespace svgreader { 33 class SvgGradientNode; 34 class SvgPatternNode; 35 class SvgMarkerNode; 36 class SvgClipPathNode; 37 class SvgMaskNode; 38 }} 39 40 41 namespace svgio 42 { 43 namespace svgreader 44 { 45 enum StrokeLinecap 46 { 47 StrokeLinecap_notset, 48 StrokeLinecap_butt, 49 StrokeLinecap_round, 50 StrokeLinecap_square 51 }; 52 53 enum StrokeLinejoin 54 { 55 StrokeLinejoin_notset, 56 StrokeLinejoin_miter, 57 StrokeLinejoin_round, 58 StrokeLinejoin_bevel 59 }; 60 61 enum FontSize 62 { 63 FontSize_notset, 64 FontSize_xx_small, 65 FontSize_x_small, 66 FontSize_small, 67 FontSize_smaller, 68 FontSize_medium, 69 FontSize_large, 70 FontSize_larger, 71 FontSize_x_large, 72 FontSize_xx_large, 73 FontSize_initial 74 }; 75 76 enum FontStretch 77 { 78 FontStretch_notset, 79 FontStretch_normal, 80 FontStretch_wider, 81 FontStretch_narrower, 82 FontStretch_ultra_condensed, 83 FontStretch_extra_condensed, 84 FontStretch_condensed, 85 FontStretch_semi_condensed, 86 FontStretch_semi_expanded, 87 FontStretch_expanded, 88 FontStretch_extra_expanded, 89 FontStretch_ultra_expanded 90 }; 91 92 FontStretch getWider(FontStretch aSource); 93 FontStretch getNarrower(FontStretch aSource); 94 95 enum FontStyle 96 { 97 FontStyle_notset, 98 FontStyle_normal, 99 FontStyle_italic, 100 FontStyle_oblique 101 }; 102 103 enum FontWeight 104 { 105 FontWeight_notset, 106 FontWeight_100, 107 FontWeight_200, 108 FontWeight_300, 109 FontWeight_400, // same as FontWeight_normal 110 FontWeight_500, 111 FontWeight_600, 112 FontWeight_700, // same as FontWeight_bold 113 FontWeight_800, 114 FontWeight_900, 115 FontWeight_bolder, 116 FontWeight_lighter, 117 }; 118 119 FontWeight getBolder(FontWeight aSource); 120 FontWeight getLighter(FontWeight aSource); 121 ::FontWeight getVclFontWeight(FontWeight aSource); 122 123 enum TextAlign 124 { 125 TextAlign_notset, 126 TextAlign_left, 127 TextAlign_right, 128 TextAlign_center, 129 TextAlign_justify 130 }; 131 132 enum TextDecoration 133 { 134 TextDecoration_notset, 135 TextDecoration_none, 136 TextDecoration_underline, 137 TextDecoration_overline, 138 TextDecoration_line_through, 139 TextDecoration_blink 140 }; 141 142 enum TextAnchor 143 { 144 TextAnchor_notset, 145 TextAnchor_start, 146 TextAnchor_middle, 147 TextAnchor_end 148 }; 149 150 enum FillRule 151 { 152 FillRule_notset, 153 FillRule_nonzero, 154 FillRule_evenodd 155 }; 156 157 enum BaselineShift 158 { 159 BaselineShift_Baseline, 160 BaselineShift_Sub, 161 BaselineShift_Super, 162 BaselineShift_Percentage, 163 BaselineShift_Length 164 }; 165 166 enum Visibility 167 { 168 Visibility_notset, 169 Visibility_visible, 170 Visibility_hidden, 171 Visibility_collapse, 172 Visibility_inherit 173 }; 174 175 class SvgStyleAttributes 176 { 177 private: 178 SvgNode& mrOwner; 179 const SvgStyleAttributes* mpCssStyleParent; 180 SvgPaint maFill; 181 SvgPaint maStroke; 182 SvgPaint maStopColor; 183 SvgNumber maStrokeWidth; 184 SvgNumber maStopOpacity; 185 SvgNumber maFillOpacity; 186 SvgNumberVector maStrokeDasharray; 187 SvgNumber maStrokeDashOffset; 188 StrokeLinecap maStrokeLinecap; 189 StrokeLinejoin maStrokeLinejoin; 190 SvgNumber maStrokeMiterLimit; 191 SvgNumber maStrokeOpacity; 192 SvgStringVector maFontFamily; 193 FontSize maFontSize; 194 SvgNumber maFontSizeNumber; 195 FontStretch maFontStretch; 196 FontStyle maFontStyle; 197 FontWeight maFontWeight; 198 TextAlign maTextAlign; 199 TextDecoration maTextDecoration; 200 TextAnchor maTextAnchor; 201 SvgPaint maColor; 202 SvgNumber maOpacity; 203 Visibility maVisibility; 204 OUString maTitle; 205 OUString maDesc; 206 207 /// link to content. If set, the node can be fetched on demand 208 OUString maClipPathXLink; 209 const SvgClipPathNode* mpClipPathXLink; 210 OUString maMaskXLink; 211 const SvgMaskNode* mpMaskXLink; 212 213 /// link to markers. If set, the node can be fetched on demand 214 OUString maMarkerStartXLink; 215 const SvgMarkerNode* mpMarkerStartXLink; 216 OUString maMarkerMidXLink; 217 const SvgMarkerNode* mpMarkerMidXLink; 218 OUString maMarkerEndXLink; 219 const SvgMarkerNode* mpMarkerEndXLink; 220 221 /// fill rule 222 FillRule maFillRule; 223 224 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero) 225 FillRule maClipRule; 226 227 // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length) 228 BaselineShift maBaselineShift; 229 SvgNumber maBaselineShiftNumber; 230 231 mutable std::vector<sal_uInt16> maResolvingParent; 232 233 // defines if this attributes are part of a ClipPath. If yes, 234 // rough geometry will be created on decomposition by patching 235 // values for fill, stroke, strokeWidth and others 236 bool mbIsClipPathContent : 1; 237 238 // #121221# Defines if evtl. an empty array *is* set 239 bool mbStrokeDasharraySet : 1; 240 241 // tdf#94765 Check id references in gradient/pattern getters 242 OUString maNodeFillURL; 243 OUString maNodeStrokeURL; 244 245 /// internal helpers 246 void add_fillGradient( 247 const basegfx::B2DPolyPolygon& rPath, 248 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 249 const SvgGradientNode& rFillGradient, 250 const basegfx::B2DRange& rGeoRange) const; 251 void add_fillPatternTransform( 252 const basegfx::B2DPolyPolygon& rPath, 253 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 254 const SvgPatternNode& rFillGradient, 255 const basegfx::B2DRange& rGeoRange) const; 256 void add_fillPattern( 257 const basegfx::B2DPolyPolygon& rPath, 258 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 259 const SvgPatternNode& rFillGradient, 260 const basegfx::B2DRange& rGeoRange) const; 261 void add_fill( 262 const basegfx::B2DPolyPolygon& rPath, 263 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 264 const basegfx::B2DRange& rGeoRange) const; 265 void add_stroke( 266 const basegfx::B2DPolyPolygon& rPath, 267 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 268 const basegfx::B2DRange& rGeoRange) const; 269 bool prepare_singleMarker( 270 drawinglayer::primitive2d::Primitive2DContainer& rMarkerPrimitives, 271 basegfx::B2DHomMatrix& rMarkerTransform, 272 basegfx::B2DRange& rClipRange, 273 const SvgMarkerNode& rMarker) const; 274 void add_markers( 275 const basegfx::B2DPolyPolygon& rPath, 276 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 277 const basegfx::utils::PointIndexSet* pHelpPointIndices) const; 278 279 280 public: 281 /// local attribute scanner 282 void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent, 283 bool bCaseIndependent); 284 285 /// helper which does the necessary with a given path 286 void add_text( 287 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 288 drawinglayer::primitive2d::Primitive2DContainer const & rSource) const; 289 void add_path( 290 const basegfx::B2DPolyPolygon& rPath, 291 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 292 const basegfx::utils::PointIndexSet* pHelpPointIndices) const; 293 void add_postProcess( 294 drawinglayer::primitive2d::Primitive2DContainer& rTarget, 295 const drawinglayer::primitive2d::Primitive2DContainer& rSource, 296 const basegfx::B2DHomMatrix* pTransform) const; 297 298 /// helper to set mpCssStyleParent temporarily for CSS style hierarchies setCssStyleParent(const SvgStyleAttributes * pNew)299 void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; } getCssStyleParent() const300 const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; } 301 302 /// scan helpers 303 void readCssStyle(const OUString& rCandidate); 304 const SvgStyleAttributes* getParentStyle() const; 305 306 SvgStyleAttributes(SvgNode& rOwner); 307 ~SvgStyleAttributes(); 308 309 /// fill content 310 bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy) 311 const basegfx::BColor* getFill() const; setFill(const SvgPaint & rFill)312 void setFill(const SvgPaint& rFill) { maFill = rFill; } 313 314 /// stroke content 315 const basegfx::BColor* getStroke() const; 316 317 /// stop color content 318 const basegfx::BColor& getStopColor() const; 319 320 /// stroke-width content 321 SvgNumber getStrokeWidth() const; 322 323 /// stop opacity content 324 SvgNumber getStopOpacity() const; 325 326 /// access to evtl. set fill gradient 327 const SvgGradientNode* getSvgGradientNodeFill() const; 328 329 /// access to evtl. set fill pattern 330 const SvgPatternNode* getSvgPatternNodeFill() const; 331 332 /// access to evtl. set stroke gradient 333 const SvgGradientNode* getSvgGradientNodeStroke() const; 334 335 /// access to evtl. set stroke pattern 336 const SvgPatternNode* getSvgPatternNodeStroke() const; 337 338 /// fill opacity content 339 SvgNumber getFillOpacity() const; 340 341 /// fill rule content 342 FillRule getFillRule() const; 343 344 /// fill StrokeDasharray content 345 const SvgNumberVector& getStrokeDasharray() const; 346 347 /// StrokeDashOffset content 348 SvgNumber getStrokeDashOffset() const; 349 350 /// StrokeLinecap content 351 StrokeLinecap getStrokeLinecap() const; setStrokeLinecap(const StrokeLinecap aStrokeLinecap)352 void setStrokeLinecap(const StrokeLinecap aStrokeLinecap) { maStrokeLinecap = aStrokeLinecap; } 353 354 /// StrokeLinejoin content 355 StrokeLinejoin getStrokeLinejoin() const; setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin)356 void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin) { maStrokeLinejoin = aStrokeLinejoin; } 357 358 /// StrokeMiterLimit content 359 SvgNumber getStrokeMiterLimit() const; 360 361 /// StrokeOpacity content 362 SvgNumber getStrokeOpacity() const; 363 364 /// Font content 365 const SvgStringVector& getFontFamily() const; 366 367 /// FontSize content setFontSize(const FontSize aFontSize)368 void setFontSize(const FontSize aFontSize) { maFontSize = aFontSize; } 369 SvgNumber getFontSizeNumber() const; 370 371 /// FontStretch content 372 FontStretch getFontStretch() const; setFontStretch(const FontStretch aFontStretch)373 void setFontStretch(const FontStretch aFontStretch) { maFontStretch = aFontStretch; } 374 375 /// FontStyle content 376 FontStyle getFontStyle() const; setFontStyle(const FontStyle aFontStyle)377 void setFontStyle(const FontStyle aFontStyle) { maFontStyle = aFontStyle; } 378 379 /// FontWeight content 380 FontWeight getFontWeight() const; setFontWeight(const FontWeight aFontWeight)381 void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; } 382 383 /// TextAlign content 384 TextAlign getTextAlign() const; setTextAlign(const TextAlign aTextAlign)385 void setTextAlign(const TextAlign aTextAlign) { maTextAlign = aTextAlign; } 386 387 /// TextDecoration content 388 const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const; 389 TextDecoration getTextDecoration() const; setTextDecoration(const TextDecoration aTextDecoration)390 void setTextDecoration(const TextDecoration aTextDecoration) { maTextDecoration = aTextDecoration; } 391 392 /// TextAnchor content 393 TextAnchor getTextAnchor() const; setTextAnchor(const TextAnchor aTextAnchor)394 void setTextAnchor(const TextAnchor aTextAnchor) { maTextAnchor = aTextAnchor; } 395 396 /// Color content 397 const basegfx::BColor* getColor() const; 398 399 /// Resolve current color (defaults to black if no color is specified) 400 const basegfx::BColor* getCurrentColor() const; 401 402 /// Opacity content 403 SvgNumber getOpacity() const; setOpacity(const SvgNumber & rOpacity)404 void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; } 405 406 /// Visibility 407 Visibility getVisibility() const; setVisibility(const Visibility aVisibility)408 void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; } 409 410 // Title content getTitle() const411 const OUString& getTitle() const { return maTitle; } 412 413 // Desc content getDesc() const414 const OUString& getDesc() const { return maDesc; } 415 416 // ClipPathXLink content 417 OUString const & getClipPathXLink() const; 418 const SvgClipPathNode* accessClipPathXLink() const; 419 420 // MaskXLink content 421 OUString getMaskXLink() const; 422 const SvgMaskNode* accessMaskXLink() const; 423 424 // MarkerStartXLink content 425 OUString getMarkerStartXLink() const; 426 const SvgMarkerNode* accessMarkerStartXLink() const; 427 428 // MarkerMidXLink content 429 OUString getMarkerMidXLink() const; 430 const SvgMarkerNode* accessMarkerMidXLink() const; 431 432 // MarkerEndXLink content 433 OUString getMarkerEndXLink() const; 434 const SvgMarkerNode* accessMarkerEndXLink() const; 435 436 // BaselineShift setBaselineShift(const BaselineShift aBaselineShift)437 void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; } getBaselineShift() const438 BaselineShift getBaselineShift() const { return maBaselineShift; } 439 SvgNumber getBaselineShiftNumber() const; 440 }; 441 } // end of namespace svgreader 442 } // end of namespace svgio 443 444 #endif // INCLUDED_SVGIO_INC_SVGSTYLEATTRIBUTES_HXX 445 446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 447