diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-08-10 14:39:27 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-08-10 16:34:54 +0200 |
commit | fff601edf76b1783c5a47353452a83ac9c5ac07a (patch) | |
tree | db2608ad1a2ba073d1641e5ae5966df560c33c1d | |
parent | 4f656a057e2a92e2107f7820fc563498c801d7d3 (diff) |
svgio: move SvgTextPosition to its own file
In order to avoid a circular dependency in a follow-up commit
Change-Id: Ib7b16e73282dfa6f3ca87aab1044cb92df72b6bf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155555
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | svgio/Library_svgio.mk | 1 | ||||
-rw-r--r-- | svgio/inc/svgcharacternode.hxx | 43 | ||||
-rw-r--r-- | svgio/inc/svgtextnode.hxx | 2 | ||||
-rw-r--r-- | svgio/inc/svgtextposition.hxx | 72 | ||||
-rw-r--r-- | svgio/source/svgreader/svgcharacternode.cxx | 171 | ||||
-rw-r--r-- | svgio/source/svgreader/svgtextposition.cxx | 200 |
6 files changed, 275 insertions, 214 deletions
diff --git a/svgio/Library_svgio.mk b/svgio/Library_svgio.mk index c25077ed94d3..edd83ed57251 100644 --- a/svgio/Library_svgio.mk +++ b/svgio/Library_svgio.mk @@ -85,6 +85,7 @@ $(eval $(call gb_Library_add_exception_objects,svgio,\ svgio/source/svgreader/svgsvgnode \ svgio/source/svgreader/svgsymbolnode \ svgio/source/svgreader/svgtextnode \ + svgio/source/svgreader/svgtextposition \ svgio/source/svgreader/svgtitledescnode \ svgio/source/svgreader/svgtoken \ svgio/source/svgreader/svgtrefnode \ diff --git a/svgio/inc/svgcharacternode.hxx b/svgio/inc/svgcharacternode.hxx index e0e353a429a7..007f9028e80b 100644 --- a/svgio/inc/svgcharacternode.hxx +++ b/svgio/inc/svgcharacternode.hxx @@ -25,53 +25,12 @@ #include <string_view> #include "svgnode.hxx" -#include "svgtspannode.hxx" +#include "svgtextposition.hxx" namespace drawinglayer::primitive2d { class TextSimplePortionPrimitive2D; } namespace svgio::svgreader { - class SvgTextPosition - { - private: - SvgTextPosition* mpParent; - ::std::vector< double > maX; - ::std::vector< double > maY; - ::std::vector< double > maDx; - ::std::vector< double > maRotate; - double mfTextLength; - - // absolute, current, advancing position - basegfx::B2DPoint maPosition; - - // advancing rotation index - sal_uInt32 mnRotationIndex; - - bool mbLengthAdjust : 1; // true = spacing, false = spacingAndGlyphs - bool mbAbsoluteX : 1; - - public: - SvgTextPosition( - SvgTextPosition* pParent, - const SvgTspanNode& rSvgCharacterNode); - - // data read access - const SvgTextPosition* getParent() const { return mpParent; } - const ::std::vector< double >& getX() const { return maX; } - const ::std::vector< double >& getDx() const { return maDx; } - double getTextLength() const { return mfTextLength; } - bool getLengthAdjust() const { return mbLengthAdjust; } - bool getAbsoluteX() const { return mbAbsoluteX; } - - // get/set absolute, current, advancing position - const basegfx::B2DPoint& getPosition() const { return maPosition; } - void setPosition(const basegfx::B2DPoint& rNew) { maPosition = rNew; } - - // rotation handling - bool isRotated() const; - double consumeRotation(); - }; - class SvgCharacterNode final : public SvgNode { private: diff --git a/svgio/inc/svgtextnode.hxx b/svgio/inc/svgtextnode.hxx index da6f0e5cbcb2..787687977e11 100644 --- a/svgio/inc/svgtextnode.hxx +++ b/svgio/inc/svgtextnode.hxx @@ -20,7 +20,7 @@ #pragma once #include "svgstyleattributes.hxx" -#include "svgcharacternode.hxx" +#include "svgtextposition.hxx" #include "svgtspannode.hxx" #include <basegfx/matrix/b2dhommatrix.hxx> diff --git a/svgio/inc/svgtextposition.hxx b/svgio/inc/svgtextposition.hxx new file mode 100644 index 000000000000..df6adc16ab1e --- /dev/null +++ b/svgio/inc/svgtextposition.hxx @@ -0,0 +1,72 @@ +/* -*- 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 . + */ + +#pragma once + +#include <sal/config.h> +#include <rtl/ref.hxx> + +#include <string_view> + +#include "svgtspannode.hxx" + +namespace svgio::svgreader +{ +class SvgTextPosition +{ +private: + SvgTextPosition* mpParent; + ::std::vector<double> maX; + ::std::vector<double> maY; + ::std::vector<double> maDx; + ::std::vector<double> maRotate; + double mfTextLength; + + // absolute, current, advancing position + basegfx::B2DPoint maPosition; + + // advancing rotation index + sal_uInt32 mnRotationIndex; + + bool mbLengthAdjust : 1; // true = spacing, false = spacingAndGlyphs + bool mbAbsoluteX : 1; + +public: + SvgTextPosition(SvgTextPosition* pParent, const SvgTspanNode& rSvgCharacterNode); + + // data read access + const SvgTextPosition* getParent() const { return mpParent; } + const ::std::vector<double>& getX() const { return maX; } + const ::std::vector<double>& getDx() const { return maDx; } + double getTextLength() const { return mfTextLength; } + bool getLengthAdjust() const { return mbLengthAdjust; } + bool getAbsoluteX() const { return mbAbsoluteX; } + + // get/set absolute, current, advancing position + const basegfx::B2DPoint& getPosition() const { return maPosition; } + void setPosition(const basegfx::B2DPoint& rNew) { maPosition = rNew; } + + // rotation handling + bool isRotated() const; + double consumeRotation(); +}; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/source/svgreader/svgcharacternode.cxx b/svgio/source/svgreader/svgcharacternode.cxx index e014cd6bf1bf..2c3fce247554 100644 --- a/svgio/source/svgreader/svgcharacternode.cxx +++ b/svgio/source/svgreader/svgcharacternode.cxx @@ -525,177 +525,6 @@ namespace svgio::svgreader } } - - SvgTextPosition::SvgTextPosition( - SvgTextPosition* pParent, - const SvgTspanNode& rSvgTspanNode) - : mpParent(pParent), - maRotate(solveSvgNumberVector(rSvgTspanNode.getRotate(), rSvgTspanNode)), - mfTextLength(0.0), - mnRotationIndex(0), - mbLengthAdjust(rSvgTspanNode.getLengthAdjust()), - mbAbsoluteX(false) - { - const InfoProvider& rInfoProvider(rSvgTspanNode); - - // get TextLength if provided - if(rSvgTspanNode.getTextLength().isSet()) - { - mfTextLength = rSvgTspanNode.getTextLength().solve(rInfoProvider); - } - - // SVG does not really define in which units a \91rotate\92 for Text/TSpan is given, - // but it seems to be degrees. Convert here to radians - if(!maRotate.empty()) - { - for (double& f : maRotate) - { - f = basegfx::deg2rad(f); - } - } - - // get text positions X - const sal_uInt32 nSizeX(rSvgTspanNode.getX().size()); - - if(nSizeX) - { - // we have absolute positions, get first one as current text position X - maPosition.setX(rSvgTspanNode.getX()[0].solve(rInfoProvider, NumberType::xcoordinate)); - mbAbsoluteX = true; - } - else - { - // no absolute position, get from parent - if(pParent) - { - maPosition.setX(pParent->getPosition().getX()); - } - } - - const sal_uInt32 nSizeDx(rSvgTspanNode.getDx().size()); - if(nSizeDx) - { - // relative positions given, translate position derived from parent - maPosition.setX(maPosition.getX() + rSvgTspanNode.getDx()[0].solve(rInfoProvider, NumberType::xcoordinate)); - } - - // fill deltas to maX - maX.reserve(nSizeX); - - for(sal_uInt32 a(1); a < std::max(nSizeX, nSizeDx); ++a) - { - if (a < nSizeX) - { - double nPos = rSvgTspanNode.getX()[a].solve(rInfoProvider, NumberType::xcoordinate) - maPosition.getX(); - - if(a < nSizeDx) - { - nPos += rSvgTspanNode.getDx()[a].solve(rInfoProvider, NumberType::xcoordinate); - } - - maX.push_back(nPos); - } - else - { - // Apply them later since it also needs the character width to calculate - // the final character position - maDx.push_back(rSvgTspanNode.getDx()[a].solve(rInfoProvider, NumberType::xcoordinate)); - } - } - - // get text positions Y - const sal_uInt32 nSizeY(rSvgTspanNode.getY().size()); - - if(nSizeY) - { - // we have absolute positions, get first one as current text position Y - maPosition.setY(rSvgTspanNode.getY()[0].solve(rInfoProvider, NumberType::ycoordinate)); - mbAbsoluteX = true; - } - else - { - // no absolute position, get from parent - if(pParent) - { - maPosition.setY(pParent->getPosition().getY()); - } - } - - const sal_uInt32 nSizeDy(rSvgTspanNode.getDy().size()); - - if(nSizeDy) - { - // relative positions given, translate position derived from parent - maPosition.setY(maPosition.getY() + rSvgTspanNode.getDy()[0].solve(rInfoProvider, NumberType::ycoordinate)); - } - - // fill deltas to maY - maY.reserve(nSizeY); - - for(sal_uInt32 a(1); a < nSizeY; a++) - { - double nPos = rSvgTspanNode.getY()[a].solve(rInfoProvider, NumberType::ycoordinate) - maPosition.getY(); - - if(a < nSizeDy) - { - nPos += rSvgTspanNode.getDy()[a].solve(rInfoProvider, NumberType::ycoordinate); - } - - maY.push_back(nPos); - } - } - - bool SvgTextPosition::isRotated() const - { - if(maRotate.empty()) - { - if(getParent()) - { - return getParent()->isRotated(); - } - else - { - return false; - } - } - else - { - return true; - } - } - - double SvgTextPosition::consumeRotation() - { - double fRetval(0.0); - - if(maRotate.empty()) - { - if(getParent()) - { - fRetval = mpParent->consumeRotation(); - } - else - { - fRetval = 0.0; - } - } - else - { - const sal_uInt32 nSize(maRotate.size()); - - if(mnRotationIndex < nSize) - { - fRetval = maRotate[mnRotationIndex++]; - } - else - { - fRetval = maRotate[nSize - 1]; - } - } - - return fRetval; - } - } // end of namespace svgio /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/source/svgreader/svgtextposition.cxx b/svgio/source/svgreader/svgtextposition.cxx new file mode 100644 index 000000000000..50a896ba2204 --- /dev/null +++ b/svgio/source/svgreader/svgtextposition.cxx @@ -0,0 +1,200 @@ +/* -*- 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 <svgtextposition.hxx> + +using namespace drawinglayer::primitive2d; + +namespace svgio::svgreader +{ +SvgTextPosition::SvgTextPosition(SvgTextPosition* pParent, const SvgTspanNode& rSvgTspanNode) + : mpParent(pParent) + , maRotate(solveSvgNumberVector(rSvgTspanNode.getRotate(), rSvgTspanNode)) + , mfTextLength(0.0) + , mnRotationIndex(0) + , mbLengthAdjust(rSvgTspanNode.getLengthAdjust()) + , mbAbsoluteX(false) +{ + const InfoProvider& rInfoProvider(rSvgTspanNode); + + // get TextLength if provided + if (rSvgTspanNode.getTextLength().isSet()) + { + mfTextLength = rSvgTspanNode.getTextLength().solve(rInfoProvider); + } + + // SVG does not really define in which units a \91rotate\92 for Text/TSpan is given, + // but it seems to be degrees. Convert here to radians + if (!maRotate.empty()) + { + for (double& f : maRotate) + { + f = basegfx::deg2rad(f); + } + } + + // get text positions X + const sal_uInt32 nSizeX(rSvgTspanNode.getX().size()); + + if (nSizeX) + { + // we have absolute positions, get first one as current text position X + maPosition.setX(rSvgTspanNode.getX()[0].solve(rInfoProvider, NumberType::xcoordinate)); + mbAbsoluteX = true; + } + else + { + // no absolute position, get from parent + if (pParent) + { + maPosition.setX(pParent->getPosition().getX()); + } + } + + const sal_uInt32 nSizeDx(rSvgTspanNode.getDx().size()); + if (nSizeDx) + { + // relative positions given, translate position derived from parent + maPosition.setX(maPosition.getX() + + rSvgTspanNode.getDx()[0].solve(rInfoProvider, NumberType::xcoordinate)); + } + + // fill deltas to maX + maX.reserve(nSizeX); + + for (sal_uInt32 a(1); a < std::max(nSizeX, nSizeDx); ++a) + { + if (a < nSizeX) + { + double nPos = rSvgTspanNode.getX()[a].solve(rInfoProvider, NumberType::xcoordinate) + - maPosition.getX(); + + if (a < nSizeDx) + { + nPos += rSvgTspanNode.getDx()[a].solve(rInfoProvider, NumberType::xcoordinate); + } + + maX.push_back(nPos); + } + else + { + // Apply them later since it also needs the character width to calculate + // the final character position + maDx.push_back(rSvgTspanNode.getDx()[a].solve(rInfoProvider, NumberType::xcoordinate)); + } + } + + // get text positions Y + const sal_uInt32 nSizeY(rSvgTspanNode.getY().size()); + + if (nSizeY) + { + // we have absolute positions, get first one as current text position Y + maPosition.setY(rSvgTspanNode.getY()[0].solve(rInfoProvider, NumberType::ycoordinate)); + mbAbsoluteX = true; + } + else + { + // no absolute position, get from parent + if (pParent) + { + maPosition.setY(pParent->getPosition().getY()); + } + } + + const sal_uInt32 nSizeDy(rSvgTspanNode.getDy().size()); + + if (nSizeDy) + { + // relative positions given, translate position derived from parent + maPosition.setY(maPosition.getY() + + rSvgTspanNode.getDy()[0].solve(rInfoProvider, NumberType::ycoordinate)); + } + + // fill deltas to maY + maY.reserve(nSizeY); + + for (sal_uInt32 a(1); a < nSizeY; a++) + { + double nPos = rSvgTspanNode.getY()[a].solve(rInfoProvider, NumberType::ycoordinate) + - maPosition.getY(); + + if (a < nSizeDy) + { + nPos += rSvgTspanNode.getDy()[a].solve(rInfoProvider, NumberType::ycoordinate); + } + + maY.push_back(nPos); + } +} + +bool SvgTextPosition::isRotated() const +{ + if (maRotate.empty()) + { + if (getParent()) + { + return getParent()->isRotated(); + } + else + { + return false; + } + } + else + { + return true; + } +} + +double SvgTextPosition::consumeRotation() +{ + double fRetval(0.0); + + if (maRotate.empty()) + { + if (getParent()) + { + fRetval = mpParent->consumeRotation(); + } + else + { + fRetval = 0.0; + } + } + else + { + const sal_uInt32 nSize(maRotate.size()); + + if (mnRotationIndex < nSize) + { + fRetval = maRotate[mnRotationIndex++]; + } + else + { + fRetval = maRotate[nSize - 1]; + } + } + + return fRetval; +} + +} // end of namespace svgio + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |