diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-05-01 13:17:21 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-05-01 13:45:02 +0200 |
commit | 0919f55512b20eb508f697f904a38b84d93aa5f9 (patch) | |
tree | d1c93d6dcd9dcb939f78f90ebf9723d496b597cc /svgio | |
parent | 6fecdeac5d81a60a479195a62cdc174b919f763b (diff) |
svgio: move SvgNumber methods to its own SvgNumber.cxx file
Change-Id: I2b52eaf83162b80ccc6f656a5808e8b2aa6c2541
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114961
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svgio')
-rw-r--r-- | svgio/Library_svgio.mk | 1 | ||||
-rw-r--r-- | svgio/source/svgreader/SvgNumber.cxx | 160 | ||||
-rw-r--r-- | svgio/source/svgreader/svgtools.cxx | 132 |
3 files changed, 161 insertions, 132 deletions
diff --git a/svgio/Library_svgio.mk b/svgio/Library_svgio.mk index 83a8546bdc1a..09b3695bb162 100644 --- a/svgio/Library_svgio.mk +++ b/svgio/Library_svgio.mk @@ -61,6 +61,7 @@ $(eval $(call gb_Library_add_exception_objects,svgio,\ svgio/source/svgreader/svgmarkernode \ svgio/source/svgreader/svgmasknode \ svgio/source/svgreader/svgnode \ + svgio/source/svgreader/SvgNumber \ svgio/source/svgreader/svgpaint \ svgio/source/svgreader/svgpathnode \ svgio/source/svgreader/svgpatternnode \ diff --git a/svgio/source/svgreader/SvgNumber.cxx b/svgio/source/svgreader/SvgNumber.cxx new file mode 100644 index 000000000000..6cfb7acf292a --- /dev/null +++ b/svgio/source/svgreader/SvgNumber.cxx @@ -0,0 +1,160 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <svgtools.hxx> +#include <sal/log.hxx> + +namespace svgio::svgreader +{ + +double SvgNumber::solveNonPercentage(const InfoProvider& rInfoProvider) const +{ + if(isSet()) + { + switch(meUnit) + { + case SvgUnit::em: + { + return mfNumber * rInfoProvider.getCurrentFontSizeInherited(); + } + case SvgUnit::ex: + { + return mfNumber * rInfoProvider.getCurrentXHeightInherited() * 0.5; + } + case SvgUnit::px: + { + return mfNumber; + } + case SvgUnit::pt: + case SvgUnit::pc: + case SvgUnit::cm: + case SvgUnit::mm: + case SvgUnit::in: + { + double fRetval(mfNumber); + + switch(meUnit) + { + case SvgUnit::pt: fRetval *= F_SVG_PIXEL_PER_INCH / 72.0; break; + case SvgUnit::pc: fRetval *= F_SVG_PIXEL_PER_INCH / 6.0; break; + case SvgUnit::cm: fRetval *= F_SVG_PIXEL_PER_INCH / 2.54; break; + case SvgUnit::mm: fRetval *= 0.1 * F_SVG_PIXEL_PER_INCH / 2.54; break; + case SvgUnit::in: fRetval *= F_SVG_PIXEL_PER_INCH; break; + default: break; + } + + return fRetval; + } + case SvgUnit::none: + { + SAL_WARN("svgio", "Design error, this case should have been handled in the caller"); + return mfNumber; + } + default: + { + assert(false && "Do not use with percentage!"); + return 0.0; + } + } + } + + /// not set + assert(false && "SvgNumber not set (!)"); + return 0.0; +} + +double SvgNumber::solve(const InfoProvider& rInfoProvider, NumberType aNumberType) const +{ + if(isSet()) + { + switch(meUnit) + { + case SvgUnit::px: + { + return mfNumber; + } + case SvgUnit::pt: + case SvgUnit::pc: + case SvgUnit::cm: + case SvgUnit::mm: + case SvgUnit::in: + case SvgUnit::em: + case SvgUnit::ex: + case SvgUnit::none: + { + return solveNonPercentage( rInfoProvider); + } + case SvgUnit::percent: + { + double fRetval(mfNumber * 0.01); + basegfx::B2DRange aViewPort = rInfoProvider.getCurrentViewPort(); + + if ( aViewPort.isEmpty() ) + { + SAL_WARN("svgio", "Design error, this case should have been handled in the caller"); + // no viewPort, assume a normal page size (A4) + aViewPort = basegfx::B2DRange( + 0.0, + 0.0, + 210.0 * F_SVG_PIXEL_PER_INCH / 2.54, + 297.0 * F_SVG_PIXEL_PER_INCH / 2.54); + + } + + if ( !aViewPort.isEmpty() ) + { + if (NumberType::xcoordinate == aNumberType) + { + // it's a x-coordinate, relative to current width (w) + fRetval *= aViewPort.getWidth(); + } + else if (NumberType::ycoordinate == aNumberType) + { + // it's a y-coordinate, relative to current height (h) + fRetval *= aViewPort.getHeight(); + } + else // length + { + // it's a length, relative to sqrt(w*w + h*h)/sqrt(2) + const double fCurrentWidth(aViewPort.getWidth()); + const double fCurrentHeight(aViewPort.getHeight()); + const double fCurrentLength( + sqrt(fCurrentWidth * fCurrentWidth + fCurrentHeight * fCurrentHeight)/sqrt(2.0)); + + fRetval *= fCurrentLength; + } + } + + return fRetval; + } + default: + { + break; + } + } + } + + /// not set + assert(false && "SvgNumber not set (!)"); + return 0.0; +} + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/source/svgreader/svgtools.cxx b/svgio/source/svgreader/svgtools.cxx index b912ce568403..75227939e489 100644 --- a/svgio/source/svgreader/svgtools.cxx +++ b/svgio/source/svgreader/svgtools.cxx @@ -135,138 +135,6 @@ namespace svgio::svgreader return aRetval; } - double SvgNumber::solveNonPercentage(const InfoProvider& rInfoProvider) const - { - if(isSet()) - { - switch(meUnit) - { - case SvgUnit::em: - { - return mfNumber * rInfoProvider.getCurrentFontSizeInherited(); - } - case SvgUnit::ex: - { - return mfNumber * rInfoProvider.getCurrentXHeightInherited() * 0.5; - } - case SvgUnit::px: - { - return mfNumber; - } - case SvgUnit::pt: - case SvgUnit::pc: - case SvgUnit::cm: - case SvgUnit::mm: - case SvgUnit::in: - { - double fRetval(mfNumber); - - switch(meUnit) - { - case SvgUnit::pt: fRetval *= F_SVG_PIXEL_PER_INCH / 72.0; break; - case SvgUnit::pc: fRetval *= F_SVG_PIXEL_PER_INCH / 6.0; break; - case SvgUnit::cm: fRetval *= F_SVG_PIXEL_PER_INCH / 2.54; break; - case SvgUnit::mm: fRetval *= 0.1 * F_SVG_PIXEL_PER_INCH / 2.54; break; - case SvgUnit::in: fRetval *= F_SVG_PIXEL_PER_INCH; break; - default: break; - } - - return fRetval; - } - case SvgUnit::none: - { - SAL_WARN("svgio", "Design error, this case should have been handled in the caller"); - return mfNumber; - } - default: - { - assert(false && "Do not use with percentage!"); - return 0.0; - } - } - } - - /// not set - assert(false && "SvgNumber not set (!)"); - return 0.0; - } - - double SvgNumber::solve(const InfoProvider& rInfoProvider, NumberType aNumberType) const - { - if(isSet()) - { - switch(meUnit) - { - case SvgUnit::px: - { - return mfNumber; - } - case SvgUnit::pt: - case SvgUnit::pc: - case SvgUnit::cm: - case SvgUnit::mm: - case SvgUnit::in: - case SvgUnit::em: - case SvgUnit::ex: - case SvgUnit::none: - { - return solveNonPercentage( rInfoProvider); - } - case SvgUnit::percent: - { - double fRetval(mfNumber * 0.01); - basegfx::B2DRange aViewPort = rInfoProvider.getCurrentViewPort(); - - if ( aViewPort.isEmpty() ) - { - SAL_WARN("svgio", "Design error, this case should have been handled in the caller"); - // no viewPort, assume a normal page size (A4) - aViewPort = basegfx::B2DRange( - 0.0, - 0.0, - 210.0 * F_SVG_PIXEL_PER_INCH / 2.54, - 297.0 * F_SVG_PIXEL_PER_INCH / 2.54); - - } - - if ( !aViewPort.isEmpty() ) - { - if (NumberType::xcoordinate == aNumberType) - { - // it's a x-coordinate, relative to current width (w) - fRetval *= aViewPort.getWidth(); - } - else if (NumberType::ycoordinate == aNumberType) - { - // it's a y-coordinate, relative to current height (h) - fRetval *= aViewPort.getHeight(); - } - else // length - { - // it's a length, relative to sqrt(w*w + h*h)/sqrt(2) - const double fCurrentWidth(aViewPort.getWidth()); - const double fCurrentHeight(aViewPort.getHeight()); - const double fCurrentLength( - sqrt(fCurrentWidth * fCurrentWidth + fCurrentHeight * fCurrentHeight)/sqrt(2.0)); - - fRetval *= fCurrentLength; - } - } - - return fRetval; - } - default: - { - break; - } - } - } - - /// not set - assert(false && "SvgNumber not set (!)"); - return 0.0; - } - void skip_char(std::u16string_view rCandidate, sal_Unicode nChar, sal_Int32& nPos, const sal_Int32 nLen) { while(nPos < nLen && nChar == rCandidate[nPos]) |