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 <basegfx/color/bcolor.hxx>
24 #include <basegfx/range/b2drange.hxx>
25 #include <basegfx/vector/b2ivector.hxx>
26 #include <rtl/ustrbuf.hxx>
27 #include "svgpaint.hxx"
29 #include <string_view>
32 namespace svgio::svgreader
35 // recommended value for this device dependent unit, see CSS2 section 4.3.2 Lengths
36 #define F_SVG_PIXEL_PER_INCH 96.0
38 // common non-token strings
41 static constexpr OUStringLiteral aStrUserSpaceOnUse
= u
"userSpaceOnUse";
42 static constexpr OUStringLiteral aStrObjectBoundingBox
= u
"objectBoundingBox";
43 static constexpr OUStringLiteral aStrNonzero
= u
"nonzero";
44 static constexpr OUStringLiteral aStrEvenOdd
= u
"evenodd";
63 virtual ~InfoProvider() {}
64 virtual basegfx::B2DRange
getCurrentViewPort() const = 0;
65 /// return font size of node inherited from parents
66 virtual double getCurrentFontSizeInherited() const = 0;
67 /// return xheight of node inherited from parents
68 virtual double getCurrentXHeightInherited() const = 0;
73 Unit_em
= 0, // relative to current font size
74 Unit_ex
, // relative to current x-height
76 Unit_px
, // 'user unit'
77 Unit_pt
, // points, 1.25 px
79 Unit_cm
, // 35.43307 px
80 Unit_mm
, // 3.543307 px
83 Unit_percent
, // relative to range
84 Unit_none
// for stroke-miterlimit, which has no unit
103 SvgNumber(double fNum
, SvgUnit aSvgUnit
= Unit_px
, bool bSet
= true)
110 double getNumber() const
115 SvgUnit
getUnit() const
125 bool isPositive() const;
127 // Only usable in cases, when the unit is not Unit_percent, otherwise use method solve
128 double solveNonPercentage(const InfoProvider
& rInfoProvider
) const;
130 double solve(const InfoProvider
& rInfoProvider
, NumberType aNumberType
= length
) const;
135 typedef ::std::vector
< SvgNumber
> SvgNumberVector
;
144 Align_xMidYMid
, // default
156 bool mbMeetOrSlice
: 1; // true = meet (default), false = slice
161 : maSvgAlign(Align_xMidYMid
),
167 SvgAspectRatio(SvgAlign aSvgAlign
, bool bMeetOrSlice
)
168 : maSvgAlign(aSvgAlign
),
169 mbMeetOrSlice(bMeetOrSlice
),
175 SvgAlign
getSvgAlign() const { return maSvgAlign
; }
176 bool isMeetOrSlice() const { return mbMeetOrSlice
; }
177 bool isSet() const { return mbSet
; }
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;
184 void skip_char(std::u16string_view rCandidate
, sal_Unicode aChar
, sal_Int32
& nPos
, const sal_Int32 nLen
);
185 void skip_char(std::u16string_view rCandidate
, sal_Unicode aCharA
, sal_Unicode nCharB
, sal_Int32
& nPos
, const sal_Int32 nLen
);
186 void copySign(std::u16string_view rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
187 void copyNumber(std::u16string_view rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
188 void copyHex(std::u16string_view rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
189 void copyString(std::u16string_view rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
190 void copyToLimiter(std::u16string_view rCandidate
, sal_Unicode aLimiter
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
191 bool readNumber(std::u16string_view rCandidate
, sal_Int32
& nPos
, double& fNum
, const sal_Int32 nLen
);
192 SvgUnit
readUnit(std::u16string_view rCandidate
, sal_Int32
& nPos
, const sal_Int32 nLen
);
193 bool readNumberAndUnit(std::u16string_view rCandidate
, sal_Int32
& nPos
, SvgNumber
& aNum
, const sal_Int32 nLen
);
194 bool readAngle(const OUString
& rCandidate
, sal_Int32
& nPos
, double& fAngle
, const sal_Int32 nLen
);
195 sal_Int32
read_hex(sal_Unicode aChar
);
196 bool match_colorKeyword(basegfx::BColor
& rColor
, const OUString
& rName
, bool bCaseIndependent
);
197 bool read_color(const OUString
& rCandidate
, basegfx::BColor
& rColor
, bool bCaseIndependent
, SvgNumber
& rOpacity
);
198 basegfx::B2DRange
readViewBox(const OUString
& rCandidate
, InfoProvider
const & rInfoProvider
);
199 basegfx::B2DHomMatrix
readTransform(const OUString
& rCandidate
, InfoProvider
const & rInfoProvider
);
200 bool readSingleNumber(const OUString
& rCandidate
, SvgNumber
& aNum
);
201 bool readLocalUrl(const OUString
& rCandidate
, OUString
& rURL
);
202 bool readSvgPaint(const OUString
& rCandidate
, SvgPaint
& rSvgPaint
, OUString
& rURL
, bool bCaseIndependent
, SvgNumber
& rOpacity
);
204 bool readSvgNumberVector(const OUString
& rCandidate
, SvgNumberVector
& rSvgNumberVector
);
205 ::std::vector
< double > solveSvgNumberVector(const SvgNumberVector
& rInput
, const InfoProvider
& rInfoProvider
);
207 SvgAspectRatio
readSvgAspectRatio(const OUString
& rCandidate
);
209 typedef ::std::vector
< OUString
> SvgStringVector
;
210 bool readSvgStringVector(const OUString
& rCandidate
, SvgStringVector
& rSvgStringVector
);
212 void readImageLink(const OUString
& rCandidate
, OUString
& rXLink
, OUString
& rUrl
, OUString
& rMimeType
, OUString
& rData
);
214 OUString
convert(const OUString
& rCandidate
, sal_Unicode nPattern
, sal_Unicode nNew
, bool bRemove
);
215 OUString
consolidateContiguousSpace(const OUString
& rCandidate
);
216 OUString
whiteSpaceHandlingDefault(const OUString
& rCandidate
);
217 OUString
whiteSpaceHandlingPreserve(const OUString
& rCandidate
);
219 // #125325# removes block comment of the general form '/* ... */', returns
220 // an adapted string or the original if no comments included
221 OUString
removeBlockComments(const OUString
& rCandidate
);
223 } // end of namespace svgio::svgreader
225 #endif // INCLUDED_SVGIO_INC_SVGTOOLS_HXX
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */