calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / svgio / source / svgreader / SvgNumber.cxx
blobc1558f3e645154a4b533a4bc839cb34a4cb81868
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 <SvgNumber.hxx>
22 #include <o3tl/unit_conversion.hxx>
23 #include <sal/log.hxx>
25 namespace svgio::svgreader
28 double SvgNumber::solveNonPercentage(const InfoProvider& rInfoProvider) const
30 if (!isSet())
32 SAL_WARN("svgio", "SvgNumber not set (!)");
33 return 0.0;
36 switch (meUnit)
38 case SvgUnit::em:
39 return mfNumber * rInfoProvider.getCurrentFontSizeInherited();
40 case SvgUnit::ex:
41 return mfNumber * rInfoProvider.getCurrentXHeightInherited() * 0.5;
42 case SvgUnit::px:
43 return mfNumber;
44 case SvgUnit::pt:
45 return o3tl::convert(mfNumber, o3tl::Length::pt, o3tl::Length::px);
46 case SvgUnit::pc:
47 return o3tl::convert(mfNumber, o3tl::Length::pc, o3tl::Length::px);
48 case SvgUnit::cm:
49 return o3tl::convert(mfNumber, o3tl::Length::cm, o3tl::Length::px);
50 case SvgUnit::mm:
51 return o3tl::convert(mfNumber, o3tl::Length::mm, o3tl::Length::px);
52 case SvgUnit::in:
53 return o3tl::convert(mfNumber, o3tl::Length::in, o3tl::Length::px);
54 case SvgUnit::none:
56 SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
57 return mfNumber;
59 case SvgUnit::percent:
61 SAL_WARN("svgio", "Do not use with percentage!");
62 break;
66 return 0.0;
69 double SvgNumber::solve(const InfoProvider& rInfoProvider, NumberType aNumberType) const
71 if (!isSet())
73 SAL_WARN("svgio", "SvgNumber not set (!)");
74 return 0.0;
77 if (meUnit == SvgUnit::percent)
79 double fRetval(mfNumber * 0.01);
80 basegfx::B2DRange aViewPort = rInfoProvider.getCurrentViewPort();
82 if ( aViewPort.isEmpty() )
84 SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
85 // no viewPort, assume a normal page size (A4)
86 aViewPort = basegfx::B2DRange(
87 0.0,
88 0.0,
89 o3tl::convert(210.0, o3tl::Length::cm, o3tl::Length::px), // should it be mm?
90 o3tl::convert(297.0, o3tl::Length::cm, o3tl::Length::px));
94 if ( !aViewPort.isEmpty() )
96 if (NumberType::xcoordinate == aNumberType)
98 // it's a x-coordinate, relative to current width (w)
99 fRetval *= aViewPort.getWidth();
101 else if (NumberType::ycoordinate == aNumberType)
103 // it's a y-coordinate, relative to current height (h)
104 fRetval *= aViewPort.getHeight();
106 else // length
108 // it's a length, relative to sqrt((w^2 + h^2)/2)
109 const double fCurrentWidth(aViewPort.getWidth());
110 const double fCurrentHeight(aViewPort.getHeight());
111 const double fCurrentLength(
112 sqrt((fCurrentWidth * fCurrentWidth + fCurrentHeight * fCurrentHeight)/2.0));
114 fRetval *= fCurrentLength;
118 return fRetval;
121 return solveNonPercentage( rInfoProvider);
124 } // end of namespace svgio::svgreader
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */