Line data Source code
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_SVGREADER_SVGSTYLEATTRIBUTES_HXX
21 : #define INCLUDED_SVGIO_SVGREADER_SVGSTYLEATTRIBUTES_HXX
22 :
23 : #include <svgio/svgreader/svgpaint.hxx>
24 : #include <svgio/svgreader/svgnode.hxx>
25 : #include <vcl/vclenum.hxx>
26 :
27 : //////////////////////////////////////////////////////////////////////////////
28 : // predefines
29 :
30 : namespace svgio { namespace svgreader {
31 : class SvgGradientNode;
32 : class SvgPatternNode;
33 : class SvgMarkerNode;
34 : }}
35 :
36 : //////////////////////////////////////////////////////////////////////////////
37 :
38 : namespace svgio
39 : {
40 : namespace svgreader
41 : {
42 : enum StrokeLinecap
43 : {
44 : StrokeLinecap_notset,
45 : StrokeLinecap_butt,
46 : StrokeLinecap_round,
47 : StrokeLinecap_square
48 : };
49 :
50 : enum StrokeLinejoin
51 : {
52 : StrokeLinejoin_notset,
53 : StrokeLinejoin_miter,
54 : StrokeLinejoin_round,
55 : StrokeLinejoin_bevel
56 : };
57 :
58 : enum FontStretch
59 : {
60 : FontStretch_notset,
61 : FontStretch_normal,
62 : FontStretch_wider,
63 : FontStretch_narrower,
64 : FontStretch_ultra_condensed,
65 : FontStretch_extra_condensed,
66 : FontStretch_condensed,
67 : FontStretch_semi_condensed,
68 : FontStretch_semi_expanded,
69 : FontStretch_expanded,
70 : FontStretch_extra_expanded,
71 : FontStretch_ultra_expanded
72 : };
73 :
74 : FontStretch getWider(FontStretch aSource);
75 : FontStretch getNarrower(FontStretch aSource);
76 :
77 : enum FontStyle
78 : {
79 : FontStyle_notset,
80 : FontStyle_normal,
81 : FontStyle_italic,
82 : FontStyle_oblique
83 : };
84 :
85 : enum FontVariant
86 : {
87 : FontVariant_notset,
88 : FontVariant_normal,
89 : FontVariant_small_caps
90 : };
91 :
92 : enum FontWeight
93 : {
94 : FontWeight_notset,
95 : FontWeight_100,
96 : FontWeight_200,
97 : FontWeight_300,
98 : FontWeight_400, // same as FontWeight_normal
99 : FontWeight_500,
100 : FontWeight_600,
101 : FontWeight_700, // same as FontWeight_bold
102 : FontWeight_800,
103 : FontWeight_900,
104 : FontWeight_bolder,
105 : FontWeight_lighter,
106 : };
107 :
108 : FontWeight getBolder(FontWeight aSource);
109 : FontWeight getLighter(FontWeight aSource);
110 : ::FontWeight getVclFontWeight(FontWeight aSource);
111 :
112 : enum TextAlign
113 : {
114 : TextAlign_notset,
115 : TextAlign_left,
116 : TextAlign_right,
117 : TextAlign_center,
118 : TextAlign_justify
119 : };
120 :
121 : enum TextDecoration
122 : {
123 : TextDecoration_notset,
124 : TextDecoration_none,
125 : TextDecoration_underline,
126 : TextDecoration_overline,
127 : TextDecoration_line_through,
128 : TextDecoration_blink
129 : };
130 :
131 : enum TextAnchor
132 : {
133 : TextAnchor_notset,
134 : TextAnchor_start,
135 : TextAnchor_middle,
136 : TextAnchor_end
137 : };
138 :
139 : enum FillRule
140 : {
141 : FillRule_notset,
142 : FillRule_nonzero,
143 : FillRule_evenodd
144 : };
145 :
146 : enum BaselineShift
147 : {
148 : BaselineShift_Baseline,
149 : BaselineShift_Sub,
150 : BaselineShift_Super,
151 : BaselineShift_Percentage,
152 : BaselineShift_Length
153 : };
154 :
155 : class SvgStyleAttributes
156 : {
157 : private:
158 : SvgNode& mrOwner;
159 : const SvgStyleAttributes* mpCssStyleParent;
160 : SvgPaint maFill;
161 : SvgPaint maStroke;
162 : SvgPaint maStopColor;
163 : SvgNumber maStrokeWidth;
164 : SvgNumber maStopOpacity;
165 : const SvgGradientNode* mpSvgGradientNodeFill;
166 : const SvgGradientNode* mpSvgGradientNodeStroke;
167 : const SvgPatternNode* mpSvgPatternNodeFill;
168 : const SvgPatternNode* mpSvgPatternNodeStroke;
169 : SvgNumber maFillOpacity;
170 : SvgNumberVector maStrokeDasharray;
171 : SvgNumber maStrokeDashOffset;
172 : StrokeLinecap maStrokeLinecap;
173 : StrokeLinejoin maStrokeLinejoin;
174 : SvgNumber maStrokeMiterLimit;
175 : SvgNumber maStrokeOpacity;
176 : SvgStringVector maFontFamily;
177 : SvgNumber maFontSize;
178 : FontStretch maFontStretch;
179 : FontStyle maFontStyle;
180 : FontVariant maFontVariant;
181 : FontWeight maFontWeight;
182 : TextAlign maTextAlign;
183 : TextDecoration maTextDecoration;
184 : TextAnchor maTextAnchor;
185 : SvgPaint maColor;
186 : SvgNumber maOpacity;
187 : OUString maTitle;
188 : OUString maDesc;
189 :
190 : /// link to content. If set, the node can be fetched on demand
191 : OUString maClipPathXLink;
192 : OUString maMaskXLink;
193 :
194 : /// link to markers. If set, the node can be fetched on demand
195 : OUString maMarkerStartXLink;
196 : const SvgMarkerNode* mpMarkerStartXLink;
197 : OUString maMarkerMidXLink;
198 : const SvgMarkerNode* mpMarkerMidXLink;
199 : OUString maMarkerEndXLink;
200 : const SvgMarkerNode* mpMarkerEndXLink;
201 :
202 : /// fill rule
203 : FillRule maFillRule;
204 :
205 : // ClipRule setting (only valid wne mbIsClipPathContent == true, default is FillRule_nonzero)
206 : FillRule maClipRule;
207 :
208 : // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length)
209 : BaselineShift maBaselineShift;
210 : SvgNumber maBaselineShiftNumber;
211 :
212 : /// bitfield
213 :
214 : // defines if this attributes are part of a ClipPath. If yes,
215 : // rough geometry will be created on decomposition by patching
216 : // vaules for fill, stroke, strokeWidth and others
217 : bool mbIsClipPathContent : 1;
218 :
219 : // #121221# Defines if evtl. an empty array *is* set
220 : bool mbStrokeDasharraySet : 1;
221 :
222 : /// internal helpers
223 : void add_fillGradient(
224 : const basegfx::B2DPolyPolygon& rPath,
225 : drawinglayer::primitive2d::Primitive2DSequence& rTarget,
226 : const SvgGradientNode& rFillGradient,
227 : const basegfx::B2DRange& rGeoRange) const;
228 : void add_fillPatternTransform(
229 : const basegfx::B2DPolyPolygon& rPath,
230 : drawinglayer::primitive2d::Primitive2DSequence& rTarget,
231 : const SvgPatternNode& rFillGradient,
232 : const basegfx::B2DRange& rGeoRange) const;
233 : void add_fillPattern(
234 : const basegfx::B2DPolyPolygon& rPath,
235 : drawinglayer::primitive2d::Primitive2DSequence& rTarget,
236 : const SvgPatternNode& rFillGradient,
237 : const basegfx::B2DRange& rGeoRange) const;
238 : void add_fill(
239 : const basegfx::B2DPolyPolygon& rPath,
240 : drawinglayer::primitive2d::Primitive2DSequence& rTarget,
241 : const basegfx::B2DRange& rGeoRange) const;
242 : void add_stroke(
243 : const basegfx::B2DPolyPolygon& rPath,
244 : drawinglayer::primitive2d::Primitive2DSequence& rTarget,
245 : const basegfx::B2DRange& rGeoRange) const;
246 : bool prepare_singleMarker(
247 : drawinglayer::primitive2d::Primitive2DSequence& rMarkerPrimitives,
248 : basegfx::B2DHomMatrix& rMarkerTransform,
249 : basegfx::B2DRange& rClipRange,
250 : const SvgMarkerNode& rMarker) const;
251 : void add_singleMarker(
252 : drawinglayer::primitive2d::Primitive2DSequence& rTarget,
253 : const drawinglayer::primitive2d::Primitive2DSequence& rMarkerPrimitives,
254 : const basegfx::B2DHomMatrix& rMarkerTransform,
255 : const basegfx::B2DRange& rClipRange,
256 : const SvgMarkerNode& rMarker,
257 : const basegfx::B2DPolygon& rCandidate,
258 : const sal_uInt32 nIndex) const;
259 : void add_markers(
260 : const basegfx::B2DPolyPolygon& rPath,
261 : drawinglayer::primitive2d::Primitive2DSequence& rTarget) const;
262 :
263 : public:
264 : /// local attribute scanner
265 : void parseStyleAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent);
266 :
267 : /// helper which does the necessary with a given path
268 : void add_text(
269 : drawinglayer::primitive2d::Primitive2DSequence& rTarget,
270 : drawinglayer::primitive2d::Primitive2DSequence& rSource) const;
271 : void add_path(
272 : const basegfx::B2DPolyPolygon& rPath,
273 : drawinglayer::primitive2d::Primitive2DSequence& rTarget) const;
274 : void add_postProcess(
275 : drawinglayer::primitive2d::Primitive2DSequence& rTarget,
276 : const drawinglayer::primitive2d::Primitive2DSequence& rSource,
277 : const basegfx::B2DHomMatrix* pTransform) const;
278 :
279 : /// helper to set mpCssStyleParent temporarily for CSS style hierarchies
280 0 : void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; }
281 127152 : const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; }
282 :
283 : /// scan helpers
284 : void readStyle(const OUString& rCandidate);
285 : const SvgStyleAttributes* getParentStyle() const;
286 :
287 : SvgStyleAttributes(SvgNode& rOwner);
288 : ~SvgStyleAttributes();
289 :
290 : /// fill content
291 : const basegfx::BColor* getFill() const;
292 1870 : void setFill(const SvgPaint& rFill) { maFill = rFill; }
293 :
294 : /// stroke content
295 : const basegfx::BColor* getStroke() const;
296 226 : void setStroke(const SvgPaint& rStroke) { maStroke = rStroke; }
297 :
298 : /// stop color content
299 : const basegfx::BColor& getStopColor() const;
300 3433 : void setStopColor(const SvgPaint& rStopColor) { maStopColor = rStopColor; }
301 :
302 : /// stroke-width content
303 : SvgNumber getStrokeWidth() const;
304 212 : void setStrokeWidth(const SvgNumber& rStrokeWidth = SvgNumber()) { maStrokeWidth = rStrokeWidth; }
305 :
306 : /// stop opacity content
307 : SvgNumber getStopOpacity() const;
308 0 : void setStopOpacity(const SvgNumber& rStopOpacity = SvgNumber()) { maStopOpacity = rStopOpacity; }
309 :
310 : /// access to evtl. set fill gradient
311 : const SvgGradientNode* getSvgGradientNodeFill() const;
312 1283 : void setSvgGradientNodeFill(const SvgGradientNode* pNew) { mpSvgGradientNodeFill = pNew; }
313 :
314 : /// access to evtl. set fill pattern
315 : const SvgPatternNode* getSvgPatternNodeFill() const;
316 0 : void setSvgPatternNodeFill(const SvgPatternNode* pNew) { mpSvgPatternNodeFill = pNew; }
317 :
318 : /// access to evtl. set stroke gradient
319 : const SvgGradientNode* getSvgGradientNodeStroke() const;
320 0 : void setSvgGradientNodeStroke(const SvgGradientNode* pNew) { mpSvgGradientNodeStroke = pNew; }
321 :
322 : /// access to evtl. set stroke pattern
323 : const SvgPatternNode* getSvgPatternNodeStroke() const;
324 0 : void setSvgPatternNodeStroke(const SvgPatternNode* pNew) { mpSvgPatternNodeStroke = pNew; }
325 :
326 : /// fill opacity content
327 : SvgNumber getFillOpacity() const;
328 1 : void setFillOpacity(const SvgNumber& rFillOpacity = SvgNumber()) { maFillOpacity = rFillOpacity; }
329 :
330 : /// fill rule content
331 : FillRule getFillRule() const;
332 : void setFillRule(const FillRule aFillRule = FillRule_notset) { maFillRule = aFillRule; }
333 :
334 : /// fill StrokeDasharray content
335 : const SvgNumberVector& getStrokeDasharray() const;
336 15 : void setStrokeDasharray(const SvgNumberVector& rStrokeDasharray = SvgNumberVector()) { maStrokeDasharray = rStrokeDasharray; }
337 :
338 : /// #121221# StrokeDasharray needs a set state, it *may* be set to empty by purpose
339 712 : bool getStrokeDasharraySet() const { return mbStrokeDasharraySet; }
340 0 : void setStrokeDasharraySet(bool bNew) { mbStrokeDasharraySet = bNew; }
341 :
342 : /// StrokeDashOffset content
343 : SvgNumber getStrokeDashOffset() const;
344 0 : void setStrokeDashOffset(const SvgNumber& rStrokeDashOffset = SvgNumber()) { maStrokeDashOffset = rStrokeDashOffset; }
345 :
346 : /// StrokeLinecap content
347 : StrokeLinecap getStrokeLinecap() const;
348 38 : void setStrokeLinecap(const StrokeLinecap aStrokeLinecap = StrokeLinecap_notset) { maStrokeLinecap = aStrokeLinecap; }
349 :
350 : /// StrokeLinejoin content
351 : StrokeLinejoin getStrokeLinejoin() const;
352 30 : void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin = StrokeLinejoin_notset) { maStrokeLinejoin = aStrokeLinejoin; }
353 :
354 : /// StrokeMiterLimit content
355 : SvgNumber getStrokeMiterLimit() const;
356 0 : void setStrokeMiterLimit(const SvgNumber& rStrokeMiterLimit = SvgNumber()) { maStrokeMiterLimit = rStrokeMiterLimit; }
357 :
358 : /// StrokeOpacity content
359 : SvgNumber getStrokeOpacity() const;
360 0 : void setStrokeOpacity(const SvgNumber& rStrokeOpacity = SvgNumber()) { maStrokeOpacity = rStrokeOpacity; }
361 :
362 : /// Font content
363 : const SvgStringVector& getFontFamily() const;
364 0 : void setFontFamily(const SvgStringVector& rSvgStringVector = SvgStringVector()) { maFontFamily = rSvgStringVector; }
365 :
366 : /// FontSize content
367 : SvgNumber getFontSize() const;
368 0 : void setFontSize(const SvgNumber& rFontSize = SvgNumber()) { maFontSize = rFontSize; }
369 :
370 : /// FontStretch content
371 : FontStretch getFontStretch() const;
372 0 : void setFontStretch(const FontStretch aFontStretch = FontStretch_notset) { maFontStretch = aFontStretch; }
373 :
374 : /// FontStyle content
375 : FontStyle getFontStyle() const;
376 0 : void setFontStyle(const FontStyle aFontStyle = FontStyle_notset) { maFontStyle = aFontStyle; }
377 :
378 : /// FontVariant content
379 : FontVariant getFontVariant() const;
380 0 : void setFontVariant(const FontVariant aFontVariant = FontVariant_notset) { maFontVariant = aFontVariant; }
381 :
382 : /// FontWeight content
383 : FontWeight getFontWeight() const;
384 0 : void setFontWeight(const FontWeight aFontWeight = FontWeight_notset) { maFontWeight = aFontWeight; }
385 :
386 : /// TextAlign content
387 : TextAlign getTextAlign() const;
388 0 : void setTextAlign(const TextAlign aTextAlign = TextAlign_notset) { maTextAlign = aTextAlign; }
389 :
390 : /// TextDecoration content
391 : const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const;
392 : TextDecoration getTextDecoration() const;
393 0 : void setTextDecoration(const TextDecoration aTextDecoration = TextDecoration_notset) { maTextDecoration = aTextDecoration; }
394 :
395 : /// TextAnchor content
396 : TextAnchor getTextAnchor() const;
397 0 : void setTextAnchor(const TextAnchor aTextAnchor = TextAnchor_notset) { maTextAnchor = aTextAnchor; }
398 :
399 : /// Color content
400 : const basegfx::BColor* getColor() const;
401 0 : void setColor(const SvgPaint& rColor) { maColor = rColor; }
402 :
403 : /// Opacity content
404 10087 : SvgNumber getOpacity() const { return maOpacity; }
405 719 : void setOpacity(const SvgNumber& rOpacity = SvgNumber()) { maOpacity = rOpacity; }
406 :
407 : // Title content
408 2397 : const OUString& getTitle() const { return maTitle; }
409 0 : void setTitle(const OUString& rNew) { maTitle = rNew; }
410 :
411 : // Desc content
412 2397 : const OUString& getDesc() const { return maDesc; }
413 0 : void setDesc(const OUString& rNew) { maDesc = rNew; }
414 :
415 : // ClipPathXLink content
416 5144 : const OUString getClipPathXLink() const { return maClipPathXLink; }
417 : void setClipPathXLink(const OUString& rNew) { maClipPathXLink = rNew; }
418 :
419 : // MaskXLink content
420 5144 : const OUString getMaskXLink() const { return maMaskXLink; }
421 : void setMaskXLink(const OUString& rNew) { maMaskXLink = rNew; }
422 :
423 : // MarkerStartXLink content
424 : OUString getMarkerStartXLink() const;
425 : const SvgMarkerNode* accessMarkerStartXLink() const;
426 : void setMarkerStartXLink(const OUString& rNew) { maMarkerStartXLink = rNew; }
427 :
428 : // MarkerMidXLink content
429 : OUString getMarkerMidXLink() const;
430 : const SvgMarkerNode* accessMarkerMidXLink() const;
431 : void setMarkerMidXLink(const OUString& rNew) { maMarkerMidXLink = rNew; }
432 :
433 : // MarkerEndXLink content
434 : OUString getMarkerEndXLink() const;
435 : const SvgMarkerNode* accessMarkerEndXLink() const;
436 : void setMarkerEndXLink(const OUString& rNew) { maMarkerEndXLink = rNew; }
437 :
438 : // BaselineShift
439 0 : void setBaselineShift(const BaselineShift aBaselineShift = BaselineShift_Baseline) { maBaselineShift = aBaselineShift; }
440 0 : BaselineShift getBaselineShift() const { return maBaselineShift; }
441 0 : void setBaselineShiftNumber(const SvgNumber& rBaselineShift = SvgNumber()) { maBaselineShiftNumber = rBaselineShift; }
442 : SvgNumber getBaselineShiftNumber() const;
443 : };
444 : } // end of namespace svgreader
445 : } // end of namespace svgio
446 :
447 : //////////////////////////////////////////////////////////////////////////////
448 :
449 : #endif //INCLUDED_SVGIO_SVGREADER_SVGSTYLEATTRIBUTES_HXX
450 :
451 : // eof
452 :
453 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|