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