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 <svgtools.hxx>
21 #include <sal/log.hxx>
23 namespace svgio::svgreader
26 double SvgNumber::solveNonPercentage(const InfoProvider
& rInfoProvider
) const
30 SAL_WARN("svgio", "SvgNumber not set (!)");
37 return mfNumber
* rInfoProvider
.getCurrentFontSizeInherited();
39 return mfNumber
* rInfoProvider
.getCurrentXHeightInherited() * 0.5;
43 return mfNumber
* F_SVG_PIXEL_PER_INCH
/ 72.0;
45 return mfNumber
* F_SVG_PIXEL_PER_INCH
/ 6.0;
47 return mfNumber
* F_SVG_PIXEL_PER_INCH
/ 2.54;
49 return mfNumber
* 0.1 * F_SVG_PIXEL_PER_INCH
/ 2.54;
51 return mfNumber
* F_SVG_PIXEL_PER_INCH
;
54 SAL_WARN("svgio", "Design error, this case should have been handled in the caller");
57 case SvgUnit::percent
:
59 SAL_WARN("svgio", "Do not use with percentage!");
67 double SvgNumber::solve(const InfoProvider
& rInfoProvider
, NumberType aNumberType
) const
71 SAL_WARN("svgio", "SvgNumber not set (!)");
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(
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();
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
;
119 return solveNonPercentage( rInfoProvider
);
122 } // end of namespace svgio::svgreader
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */