1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_SVGTOOLS_HXX
21 #define INCLUDED_SVGIO_INC_SVGTOOLS_HXX
23 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
24 #include <basegfx/color/bcolor.hxx>
25 #include <basegfx/polygon/b2dpolypolygon.hxx>
26 #include "svgpaint.hxx"
34 // recommended value for this device dependent unit, see CSS2 section 4.3.2 Lengths
35 #define F_SVG_PIXEL_PER_INCH 96.0
37 // common non-token strings
40 static const OUString aStrUserSpaceOnUse
;
41 static const OUString aStrObjectBoundingBox
;
42 static const OUString aStrNonzero
;
43 static const OUString aStrEvenOdd
;
62 virtual ~InfoProvider() {}
63 virtual const basegfx::B2DRange
getCurrentViewPort() const = 0;
64 /// return font size of node inherited from parents
65 virtual double getCurrentFontSizeInherited() const = 0;
66 /// return xheight of node inherited from parents
67 virtual double getCurrentXHeightInherited() const = 0;
72 Unit_em
= 0, // relative to current font size
73 Unit_ex
, // relative to current x-height
75 Unit_px
, // 'user unit'
76 Unit_pt
, // points, 1.25 px
78 Unit_cm
, // 35.43307 px
79 Unit_mm
, // 3.543307 px
82 Unit_percent
, // relative to range
83 Unit_none
// for stroke-miterlimit, which has no unit
102 SvgNumber(double fNum
, SvgUnit aSvgUnit
= Unit_px
, bool bSet
= true)
109 double getNumber() const
114 SvgUnit
getUnit() const
124 bool isPositive() const;
126 // Only usable in cases, when the unit is not Unit_percent, otherwise use method solve
127 double solveNonPercentage(const InfoProvider
& rInfoProvider
) const;
129 double solve(const InfoProvider
& rInfoProvider
, NumberType aNumberType
= length
) const;
134 typedef ::std::vector
< SvgNumber
> SvgNumberVector
;
143 Align_xMidYMid
, // default
155 bool mbMeetOrSlice
: 1; // true = meet (default), false = slice
160 : maSvgAlign(Align_xMidYMid
),
166 SvgAspectRatio(SvgAlign aSvgAlign
, bool bMeetOrSlice
)
167 : maSvgAlign(aSvgAlign
),
168 mbMeetOrSlice(bMeetOrSlice
),
174 SvgAlign
getSvgAlign() const { return maSvgAlign
; }
175 bool isMeetOrSlice() const { return mbMeetOrSlice
; }
176 bool isSet() const { return mbSet
; }
179 static basegfx::B2DHomMatrix
createLinearMapping(const basegfx::B2DRange
& rTarget
, const basegfx::B2DRange
& rSource
);
180 basegfx::B2DHomMatrix
createMapping(const basegfx::B2DRange
& rTarget
, const basegfx::B2DRange
& rSource
) const;
183 void skip_char(const OUString
& rCandidate
, sal_Unicode aChar
, sal_Int32
& nPos
, const sal_Int32 nLen
);
184 void skip_char(const OUString
& rCandidate
, sal_Unicode aCharA
, sal_Unicode nCharB
, sal_Int32
& nPos
, const sal_Int32 nLen
);
185 void copySign(const OUString
& rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
186 void copyNumber(const OUString
& rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
187 void copyHex(const OUString
& rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
188 void copyString(const OUString
& rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
189 void copyToLimiter(const OUString
& rCandidate
, sal_Unicode aLimiter
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
190 bool readNumber(const OUString
& rCandidate
, sal_Int32
& nPos
, double& fNum
, const sal_Int32 nLen
);
191 SvgUnit
readUnit(const OUString
& rCandidate
, sal_Int32
& nPos
, const sal_Int32 nLen
);
192 bool readNumberAndUnit(const OUString
& rCandidate
, sal_Int32
& nPos
, SvgNumber
& aNum
, const sal_Int32 nLen
);
193 bool readAngle(const OUString
& rCandidate
, sal_Int32
& nPos
, double& fAngle
, const sal_Int32 nLen
);
194 sal_Int32
read_hex(sal_Unicode aChar
);
195 bool match_colorKeyword(basegfx::BColor
& rColor
, const OUString
& rName
, bool bCaseIndependent
);
196 bool read_color(const OUString
& rCandidate
, basegfx::BColor
& rColor
, bool bCaseIndependent
, SvgNumber
& rOpacity
);
197 basegfx::B2DRange
readViewBox(const OUString
& rCandidate
, InfoProvider
const & rInfoProvider
);
198 basegfx::B2DHomMatrix
readTransform(const OUString
& rCandidate
, InfoProvider
const & rInfoProvider
);
199 bool readSingleNumber(const OUString
& rCandidate
, SvgNumber
& aNum
);
200 bool readLocalUrl(const OUString
& rCandidate
, OUString
& rURL
);
201 bool readSvgPaint(const OUString
& rCandidate
, SvgPaint
& rSvgPaint
, OUString
& rURL
, bool bCaseIndependent
, SvgNumber
& rOpacity
);
203 bool readSvgNumberVector(const OUString
& rCandidate
, SvgNumberVector
& rSvgNumberVector
);
204 ::std::vector
< double > solveSvgNumberVector(const SvgNumberVector
& rInput
, const InfoProvider
& rInfoProvider
);
206 SvgAspectRatio
readSvgAspectRatio(const OUString
& rCandidate
);
208 typedef ::std::vector
< OUString
> SvgStringVector
;
209 bool readSvgStringVector(const OUString
& rCandidate
, SvgStringVector
& rSvgStringVector
);
211 void readImageLink(const OUString
& rCandidate
, OUString
& rXLink
, OUString
& rUrl
, OUString
& rMimeType
, OUString
& rData
);
213 OUString
convert(const OUString
& rCandidate
, sal_Unicode nPattern
, sal_Unicode nNew
, bool bRemove
);
214 OUString
consolidateContiguousSpace(const OUString
& rCandidate
);
215 OUString
whiteSpaceHandlingDefault(const OUString
& rCandidate
);
216 OUString
whiteSpaceHandlingPreserve(const OUString
& rCandidate
);
218 // #125325# removes block comment of the general form '/* ... */', returns
219 // an adapted string or the original if no comments included
220 OUString
removeBlockComments(const OUString
& rCandidate
);
222 } // end of namespace svgreader
223 } // end of namespace svgio
225 #endif // INCLUDED_SVGIO_INC_SVGTOOLS_HXX
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */