Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / svgio / inc / svgstyleattributes.hxx
blob3a3ac670b962249c435d19802f12d3aedd63ddef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVGIO_INC_SVGSTYLEATTRIBUTES_HXX
21 #define INCLUDED_SVGIO_INC_SVGSTYLEATTRIBUTES_HXX
23 #include "svgpaint.hxx"
24 #include "svgnode.hxx"
25 #include <vcl/vclenum.hxx>
26 #include <tools/fontenum.hxx>
27 #include <basegfx/polygon/b2dpolypolygontools.hxx>
30 // predefines
32 namespace svgio { namespace svgreader {
33 class SvgGradientNode;
34 class SvgPatternNode;
35 class SvgMarkerNode;
36 class SvgClipPathNode;
37 class SvgMaskNode;
41 namespace svgio
43 namespace svgreader
45 enum StrokeLinecap
47 StrokeLinecap_notset,
48 StrokeLinecap_butt,
49 StrokeLinecap_round,
50 StrokeLinecap_square
53 enum StrokeLinejoin
55 StrokeLinejoin_notset,
56 StrokeLinejoin_miter,
57 StrokeLinejoin_round,
58 StrokeLinejoin_bevel
61 enum FontSize
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
76 enum FontStretch
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
92 FontStretch getWider(FontStretch aSource);
93 FontStretch getNarrower(FontStretch aSource);
95 enum FontStyle
97 FontStyle_notset,
98 FontStyle_normal,
99 FontStyle_italic,
100 FontStyle_oblique
103 enum FontWeight
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,
119 FontWeight getBolder(FontWeight aSource);
120 FontWeight getLighter(FontWeight aSource);
121 ::FontWeight getVclFontWeight(FontWeight aSource);
123 enum TextAlign
125 TextAlign_notset,
126 TextAlign_left,
127 TextAlign_right,
128 TextAlign_center,
129 TextAlign_justify
132 enum TextDecoration
134 TextDecoration_notset,
135 TextDecoration_none,
136 TextDecoration_underline,
137 TextDecoration_overline,
138 TextDecoration_line_through,
139 TextDecoration_blink
142 enum TextAnchor
144 TextAnchor_notset,
145 TextAnchor_start,
146 TextAnchor_middle,
147 TextAnchor_end
150 enum FillRule
152 FillRule_notset,
153 FillRule_nonzero,
154 FillRule_evenodd
157 enum BaselineShift
159 BaselineShift_Baseline,
160 BaselineShift_Sub,
161 BaselineShift_Super,
162 BaselineShift_Percentage,
163 BaselineShift_Length
166 enum Visibility
168 Visibility_notset,
169 Visibility_visible,
170 Visibility_hidden,
171 Visibility_collapse,
172 Visibility_inherit
175 class SvgStyleAttributes
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;
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;
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;
221 /// fill rule
222 FillRule maFillRule;
224 // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero)
225 FillRule maClipRule;
227 // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
228 BaselineShift maBaselineShift;
229 SvgNumber maBaselineShiftNumber;
231 mutable std::vector<sal_uInt16> maResolvingParent;
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;
238 // #121221# Defines if evtl. an empty array *is* set
239 bool mbStrokeDasharraySet : 1;
241 // tdf#94765 Check id references in gradient/pattern getters
242 OUString maNodeFillURL;
243 OUString maNodeStrokeURL;
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;
280 public:
281 /// local attribute scanner
282 void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent,
283 bool bCaseIndependent);
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;
298 /// helper to set mpCssStyleParent temporarily for CSS style hierarchies
299 void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; }
300 const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; }
302 /// scan helpers
303 void readCssStyle(const OUString& rCandidate);
304 const SvgStyleAttributes* getParentStyle() const;
306 SvgStyleAttributes(SvgNode& rOwner);
307 ~SvgStyleAttributes();
309 /// fill content
310 bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy)
311 const basegfx::BColor* getFill() const;
312 void setFill(const SvgPaint& rFill) { maFill = rFill; }
314 /// stroke content
315 const basegfx::BColor* getStroke() const;
317 /// stop color content
318 const basegfx::BColor& getStopColor() const;
320 /// stroke-width content
321 SvgNumber getStrokeWidth() const;
323 /// stop opacity content
324 SvgNumber getStopOpacity() const;
326 /// access to evtl. set fill gradient
327 const SvgGradientNode* getSvgGradientNodeFill() const;
329 /// access to evtl. set fill pattern
330 const SvgPatternNode* getSvgPatternNodeFill() const;
332 /// access to evtl. set stroke gradient
333 const SvgGradientNode* getSvgGradientNodeStroke() const;
335 /// access to evtl. set stroke pattern
336 const SvgPatternNode* getSvgPatternNodeStroke() const;
338 /// fill opacity content
339 SvgNumber getFillOpacity() const;
341 /// fill rule content
342 FillRule getFillRule() const;
344 /// fill StrokeDasharray content
345 const SvgNumberVector& getStrokeDasharray() const;
347 /// StrokeDashOffset content
348 SvgNumber getStrokeDashOffset() const;
350 /// StrokeLinecap content
351 StrokeLinecap getStrokeLinecap() const;
352 void setStrokeLinecap(const StrokeLinecap aStrokeLinecap) { maStrokeLinecap = aStrokeLinecap; }
354 /// StrokeLinejoin content
355 StrokeLinejoin getStrokeLinejoin() const;
356 void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin) { maStrokeLinejoin = aStrokeLinejoin; }
358 /// StrokeMiterLimit content
359 SvgNumber getStrokeMiterLimit() const;
361 /// StrokeOpacity content
362 SvgNumber getStrokeOpacity() const;
364 /// Font content
365 const SvgStringVector& getFontFamily() const;
367 /// FontSize content
368 void setFontSize(const FontSize aFontSize) { maFontSize = aFontSize; }
369 SvgNumber getFontSizeNumber() const;
371 /// FontStretch content
372 FontStretch getFontStretch() const;
373 void setFontStretch(const FontStretch aFontStretch) { maFontStretch = aFontStretch; }
375 /// FontStyle content
376 FontStyle getFontStyle() const;
377 void setFontStyle(const FontStyle aFontStyle) { maFontStyle = aFontStyle; }
379 /// FontWeight content
380 FontWeight getFontWeight() const;
381 void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; }
383 /// TextAlign content
384 TextAlign getTextAlign() const;
385 void setTextAlign(const TextAlign aTextAlign) { maTextAlign = aTextAlign; }
387 /// TextDecoration content
388 const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const;
389 TextDecoration getTextDecoration() const;
390 void setTextDecoration(const TextDecoration aTextDecoration) { maTextDecoration = aTextDecoration; }
392 /// TextAnchor content
393 TextAnchor getTextAnchor() const;
394 void setTextAnchor(const TextAnchor aTextAnchor) { maTextAnchor = aTextAnchor; }
396 /// Color content
397 const basegfx::BColor* getColor() const;
399 /// Resolve current color (defaults to black if no color is specified)
400 const basegfx::BColor* getCurrentColor() const;
402 /// Opacity content
403 SvgNumber getOpacity() const;
404 void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; }
406 /// Visibility
407 Visibility getVisibility() const;
408 void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; }
410 // Title content
411 const OUString& getTitle() const { return maTitle; }
413 // Desc content
414 const OUString& getDesc() const { return maDesc; }
416 // ClipPathXLink content
417 OUString const & getClipPathXLink() const;
418 const SvgClipPathNode* accessClipPathXLink() const;
420 // MaskXLink content
421 OUString getMaskXLink() const;
422 const SvgMaskNode* accessMaskXLink() const;
424 // MarkerStartXLink content
425 OUString getMarkerStartXLink() const;
426 const SvgMarkerNode* accessMarkerStartXLink() const;
428 // MarkerMidXLink content
429 OUString getMarkerMidXLink() const;
430 const SvgMarkerNode* accessMarkerMidXLink() const;
432 // MarkerEndXLink content
433 OUString getMarkerEndXLink() const;
434 const SvgMarkerNode* accessMarkerEndXLink() const;
436 // BaselineShift
437 void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; }
438 BaselineShift getBaselineShift() const { return maBaselineShift; }
439 SvgNumber getBaselineShiftNumber() const;
441 } // end of namespace svgreader
442 } // end of namespace svgio
444 #endif // INCLUDED_SVGIO_INC_SVGSTYLEATTRIBUTES_HXX
446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */