Update git submodules
[LibreOffice.git] / svgio / inc / svgtools.hxx
blobdfeb12d9ea4961ae492231d0ca8d91f9f3b8e1fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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>
30 #include <vector>
33 namespace svgio::svgreader
35 // common non-token strings
36 struct commonStrings
38 static constexpr OUString aStrUserSpaceOnUse = u"userSpaceOnUse"_ustr;
39 static constexpr OUString aStrObjectBoundingBox = u"objectBoundingBox"_ustr;
40 static constexpr OUString aStrNonzero = u"nonzero"_ustr;
41 static constexpr OUString aStrEvenOdd = u"evenodd"_ustr;
44 enum class SvgUnits
46 userSpaceOnUse,
47 objectBoundingBox
50 enum class SvgAlign
52 none,
53 xMinYMin,
54 xMidYMin,
55 xMaxYMin,
56 xMinYMid,
57 xMidYMid, // default
58 xMaxYMid,
59 xMinYMax,
60 xMidYMax,
61 xMaxYMax
64 class SvgAspectRatio
66 private:
67 SvgAlign maSvgAlign;
69 bool mbMeetOrSlice : 1; // true = meet (default), false = slice
70 bool mbSet : 1;
72 public:
73 SvgAspectRatio()
74 : maSvgAlign(SvgAlign::xMidYMid),
75 mbMeetOrSlice(true),
76 mbSet(false)
80 SvgAspectRatio(SvgAlign aSvgAlign, bool bMeetOrSlice)
81 : maSvgAlign(aSvgAlign),
82 mbMeetOrSlice(bMeetOrSlice),
83 mbSet(true)
87 /// data read access
88 SvgAlign getSvgAlign() const { return maSvgAlign; }
89 bool isMeetOrSlice() const { return mbMeetOrSlice; }
90 bool isSet() const { return mbSet; }
92 /// tooling
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 std::vector<double> readFilterMatrix(std::u16string_view rCandidate, InfoProvider const & rInfoProvider);
113 basegfx::B2DHomMatrix readTransform(std::u16string_view rCandidate, InfoProvider const & rInfoProvider);
114 bool readSingleNumber(std::u16string_view rCandidate, SvgNumber& aNum);
115 bool readLocalLink(std::u16string_view rCandidate, OUString& rURL);
116 bool readLocalUrl(const OUString& rCandidate, OUString& rURL);
117 bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, SvgNumber& rOpacity);
119 bool readSvgNumberVector(std::u16string_view rCandidate, SvgNumberVector& rSvgNumberVector);
120 ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider);
122 SvgAspectRatio readSvgAspectRatio(std::u16string_view rCandidate);
124 typedef ::std::vector< OUString > SvgStringVector;
125 bool readSvgStringVector(std::u16string_view rCandidate, SvgStringVector& rSvgStringVector, sal_Unicode nSeparator);
127 void readImageLink(const OUString& rCandidate, OUString& rXLink, OUString& rUrl, OUString& rData);
129 OUString consolidateContiguousSpace(const OUString& rCandidate);
131 // #125325# removes block comment of the general form '/* ... */', returns
132 // an adapted string or the original if no comments included
133 OUString removeBlockComments(const OUString& rCandidate);
135 } // end of namespace svgio::svgreader
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */