bump product version to 7.2.5.1
[LibreOffice.git] / svgio / inc / SvgNumber.hxx
blob9b6907a02031b19ef204dc6184e8b46b5df0d56c
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/range/b2drange.hxx>
23 #include <vector>
25 namespace svgio::svgreader
28 // recommended value for this device dependent unit, see CSS2 section 4.3.2 Lengths
29 constexpr const double F_SVG_PIXEL_PER_INCH = 96.0;
31 enum class NumberType
33 xcoordinate,
34 ycoordinate,
35 length
38 class InfoProvider
40 public:
41 virtual ~InfoProvider() {}
42 virtual basegfx::B2DRange getCurrentViewPort() const = 0;
43 /// return font size of node inherited from parents
44 virtual double getCurrentFontSizeInherited() const = 0;
45 /// return xheight of node inherited from parents
46 virtual double getCurrentXHeightInherited() const = 0;
49 enum class SvgUnit
51 em = 0, // relative to current font size
52 ex, // relative to current x-height
54 px, // 'user unit'
55 pt, // points, 1.25 px
56 pc, // 15.0 px
57 cm, // 35.43307 px
58 mm, // 3.543307 px
59 in, // 90 px
61 percent, // relative to range
62 none // for stroke-miterlimit, which has no unit
65 class SvgNumber
67 private:
68 double mfNumber;
69 SvgUnit meUnit;
71 bool mbSet : 1;
73 public:
74 SvgNumber()
75 : mfNumber(0.0),
76 meUnit(SvgUnit::px),
77 mbSet(false)
81 SvgNumber(double fNum, SvgUnit aSvgUnit = SvgUnit::px, bool bSet = true)
82 : mfNumber(fNum),
83 meUnit(aSvgUnit),
84 mbSet(bSet)
88 double getNumber() const
90 return mfNumber;
93 SvgUnit getUnit() const
95 return meUnit;
98 bool isSet() const
100 return mbSet;
103 bool isPositive() const
105 return basegfx::fTools::moreOrEqual(mfNumber, 0.0);
108 // Only usable in cases, when the unit is not SvgUnit::percent, otherwise use method solve
109 double solveNonPercentage(const InfoProvider& rInfoProvider) const;
111 double solve(const InfoProvider& rInfoProvider, NumberType aNumberType = NumberType::length) const;
114 typedef std::vector<SvgNumber> SvgNumberVector;
116 } // end of namespace svgio::svgreader
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */