1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
32 SAL_WARN("svgio", "SvgNumber not set (!)");
39 return mfNumber
* rInfoProvider
.getCurrentFontSizeInherited();
41 return mfNumber
* rInfoProvider
.getCurrentXHeightInherited() * 0.5;
45 return o3tl::convert(mfNumber
, o3tl::Length::pt
, o3tl::Length::px
);
47 return o3tl::convert(mfNumber
, o3tl::Length::pc
, o3tl::Length::px
);
49 return o3tl::convert(mfNumber
, o3tl::Length::cm
, o3tl::Length::px
);
51 return o3tl::convert(mfNumber
, o3tl::Length::mm
, o3tl::Length::px
);
53 return o3tl::convert(mfNumber
, o3tl::Length::in
, o3tl::Length::px
);
56 SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
59 case SvgUnit::percent
:
61 SAL_WARN("svgio", "Do not use with percentage!");
69 double SvgNumber::solve(const InfoProvider
& rInfoProvider
, NumberType aNumberType
) const
73 SAL_WARN("svgio", "SvgNumber not set (!)");
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(
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();
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
;
121 return solveNonPercentage( rInfoProvider
);
124 } // end of namespace svgio::svgreader
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */