Resolves: tdf#149858 embedded starmath not using correct initial zoom
[LibreOffice.git] / svgio / inc / svgtools.hxx
blob7b532cd35b159001bc2fb544deebf07fd2270340
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 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";
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(const OUString& 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(const OUString& rCandidate, InfoProvider const & rInfoProvider);
112 basegfx::B2DHomMatrix readTransform(const OUString& rCandidate, InfoProvider const & rInfoProvider);
113 bool readSingleNumber(const OUString& rCandidate, SvgNumber& aNum);
114 bool readLocalUrl(const OUString& rCandidate, OUString& rURL);
115 bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, SvgNumber& rOpacity);
117 bool readSvgNumberVector(const OUString& rCandidate, SvgNumberVector& rSvgNumberVector);
118 ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider);
120 SvgAspectRatio readSvgAspectRatio(const OUString& rCandidate);
122 typedef ::std::vector< OUString > SvgStringVector;
123 bool readSvgStringVector(const OUString& rCandidate, SvgStringVector& rSvgStringVector);
125 void readImageLink(const OUString& rCandidate, OUString& rXLink, OUString& rUrl, OUString& rMimeType, OUString& rData);
127 OUString convert(const OUString& rCandidate, sal_Unicode nPattern, sal_Unicode nNew, bool bRemove);
128 OUString consolidateContiguousSpace(const OUString& rCandidate);
129 OUString whiteSpaceHandlingDefault(const OUString& rCandidate);
130 OUString whiteSpaceHandlingPreserve(const OUString& rCandidate);
132 // #125325# removes block comment of the general form '/* ... */', returns
133 // an adapted string or the original if no comments included
134 OUString removeBlockComments(const OUString& rCandidate);
136 } // end of namespace svgio::svgreader
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */