bump product version to 7.2.5.1
[LibreOffice.git] / svgio / source / svgreader / SvgNumber.cxx
blob9a11c197996246a4575b522954f33d69b3b11d9b
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 #include <svgtools.hxx>
21 #include <sal/log.hxx>
23 namespace svgio::svgreader
26 double SvgNumber::solveNonPercentage(const InfoProvider& rInfoProvider) const
28 if (!isSet())
30 SAL_WARN("svgio", "SvgNumber not set (!)");
31 return 0.0;
34 switch (meUnit)
36 case SvgUnit::em:
37 return mfNumber * rInfoProvider.getCurrentFontSizeInherited();
38 case SvgUnit::ex:
39 return mfNumber * rInfoProvider.getCurrentXHeightInherited() * 0.5;
40 case SvgUnit::px:
41 return mfNumber;
42 case SvgUnit::pt:
43 return mfNumber * F_SVG_PIXEL_PER_INCH / 72.0;
44 case SvgUnit::pc:
45 return mfNumber * F_SVG_PIXEL_PER_INCH / 6.0;
46 case SvgUnit::cm:
47 return mfNumber * F_SVG_PIXEL_PER_INCH / 2.54;
48 case SvgUnit::mm:
49 return mfNumber * 0.1 * F_SVG_PIXEL_PER_INCH / 2.54;
50 case SvgUnit::in:
51 return mfNumber * F_SVG_PIXEL_PER_INCH;
52 case SvgUnit::none:
54 SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
55 return mfNumber;
57 case SvgUnit::percent:
59 SAL_WARN("svgio", "Do not use with percentage!");
60 break;
64 return 0.0;
67 double SvgNumber::solve(const InfoProvider& rInfoProvider, NumberType aNumberType) const
69 if (!isSet())
71 SAL_WARN("svgio", "SvgNumber not set (!)");
72 return 0.0;
75 if (meUnit == SvgUnit::percent)
77 double fRetval(mfNumber * 0.01);
78 basegfx::B2DRange aViewPort = rInfoProvider.getCurrentViewPort();
80 if ( aViewPort.isEmpty() )
82 SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
83 // no viewPort, assume a normal page size (A4)
84 aViewPort = basegfx::B2DRange(
85 0.0,
86 0.0,
87 210.0 * F_SVG_PIXEL_PER_INCH / 2.54,
88 297.0 * F_SVG_PIXEL_PER_INCH / 2.54);
92 if ( !aViewPort.isEmpty() )
94 if (NumberType::xcoordinate == aNumberType)
96 // it's a x-coordinate, relative to current width (w)
97 fRetval *= aViewPort.getWidth();
99 else if (NumberType::ycoordinate == aNumberType)
101 // it's a y-coordinate, relative to current height (h)
102 fRetval *= aViewPort.getHeight();
104 else // length
106 // it's a length, relative to sqrt(w*w + h*h)/sqrt(2)
107 const double fCurrentWidth(aViewPort.getWidth());
108 const double fCurrentHeight(aViewPort.getHeight());
109 const double fCurrentLength(
110 sqrt(fCurrentWidth * fCurrentWidth + fCurrentHeight * fCurrentHeight)/sqrt(2.0));
112 fRetval *= fCurrentLength;
116 return fRetval;
119 return solveNonPercentage( rInfoProvider);
122 } // end of namespace svgio::svgreader
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */