/src/libreoffice/svgio/inc/svgtools.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
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" |
28 | | |
29 | | #include <string_view> |
30 | | #include <vector> |
31 | | |
32 | | |
33 | | namespace svgio::svgreader |
34 | | { |
35 | | // common non-token strings |
36 | | struct commonStrings |
37 | | { |
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; |
42 | | }; |
43 | | |
44 | | enum class SvgUnits |
45 | | { |
46 | | userSpaceOnUse, |
47 | | objectBoundingBox |
48 | | }; |
49 | | |
50 | | enum class SvgAlign |
51 | | { |
52 | | none, |
53 | | xMinYMin, |
54 | | xMidYMin, |
55 | | xMaxYMin, |
56 | | xMinYMid, |
57 | | xMidYMid, // default |
58 | | xMaxYMid, |
59 | | xMinYMax, |
60 | | xMidYMax, |
61 | | xMaxYMax |
62 | | }; |
63 | | |
64 | | class SvgAspectRatio |
65 | | { |
66 | | private: |
67 | | SvgAlign maSvgAlign; |
68 | | |
69 | | bool mbMeetOrSlice : 1; // true = meet (default), false = slice |
70 | | bool mbSet : 1; |
71 | | |
72 | | public: |
73 | | SvgAspectRatio() |
74 | 18.4k | : maSvgAlign(SvgAlign::xMidYMid), |
75 | 18.4k | mbMeetOrSlice(true), |
76 | 18.4k | mbSet(false) |
77 | 18.4k | { |
78 | 18.4k | } |
79 | | |
80 | | SvgAspectRatio(SvgAlign aSvgAlign, bool bMeetOrSlice) |
81 | 0 | : maSvgAlign(aSvgAlign), |
82 | 0 | mbMeetOrSlice(bMeetOrSlice), |
83 | 0 | mbSet(true) |
84 | 0 | { |
85 | 0 | } |
86 | | |
87 | | /// data read access |
88 | 0 | SvgAlign getSvgAlign() const { return maSvgAlign; } |
89 | 0 | bool isMeetOrSlice() const { return mbMeetOrSlice; } |
90 | 0 | bool isSet() const { return mbSet; } |
91 | | |
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; |
95 | | }; |
96 | | |
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); |
118 | | |
119 | | bool readSvgNumberVector(std::u16string_view rCandidate, SvgNumberVector& rSvgNumberVector); |
120 | | ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider); |
121 | | |
122 | | SvgAspectRatio readSvgAspectRatio(std::u16string_view rCandidate); |
123 | | |
124 | | typedef ::std::vector< OUString > SvgStringVector; |
125 | | bool readSvgStringVector(std::u16string_view rCandidate, SvgStringVector& rSvgStringVector, sal_Unicode nSeparator); |
126 | | |
127 | | void readImageLink(const OUString& rCandidate, OUString& rXLink, OUString& rUrl, OUString& rData); |
128 | | |
129 | | OUString consolidateContiguousSpace(const OUString& rCandidate); |
130 | | |
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); |
134 | | |
135 | | } // end of namespace svgio::svgreader |
136 | | |
137 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |