LibreOffice Module svgio (master) 1
SvgNumber.cxx
Go to the documentation of this file.
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#include <SvgNumber.hxx>
21
23#include <sal/log.hxx>
24
25namespace svgio::svgreader
26{
27
28double SvgNumber::solveNonPercentage(const InfoProvider& rInfoProvider) const
29{
30 if (!isSet())
31 {
32 SAL_WARN("svgio", "SvgNumber not set (!)");
33 return 0.0;
34 }
35
36 switch (meUnit)
37 {
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:
46 case SvgUnit::pc:
48 case SvgUnit::cm:
50 case SvgUnit::mm:
52 case SvgUnit::in:
54 case SvgUnit::none:
55 {
56 SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
57 return mfNumber;
58 }
60 {
61 SAL_WARN("svgio", "Do not use with percentage!");
62 break;
63 }
64 }
65
66 return 0.0;
67}
68
69double SvgNumber::solve(const InfoProvider& rInfoProvider, NumberType aNumberType) const
70{
71 if (!isSet())
72 {
73 SAL_WARN("svgio", "SvgNumber not set (!)");
74 return 0.0;
75 }
76
78 {
79 double fRetval(mfNumber * 0.01);
80 basegfx::B2DRange aViewPort = rInfoProvider.getCurrentViewPort();
81
82 if ( aViewPort.isEmpty() )
83 {
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?
91
92 }
93
94 if ( !aViewPort.isEmpty() )
95 {
96 if (NumberType::xcoordinate == aNumberType)
97 {
98 // it's a x-coordinate, relative to current width (w)
99 fRetval *= aViewPort.getWidth();
100 }
101 else if (NumberType::ycoordinate == aNumberType)
102 {
103 // it's a y-coordinate, relative to current height (h)
104 fRetval *= aViewPort.getHeight();
105 }
106 else // length
107 {
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));
113
114 fRetval *= fCurrentLength;
115 }
116 }
117
118 return fRetval;
119 }
120
121 return solveNonPercentage( rInfoProvider);
122}
123
124} // end of namespace svgio::svgreader
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TYPE getWidth() const
bool isEmpty() const
TYPE getHeight() const
virtual double getCurrentFontSizeInherited() const =0
return font size of node inherited from parents
virtual double getCurrentXHeightInherited() const =0
return xheight of node inherited from parents
virtual basegfx::B2DRange getCurrentViewPort() const =0
double solveNonPercentage(const InfoProvider &rInfoProvider) const
Definition: SvgNumber.cxx:28
double solve(const InfoProvider &rInfoProvider, NumberType aNumberType=NumberType::length) const
Definition: SvgNumber.cxx:69
#define SAL_WARN(area, stream)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)