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 .
22 #include <basegfx/color/bcolor.hxx>
23 #include <basegfx/range/b2drange.hxx>
24 #include <basegfx/vector/b2ivector.hxx>
25 #include <rtl/ustrbuf.hxx>
26 #include "svgpaint.hxx"
27 #include "SvgNumber.hxx"
29 #include <string_view>
33 namespace svgio::svgreader
35 // common non-token strings
38 static constexpr OUStringLiteral aStrUserSpaceOnUse
= u
"userSpaceOnUse";
39 static constexpr OUStringLiteral aStrObjectBoundingBox
= u
"objectBoundingBox";
40 static constexpr OUStringLiteral aStrNonzero
= u
"nonzero";
41 static constexpr OUStringLiteral aStrEvenOdd
= u
"evenodd";
69 bool mbMeetOrSlice
: 1; // true = meet (default), false = slice
74 : maSvgAlign(SvgAlign::xMidYMid
),
80 SvgAspectRatio(SvgAlign aSvgAlign
, bool bMeetOrSlice
)
81 : maSvgAlign(aSvgAlign
),
82 mbMeetOrSlice(bMeetOrSlice
),
88 SvgAlign
getSvgAlign() const { return maSvgAlign
; }
89 bool isMeetOrSlice() const { return mbMeetOrSlice
; }
90 bool isSet() const { return mbSet
; }
93 static basegfx::B2DHomMatrix
createLinearMapping(const basegfx::B2DRange
& rTarget
, const basegfx::B2DRange
& rSource
);
94 basegfx::B2DHomMatrix
createMapping(const basegfx::B2DRange
& rTarget
, const basegfx::B2DRange
& rSource
) const;
97 void skip_char(std::u16string_view rCandidate
, sal_Unicode aChar
, sal_Int32
& nPos
, const sal_Int32 nLen
);
98 void skip_char(std::u16string_view rCandidate
, sal_Unicode aCharA
, sal_Unicode nCharB
, sal_Int32
& nPos
, const sal_Int32 nLen
);
99 void copySign(std::u16string_view rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
100 void copyNumber(std::u16string_view rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
101 void copyHex(std::u16string_view rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
102 void copyString(std::u16string_view rCandidate
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
103 void copyToLimiter(std::u16string_view rCandidate
, sal_Unicode aLimiter
, sal_Int32
& nPos
, OUStringBuffer
& rTarget
, const sal_Int32 nLen
);
104 bool readNumber(std::u16string_view rCandidate
, sal_Int32
& nPos
, double& fNum
, const sal_Int32 nLen
);
105 SvgUnit
readUnit(std::u16string_view rCandidate
, sal_Int32
& nPos
, const sal_Int32 nLen
);
106 bool readNumberAndUnit(std::u16string_view rCandidate
, sal_Int32
& nPos
, SvgNumber
& aNum
, const sal_Int32 nLen
);
107 bool readAngle(std::u16string_view rCandidate
, sal_Int32
& nPos
, double& fAngle
, const sal_Int32 nLen
);
108 sal_Int32
read_hex(sal_Unicode aChar
);
109 bool match_colorKeyword(basegfx::BColor
& rColor
, const OUString
& rName
);
110 bool read_color(const OUString
& rCandidate
, basegfx::BColor
& rColor
, SvgNumber
& rOpacity
);
111 basegfx::B2DRange
readViewBox(std::u16string_view rCandidate
, InfoProvider
const & rInfoProvider
);
112 basegfx::B2DHomMatrix
readTransform(std::u16string_view rCandidate
, InfoProvider
const & rInfoProvider
);
113 bool readSingleNumber(std::u16string_view rCandidate
, SvgNumber
& aNum
);
114 bool readLocalLink(std::u16string_view rCandidate
, OUString
& rURL
);
115 bool readLocalUrl(const OUString
& rCandidate
, OUString
& rURL
);
116 bool readSvgPaint(const OUString
& rCandidate
, SvgPaint
& rSvgPaint
, OUString
& rURL
, SvgNumber
& rOpacity
);
118 bool readSvgNumberVector(std::u16string_view rCandidate
, SvgNumberVector
& rSvgNumberVector
);
119 ::std::vector
< double > solveSvgNumberVector(const SvgNumberVector
& rInput
, const InfoProvider
& rInfoProvider
);
121 SvgAspectRatio
readSvgAspectRatio(std::u16string_view rCandidate
);
123 typedef ::std::vector
< OUString
> SvgStringVector
;
124 bool readSvgStringVector(std::u16string_view rCandidate
, SvgStringVector
& rSvgStringVector
);
126 void readImageLink(const OUString
& rCandidate
, OUString
& rXLink
, OUString
& rUrl
, OUString
& rMimeType
, OUString
& rData
);
128 OUString
consolidateContiguousSpace(const OUString
& rCandidate
);
130 // #125325# removes block comment of the general form '/* ... */', returns
131 // an adapted string or the original if no comments included
132 OUString
removeBlockComments(const OUString
& rCandidate
);
134 } // end of namespace svgio::svgreader
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */