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