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_SVGTOOLS_HXX
21 : #define INCLUDED_SVGIO_SVGREADER_SVGTOOLS_HXX
22 :
23 : #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
24 : #include <basegfx/color/bcolor.hxx>
25 : #include <basegfx/polygon/b2dpolypolygon.hxx>
26 : #include <svgio/svgreader/svgpaint.hxx>
27 : #include <vector>
28 :
29 :
30 :
31 : namespace svgio
32 : {
33 : namespace svgreader
34 : {
35 : #ifdef DBG_UTIL
36 : // error helper
37 : void myAssert(const OUString& rMessage);
38 : #endif
39 :
40 : // recommended value for this devise dependend unit, see CSS2 section 4.3.2 Lengths
41 : #define F_SVG_PIXEL_PER_INCH 90.0
42 :
43 : // common non-token strings
44 : struct commonStrings
45 : {
46 : static const OUString aStrUserSpaceOnUse;
47 : static const OUString aStrObjectBoundingBox;
48 : static const OUString aStrNonzero;
49 : static const OUString aStrEvenOdd;
50 : };
51 :
52 : enum SvgUnits
53 : {
54 : userSpaceOnUse,
55 : objectBoundingBox
56 : };
57 :
58 : enum NumberType
59 : {
60 : xcoordinate,
61 : ycoordinate,
62 : length
63 : };
64 :
65 0 : class InfoProvider
66 : {
67 : public:
68 0 : virtual ~InfoProvider() {}
69 : virtual const basegfx::B2DRange getCurrentViewPort() const = 0;
70 : /// return font size of node inherited from parents
71 : virtual double getCurrentFontSizeInherited() const = 0;
72 : /// return xheight of node inherited from parents
73 : virtual double getCurrentXHeightInherited() const = 0;
74 : };
75 :
76 : enum SvgUnit
77 : {
78 : Unit_em = 0, // relative to current font size
79 : Unit_ex, // relative to current x-height
80 :
81 : Unit_px, // 'user unit'
82 : Unit_pt, // points, 1.25 px
83 : Unit_pc, // 15.0 px
84 : Unit_cm, // 35.43307 px
85 : Unit_mm, // 3.543307 px
86 : Unit_in, // 90 px
87 :
88 : Unit_percent // relative to range
89 : };
90 :
91 : class SvgNumber
92 : {
93 : private:
94 : double mfNumber;
95 : SvgUnit meUnit;
96 :
97 : /// bitfield
98 : bool mbSet : 1;
99 :
100 : public:
101 0 : SvgNumber()
102 : : mfNumber(0.0),
103 : meUnit(Unit_px),
104 0 : mbSet(false)
105 : {
106 0 : }
107 :
108 0 : SvgNumber(double fNum, SvgUnit aSvgUnit = Unit_px, bool bSet = true)
109 : : mfNumber(fNum),
110 : meUnit(aSvgUnit),
111 0 : mbSet(bSet)
112 : {
113 0 : }
114 :
115 0 : double getNumber() const
116 : {
117 0 : return mfNumber;
118 : }
119 :
120 0 : SvgUnit getUnit() const
121 : {
122 0 : return meUnit;
123 : }
124 :
125 0 : bool isSet() const
126 : {
127 0 : return mbSet;
128 : }
129 :
130 : bool isPositive() const;
131 :
132 : // Only usable in cases, when the unit is not Unit_percent, otherwise use method solve
133 : double solveNonPercentage(const InfoProvider& rInfoProvider) const;
134 :
135 : double solve(const InfoProvider& rInfoProvider, NumberType aNumberType = length) const;
136 :
137 :
138 : };
139 :
140 : typedef ::std::vector< SvgNumber > SvgNumberVector;
141 :
142 : enum SvgAlign
143 : {
144 : Align_none,
145 : Align_xMinYMin,
146 : Align_xMidYMin,
147 : Align_xMaxYMin,
148 : Align_xMinYMid,
149 : Align_xMidYMid, // default
150 : Align_xMaxYMid,
151 : Align_xMinYMax,
152 : Align_xMidYMax,
153 : Align_xMaxYMax
154 : };
155 :
156 : class SvgAspectRatio
157 : {
158 : private:
159 : SvgAlign maSvgAlign;
160 :
161 : /// bitfield
162 : bool mbDefer : 1; // default is false
163 : bool mbMeetOrSlice : 1; // true = meet (default), false = slice
164 : bool mbSet : 1;
165 :
166 : public:
167 0 : SvgAspectRatio()
168 : : maSvgAlign(Align_xMidYMid),
169 : mbDefer(false),
170 : mbMeetOrSlice(true),
171 0 : mbSet(false)
172 : {
173 0 : }
174 :
175 0 : SvgAspectRatio(SvgAlign aSvgAlign, bool bDefer, bool bMeetOrSlice)
176 : : maSvgAlign(aSvgAlign),
177 : mbDefer(bDefer),
178 : mbMeetOrSlice(bMeetOrSlice),
179 0 : mbSet(true)
180 : {
181 0 : }
182 :
183 : /// data read access
184 0 : SvgAlign getSvgAlign() const { return maSvgAlign; }
185 : bool isDefer() const { return mbDefer; }
186 0 : bool isMeetOrSlice() const { return mbMeetOrSlice; }
187 0 : bool isSet() const { return mbSet; }
188 :
189 : /// tooling
190 : static basegfx::B2DHomMatrix createLinearMapping(const basegfx::B2DRange& rTarget, const basegfx::B2DRange& rSource);
191 : basegfx::B2DHomMatrix createMapping(const basegfx::B2DRange& rTarget, const basegfx::B2DRange& rSource) const;
192 : };
193 :
194 : void skip_char(const OUString& rCandidate, const sal_Unicode& rChar, sal_Int32& nPos, const sal_Int32 nLen);
195 : void skip_char(const OUString& rCandidate, const sal_Unicode& rCharA, const sal_Unicode& rCharB, sal_Int32& nPos, const sal_Int32 nLen);
196 : void copySign(const OUString& rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
197 : void copyNumber(const OUString& rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
198 : void copyHex(const OUString& rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
199 : void copyString(const OUString& rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
200 : void copyToLimiter(const OUString& rCandidate, const sal_Unicode& rLimiter, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen);
201 : bool readNumber(const OUString& rCandidate, sal_Int32& nPos, double& fNum, const sal_Int32 nLen);
202 : SvgUnit readUnit(const OUString& rCandidate, sal_Int32& nPos, const sal_Int32 nLen);
203 : bool readNumberAndUnit(const OUString& rCandidate, sal_Int32& nPos, SvgNumber& aNum, const sal_Int32 nLen);
204 : bool readAngle(const OUString& rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen);
205 : sal_Int32 read_hex(const sal_Unicode& rChar);
206 : bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName);
207 : bool read_color(const OUString& rCandidate, basegfx::BColor& rColor);
208 : basegfx::B2DRange readViewBox(const OUString& rCandidate, InfoProvider& rInfoProvider);
209 : basegfx::B2DHomMatrix readTransform(const OUString& rCandidate, InfoProvider& rInfoProvider);
210 : bool readSingleNumber(const OUString& rCandidate, SvgNumber& aNum);
211 : bool readLocalUrl(const OUString& rCandidate, OUString& rURL);
212 : bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL);
213 :
214 : bool readSvgNumberVector(const OUString& rCandidate, SvgNumberVector& rSvgNumberVector);
215 : ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider, NumberType aNumberType = length);
216 :
217 : SvgAspectRatio readSvgAspectRatio(const OUString& rCandidate);
218 :
219 : typedef ::std::vector< OUString > SvgStringVector;
220 : bool readSvgStringVector(const OUString& rCandidate, SvgStringVector& rSvgStringVector);
221 :
222 : void readImageLink(const OUString& rCandidate, OUString& rXLink, OUString& rUrl, OUString& rMimeType, OUString& rData);
223 :
224 : OUString convert(const OUString& rCandidate, const sal_Unicode& rPattern, const sal_Unicode& rNew, bool bRemove);
225 : OUString consolidateContiguosSpace(const OUString& rCandidate);
226 : OUString whiteSpaceHandlingDefault(const OUString& rCandidate);
227 : OUString whiteSpaceHandlingPreserve(const OUString& rCandidate);
228 :
229 : } // end of namespace svgreader
230 : } // end of namespace svgio
231 :
232 :
233 :
234 : #endif //INCLUDED_SVGIO_SVGREADER_SVGTOOLS_HXX
235 :
236 : // eof
237 :
238 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|