diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /svgio/inc | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'svgio/inc')
36 files changed, 3246 insertions, 0 deletions
diff --git a/svgio/inc/SvgNumber.hxx b/svgio/inc/SvgNumber.hxx new file mode 100644 index 000000000..4d03335cf --- /dev/null +++ b/svgio/inc/SvgNumber.hxx @@ -0,0 +1,115 @@ +/* -*- 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 <basegfx/range/b2drange.hxx> +#include <vector> + +namespace svgio::svgreader +{ + +enum class NumberType +{ + xcoordinate, + ycoordinate, + length +}; + +class InfoProvider +{ +public: + virtual ~InfoProvider() {} + virtual basegfx::B2DRange getCurrentViewPort() const = 0; + /// return font size of node inherited from parents + virtual double getCurrentFontSizeInherited() const = 0; + /// return xheight of node inherited from parents + virtual double getCurrentXHeightInherited() const = 0; +}; + +enum class SvgUnit +{ + em = 0, // relative to current font size + ex, // relative to current x-height + + px, // 'user unit' + pt, // points, 1/72 in + pc, // 1/6 in + cm, + mm, + in, + + percent, // relative to range + none // for stroke-miterlimit, which has no unit +}; + +class SvgNumber +{ +private: + double mfNumber; + SvgUnit meUnit; + + bool mbSet : 1; + +public: + SvgNumber() + : mfNumber(0.0), + meUnit(SvgUnit::px), + mbSet(false) + { + } + + SvgNumber(double fNum, SvgUnit aSvgUnit = SvgUnit::px, bool bSet = true) + : mfNumber(fNum), + meUnit(aSvgUnit), + mbSet(bSet) + { + } + + double getNumber() const + { + return mfNumber; + } + + SvgUnit getUnit() const + { + return meUnit; + } + + bool isSet() const + { + return mbSet; + } + + bool isPositive() const + { + return basegfx::fTools::moreOrEqual(mfNumber, 0.0); + } + + // Only usable in cases, when the unit is not SvgUnit::percent, otherwise use method solve + double solveNonPercentage(const InfoProvider& rInfoProvider) const; + + double solve(const InfoProvider& rInfoProvider, NumberType aNumberType = NumberType::length) const; +}; + +typedef std::vector<SvgNumber> SvgNumberVector; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/pch/precompiled_svgio.cxx b/svgio/inc/pch/precompiled_svgio.cxx new file mode 100644 index 000000000..843dba73f --- /dev/null +++ b/svgio/inc/pch/precompiled_svgio.cxx @@ -0,0 +1,12 @@ +/* -*- 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/. + */ + +#include "precompiled_svgio.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/pch/precompiled_svgio.hxx b/svgio/inc/pch/precompiled_svgio.hxx new file mode 100644 index 000000000..c9e284ca2 --- /dev/null +++ b/svgio/inc/pch/precompiled_svgio.hxx @@ -0,0 +1,69 @@ +/* -*- 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 has been autogenerated by update_pch.sh. It is possible to edit it + manually (such as when an include file has been moved/renamed/removed). All such + manual changes will be rewritten by the next run of update_pch.sh (which presumably + also fixes all possible problems, so it's usually better to use it). + + Generated on 2021-04-11 19:48:19 using: + ./bin/update_pch svgio svgio --cutoff=8 --exclude:system --exclude:module --include:local + + If after updating build fails, use the following command to locate conflicting headers: + ./bin/update_pch_bisect ./svgio/inc/pch/precompiled_svgio.hxx "make svgio.build" --find-conflicts +*/ + +#include <sal/config.h> +#if PCH_LEVEL >= 1 +#include <memory> +#include <ostream> +#include <string_view> +#include <vector> +#endif // PCH_LEVEL >= 1 +#if PCH_LEVEL >= 2 +#include <osl/diagnose.h> +#include <osl/endian.h> +#include <rtl/instance.hxx> +#include <rtl/math.hxx> +#include <rtl/ref.hxx> +#include <rtl/uri.hxx> +#include <rtl/ustring.hxx> +#include <sal/log.hxx> +#include <sal/types.h> +#endif // PCH_LEVEL >= 2 +#if PCH_LEVEL >= 3 +#include <basegfx/basegfxdllapi.h> +#include <basegfx/color/bcolor.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/point/b2dpoint.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> +#include <basegfx/polygon/b3dpolypolygon.hxx> +#include <basegfx/range/b2drange.hxx> +#include <com/sun/star/drawing/PointSequenceSequence.hpp> +#include <drawinglayer/drawinglayerdllapi.h> +#include <drawinglayer/primitive2d/Primitive2DContainer.hxx> +#include <drawinglayer/primitive2d/baseprimitive2d.hxx> +#include <drawinglayer/primitive2d/groupprimitive2d.hxx> +#include <o3tl/cow_wrapper.hxx> +#include <o3tl/sorted_vector.hxx> +#include <tools/fontenum.hxx> +#include <tools/toolsdllapi.h> +#endif // PCH_LEVEL >= 3 +#if PCH_LEVEL >= 4 +#include <svgdocument.hxx> +#include <svgnode.hxx> +#include <svgpaint.hxx> +#include <svgstyleattributes.hxx> +#endif // PCH_LEVEL >= 4 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svganode.hxx b/svgio/inc/svganode.hxx new file mode 100644 index 000000000..1590421c5 --- /dev/null +++ b/svgio/inc/svganode.hxx @@ -0,0 +1,54 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgANode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::optional<basegfx::B2DHomMatrix> mpaTransform; + + public: + SvgANode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgANode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// transform content + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgcharacternode.hxx b/svgio/inc/svgcharacternode.hxx new file mode 100644 index 000000000..0e618c3f1 --- /dev/null +++ b/svgio/inc/svgcharacternode.hxx @@ -0,0 +1,153 @@ +/* -*- 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 "svgnode.hxx" + +namespace drawinglayer::primitive2d { class TextSimplePortionPrimitive2D; } + +namespace svgio::svgreader + { + class SvgTextPositions + { + private: + SvgNumberVector maX; + SvgNumberVector maY; + SvgNumberVector maDx; + SvgNumberVector maDy; + SvgNumberVector maRotate; + SvgNumber maTextLength; + + bool mbLengthAdjust : 1; // true = spacing, false = spacingAndGlyphs + + public: + SvgTextPositions(); + + void parseTextPositionAttributes(SVGToken aSVGToken, const OUString& aContent); + + /// X content + const SvgNumberVector& getX() const { return maX; } + void setX(SvgNumberVector&& aX) { maX = std::move(aX); } + + /// Y content + const SvgNumberVector& getY() const { return maY; } + void setY(SvgNumberVector&& aY) { maY = std::move(aY); } + + /// Dx content + const SvgNumberVector& getDx() const { return maDx; } + void setDx(SvgNumberVector&& aDx) { maDx = std::move(aDx); } + + /// Dy content + const SvgNumberVector& getDy() const { return maDy; } + void setDy(SvgNumberVector&& aDy) { maDy = std::move(aDy); } + + /// Rotate content + const SvgNumberVector& getRotate() const { return maRotate; } + void setRotate(SvgNumberVector&& aRotate) { maRotate = std::move(aRotate); } + + /// TextLength content + const SvgNumber& getTextLength() const { return maTextLength; } + void setTextLength(const SvgNumber& rTextLength) { maTextLength = rTextLength; } + + /// LengthAdjust content + bool getLengthAdjust() const { return mbLengthAdjust; } + void setLengthAdjust(bool bNew) { mbLengthAdjust = bNew; } + }; + + class SvgTextPosition + { + private: + SvgTextPosition* mpParent; + ::std::vector< double > maX; + ::std::vector< double > maY; + ::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 InfoProvider& rInfoProvider, + const SvgTextPositions& rSvgTextPositions); + + // data read access + const SvgTextPosition* getParent() const { return mpParent; } + const ::std::vector< double >& getX() const { return maX; } + 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: + /// the string data + OUString maText; + + /// local helpers + rtl::Reference<drawinglayer::primitive2d::BasePrimitive2D> createSimpleTextPrimitive( + SvgTextPosition& rSvgTextPosition, + const SvgStyleAttributes& rSvgStyleAttributes) const; + void decomposeTextWithStyle( + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + SvgTextPosition& rSvgTextPosition, + const SvgStyleAttributes& rSvgStyleAttributes) const; + + public: + SvgCharacterNode( + SvgDocument& rDocument, + SvgNode* pParent, + const OUString& rText); + virtual ~SvgCharacterNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + void decomposeText(drawinglayer::primitive2d::Primitive2DContainer& rTarget, SvgTextPosition& rSvgTextPosition) const; + void whiteSpaceHandling(); + void concatenate(std::u16string_view rText); + + /// Text content + const OUString& getText() const { return maText; } + }; + +} // end of namespace svgio::svgreader + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgcirclenode.hxx b/svgio/inc/svgcirclenode.hxx new file mode 100644 index 000000000..fa699d82c --- /dev/null +++ b/svgio/inc/svgcirclenode.hxx @@ -0,0 +1,66 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgCircleNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + SvgNumber maCx; + SvgNumber maCy; + SvgNumber maR; + std::optional<basegfx::B2DHomMatrix> mpaTransform; + + public: + SvgCircleNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgCircleNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// Cx content, set if found in current context + const SvgNumber& getCx() const { return maCx; } + + /// Cy content, set if found in current context + const SvgNumber& getCy() const { return maCy; } + + /// R content, set if found in current context + const SvgNumber& getR() const { return maR; } + + /// transform content, set if found in current context + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgclippathnode.hxx b/svgio/inc/svgclippathnode.hxx new file mode 100644 index 000000000..fc2951379 --- /dev/null +++ b/svgio/inc/svgclippathnode.hxx @@ -0,0 +1,64 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgClipPathNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::optional<basegfx::B2DHomMatrix> mpaTransform; + SvgUnits maClipPathUnits; + + public: + SvgClipPathNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgClipPathNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// apply contained clipPath to given geometry #i124852# transform may be needed + void apply( + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const std::optional<basegfx::B2DHomMatrix>& pTransform) const; + + /// clipPathUnits content + SvgUnits getClipPathUnits() const { return maClipPathUnits; } + void setClipPathUnits(const SvgUnits aClipPathUnits) { maClipPathUnits = aClipPathUnits; } + + /// transform content + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgdocument.hxx b/svgio/inc/svgdocument.hxx new file mode 100644 index 000000000..ef7817284 --- /dev/null +++ b/svgio/inc/svgdocument.hxx @@ -0,0 +1,79 @@ +/* -*- 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 "svgnode.hxx" +#include <memory> +#include <unordered_map> +#include <vector> + +namespace svgio::svgreader + { + typedef std::vector< std::unique_ptr<SvgNode> > SvgNodeVector; + + class SvgDocument + { + private: + /// the document hierarchy with all root nodes + SvgNodeVector maNodes; + + /// the absolute path of the Svg file in progress (if available) + const OUString maAbsolutePath; + + /// hash mapper to find nodes by their id + typedef std::unordered_map< OUString, const SvgNode* > IdTokenMapper; + IdTokenMapper maIdTokenMapperList; + + /// hash mapper to find css styles by their id + typedef std::unordered_map< OUString, const SvgStyleAttributes* > IdStyleTokenMapper; + IdStyleTokenMapper maIdStyleTokenMapperList; + + public: + explicit SvgDocument(const OUString& rAbsolutePath); + ~SvgDocument(); + + SvgDocument(const SvgDocument&) = delete; + SvgDocument& operator=(const SvgDocument&) = delete; + + /// append another root node, ownership changes + void appendNode(std::unique_ptr<SvgNode> pNode); + + /// add/remove nodes with Id to mapper + void addSvgNodeToMapper(const OUString& rStr, const SvgNode& rNode); + void removeSvgNodeFromMapper(const OUString& rStr); + + /// find a node by its Id + const SvgNode* findSvgNodeById(const OUString& rStr) const; + + /// add/remove styles to mapper + void addSvgStyleAttributesToMapper(const OUString& rStr, const SvgStyleAttributes& rSvgStyleAttributes); + + /// find a style by its Id + bool hasGlobalCssStyleAttributes() const { return !maIdStyleTokenMapperList.empty(); } + const SvgStyleAttributes* findGlobalCssStyleAttributes(const OUString& rStr) const; + + /// data read access + const SvgNodeVector& getSvgNodeVector() const { return maNodes; } + const OUString& getAbsolutePath() const { return maAbsolutePath; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgdocumenthandler.hxx b/svgio/inc/svgdocumenthandler.hxx new file mode 100644 index 000000000..197c9e8e8 --- /dev/null +++ b/svgio/inc/svgdocumenthandler.hxx @@ -0,0 +1,63 @@ +/* -*- 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 <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include "svgdocument.hxx" +#include <cppuhelper/implbase.hxx> + +namespace svgio::svgreader { class SvgCharacterNode; } + +namespace svgio::svgreader + { + class SvgDocHdl final : public cppu::WeakImplHelper< css::xml::sax::XDocumentHandler > + { + private: + // the complete SVG Document + SvgDocument maDocument; + + // current node for parsing + SvgNode* mpTarget; + + // text collector string stack for css styles + std::vector< OUString > maCssContents; + + bool bSkip; + + public: + SvgDocHdl(const OUString& rAbsolutePath); + virtual ~SvgDocHdl() override; + + // Methods XDocumentHandler + virtual void SAL_CALL startDocument( ) override; + virtual void SAL_CALL endDocument( ) override; + virtual void SAL_CALL startElement( const OUString& aName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs ) override; + virtual void SAL_CALL endElement( const OUString& aName ) override; + virtual void SAL_CALL characters( const OUString& aChars ) override; + virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override; + virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) override; + virtual void SAL_CALL setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override; + + const SvgDocument& getSvgDocument() const { return maDocument; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgellipsenode.hxx b/svgio/inc/svgellipsenode.hxx new file mode 100644 index 000000000..f0ba640d2 --- /dev/null +++ b/svgio/inc/svgellipsenode.hxx @@ -0,0 +1,70 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgEllipseNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + SvgNumber maCx; + SvgNumber maCy; + SvgNumber maRx; + SvgNumber maRy; + std::optional<basegfx::B2DHomMatrix> mpaTransform; + + public: + SvgEllipseNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgEllipseNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// Cx content, set if found in current context + const SvgNumber& getCx() const { return maCx; } + + /// Cy content, set if found in current context + const SvgNumber& getCy() const { return maCy; } + + /// Rx content, set if found in current context + const SvgNumber& getRx() const { return maRx; } + + /// Ry content, set if found in current context + const SvgNumber& getRy() const { return maRy; } + + /// transform content, set if found in current context + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svggnode.hxx b/svgio/inc/svggnode.hxx new file mode 100644 index 000000000..0ba03a1d0 --- /dev/null +++ b/svgio/inc/svggnode.hxx @@ -0,0 +1,55 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgGNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::optional<basegfx::B2DHomMatrix> mpaTransform; + + public: + SvgGNode( + SVGToken aType, + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgGNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// transform content + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svggradientnode.hxx b/svgio/inc/svggradientnode.hxx new file mode 100644 index 000000000..605ac6f4e --- /dev/null +++ b/svgio/inc/svggradientnode.hxx @@ -0,0 +1,118 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include "svgtools.hxx" +#include <drawinglayer/primitive2d/svggradientprimitive2d.hxx> + +namespace svgio::svgreader + { + class SvgGradientNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// linear gradient values + SvgNumber maX1; + SvgNumber maY1; + SvgNumber maX2; + SvgNumber maY2; + + /// radial gradient values + SvgNumber maCx; + SvgNumber maCy; + SvgNumber maR; + SvgNumber maFx; + SvgNumber maFy; + + /// variable scan values, dependent of given XAttributeList + SvgUnits maGradientUnits; + drawinglayer::primitive2d::SpreadMethod maSpreadMethod; + std::optional<basegfx::B2DHomMatrix> mpaGradientTransform; + + /// link to another gradient used as style. If maXLink + /// is set, the node can be fetched on demand by using + // tryToFindLink (buffered) + mutable bool mbResolvingLink; // protect against infinite link recursion + OUString maXLink; + const SvgGradientNode* mpXLink; + + /// link on demand + void tryToFindLink(); + + public: + SvgGradientNode( + SVGToken aType, + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgGradientNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + + /// collect gradient stop entries + void collectGradientEntries(drawinglayer::primitive2d::SvgGradientEntryVector& aVector) const; + + /// x1 content + SvgNumber getX1() const; + + /// y1 content + SvgNumber getY1() const; + + /// x2 content + SvgNumber getX2() const; + + /// y2 content + SvgNumber getY2() const; + + /// Cx content + SvgNumber getCx() const; + + /// Cy content + SvgNumber getCy() const; + + /// R content + SvgNumber getR() const; + + /// Fx content + const SvgNumber* getFx() const; + + /// Fy content + const SvgNumber* getFy() const; + + /// gradientUnits content + SvgUnits getGradientUnits() const { return maGradientUnits; } + void setGradientUnits(const SvgUnits aGradientUnits) { maGradientUnits = aGradientUnits; } + + /// SpreadMethod content + drawinglayer::primitive2d::SpreadMethod getSpreadMethod() const { return maSpreadMethod; } + void setSpreadMethod(const drawinglayer::primitive2d::SpreadMethod aSpreadMethod) { maSpreadMethod = aSpreadMethod; } + + /// transform content, set if found in current context + std::optional<basegfx::B2DHomMatrix> getGradientTransform() const; + void setGradientTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaGradientTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svggradientstopnode.hxx b/svgio/inc/svggradientstopnode.hxx new file mode 100644 index 000000000..ea2bbec7f --- /dev/null +++ b/svgio/inc/svggradientstopnode.hxx @@ -0,0 +1,51 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" + +namespace svgio::svgreader + { + class SvgGradientStopNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// local attributes + SvgNumber maOffset; + + public: + SvgGradientStopNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgGradientStopNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + + /// offset content + const SvgNumber& getOffset() const { return maOffset; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgimagenode.hxx b/svgio/inc/svgimagenode.hxx new file mode 100644 index 000000000..171a863d8 --- /dev/null +++ b/svgio/inc/svgimagenode.hxx @@ -0,0 +1,78 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgImageNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + SvgAspectRatio maSvgAspectRatio; + std::optional<basegfx::B2DHomMatrix> + mpaTransform; + SvgNumber maX; + SvgNumber maY; + SvgNumber maWidth; + SvgNumber maHeight; + + OUString maXLink; // internal link + OUString maUrl; // external link + + OUString maMimeType; // mimetype and + OUString maData; // base64 data + + public: + SvgImageNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgImageNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// transform content, set if found in current context + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + + /// x content, set if found in current context + const SvgNumber& getX() const { return maX; } + + /// y content, set if found in current context + const SvgNumber& getY() const { return maY; } + + /// width content, set if found in current context + const SvgNumber& getWidth() const { return maWidth; } + + /// height content, set if found in current context + const SvgNumber& getHeight() const { return maHeight; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svglinenode.hxx b/svgio/inc/svglinenode.hxx new file mode 100644 index 000000000..28137303e --- /dev/null +++ b/svgio/inc/svglinenode.hxx @@ -0,0 +1,70 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgLineNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + SvgNumber maX1; + SvgNumber maY1; + SvgNumber maX2; + SvgNumber maY2; + std::optional<basegfx::B2DHomMatrix> mpaTransform; + + public: + SvgLineNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgLineNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// X1 content, set if found in current context + const SvgNumber& getX1() const { return maX1; } + + /// Y1 content, set if found in current context + const SvgNumber& getY1() const { return maY1; } + + /// X2 content, set if found in current context + const SvgNumber& getX2() const { return maX2; } + + /// Y2 content, set if found in current context + const SvgNumber& getY2() const { return maY2; } + + /// transform content, set if found in current context + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgmarkernode.hxx b/svgio/inc/svgmarkernode.hxx new file mode 100644 index 000000000..3f4b08791 --- /dev/null +++ b/svgio/inc/svgmarkernode.hxx @@ -0,0 +1,113 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <memory> + +namespace svgio::svgreader + { + class SvgMarkerNode final : public SvgNode + { + public: + enum class MarkerUnits + { + strokeWidth, + userSpaceOnUse + }; + + enum class MarkerOrient + { + notset, + auto_start, + auto_start_reverse + }; + + private: + /// buffered decomposition + drawinglayer::primitive2d::Primitive2DContainer aPrimitives; + + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::unique_ptr<basegfx::B2DRange> + mpViewBox; + SvgAspectRatio maSvgAspectRatio; + SvgNumber maRefX; + SvgNumber maRefY; + MarkerUnits maMarkerUnits; + SvgNumber maMarkerWidth; + SvgNumber maMarkerHeight; + double mfAngle; + MarkerOrient maMarkerOrient; + + public: + SvgMarkerNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgMarkerNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + + /// get marker primitives buffered, uses decomposeSvgNode internally + const drawinglayer::primitive2d::Primitive2DContainer& getMarkerPrimitives() const; + + /// InfoProvider support for % values + virtual basegfx::B2DRange getCurrentViewPort() const override; + + /// viewBox content + const basegfx::B2DRange* getViewBox() const { return mpViewBox.get(); } + void setViewBox(const basegfx::B2DRange* pViewBox) { mpViewBox.reset(); if(pViewBox) mpViewBox.reset( new basegfx::B2DRange(*pViewBox) ); } + + /// SvgAspectRatio content + const SvgAspectRatio& getSvgAspectRatio() const { return maSvgAspectRatio; } + + /// RefX content, set if found in current context + const SvgNumber& getRefX() const { return maRefX; } + + /// RefY content, set if found in current context + const SvgNumber& getRefY() const { return maRefY; } + + /// MarkerUnits content + MarkerUnits getMarkerUnits() const { return maMarkerUnits; } + void setMarkerUnits(const MarkerUnits aMarkerUnits) { maMarkerUnits = aMarkerUnits; } + + /// MarkerWidth content, set if found in current context + const SvgNumber& getMarkerWidth() const { return maMarkerWidth; } + + /// MarkerHeight content, set if found in current context + const SvgNumber& getMarkerHeight() const { return maMarkerHeight; } + + /// Angle content, set if found in current context + double getAngle() const { return mfAngle; } + void setAngle(double fAngle) { mfAngle = fAngle;} + + /// MarkerOrient content + MarkerOrient getMarkerOrient() const { return maMarkerOrient; } + void setMarkerOrient(const MarkerOrient aMarkerOrient) { maMarkerOrient = aMarkerOrient; } + + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgmasknode.hxx b/svgio/inc/svgmasknode.hxx new file mode 100644 index 000000000..641a9fe1a --- /dev/null +++ b/svgio/inc/svgmasknode.hxx @@ -0,0 +1,84 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgMaskNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + SvgNumber maX; + SvgNumber maY; + SvgNumber maWidth; + SvgNumber maHeight; + std::optional<basegfx::B2DHomMatrix> + mpaTransform; + SvgUnits maMaskUnits; + SvgUnits maMaskContentUnits; + + public: + SvgMaskNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgMaskNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// apply contained clipPath to given geometry #i124852# transform may be needed + void apply( + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const std::optional<basegfx::B2DHomMatrix>& pTransform) const; + + /// x content, set if found in current context + const SvgNumber& getX() const { return maX; } + + /// y content, set if found in current context + const SvgNumber& getY() const { return maY; } + + /// width content, set if found in current context + const SvgNumber& getWidth() const { return maWidth; } + + /// height content, set if found in current context + const SvgNumber& getHeight() const { return maHeight; } + + /// transform content + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + + /// MaskUnits content + void setMaskUnits(const SvgUnits aMaskUnits) { maMaskUnits = aMaskUnits; } + + /// MaskContentUnits content + void setMaskContentUnits(const SvgUnits aMaskContentUnits) { maMaskContentUnits = aMaskContentUnits; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx new file mode 100644 index 000000000..54016aa34 --- /dev/null +++ b/svgio/inc/svgnode.hxx @@ -0,0 +1,194 @@ +/* -*- 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 "SvgNumber.hxx" +#include "svgtoken.hxx" +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <drawinglayer/primitive2d/Primitive2DContainer.hxx> +#include <memory> +#include <string_view> +#include <vector> +#include <optional> + +// predefines +namespace svgio::svgreader +{ + class SvgNode; + class SvgDocument; + class SvgStyleAttributes; +} + + + +namespace svgio::svgreader + { + enum class XmlSpace + { + NotSet, + Default, + Preserve + }; + + // display property (see SVG 1.1. 11.5), not inheritable + enum class Display // #i121656# + { + Inline, // the default + Block, + ListItem, + RunIn, + Compact, + Marker, + Table, + InlineTable, + TableRowGroup, + TableHeaderGroup, + TableFooterGroup, + TableRow, + TableColumnGroup, + TableColumn, + TableCell, + TableCaption, + None, + Inherit + }; + + // helper to convert a string associated with a token of type SVGTokenDisplay + // to the enum Display. Empty strings return the default 'Display_inline' with + // which members should be initialized + Display getDisplayFromContent(std::u16string_view aContent); + + class Visitor; + + class SvgNode : public InfoProvider + { + private: + /// basic data, Type, document we belong to and parent (if not root) + SVGToken maType; + SvgDocument& mrDocument; + const SvgNode* mpParent; + const SvgNode* mpAlternativeParent; + + /// sub hierarchy + std::vector< std::unique_ptr<SvgNode> > maChildren; + + /// Id svan value + std::optional<OUString> mpId; + + /// Class svan value + std::optional<OUString> mpClass; + + /// XmlSpace value + XmlSpace maXmlSpace; + + /// Display value #i121656# + Display maDisplay; + + // CSS style vector chain, used in decompose phase and built up once per node. + // It contains the StyleHierarchy for the local node. Independent from the + // node hierarchy itself which also needs to be used in style entry solving + ::std::vector< const SvgStyleAttributes* > maCssStyleVector; + + /// possible local CssStyle, e.g. style="fill:red; stroke:red;" + std::unique_ptr<SvgStyleAttributes> mpLocalCssStyle; + + mutable bool mbDecomposing; + + // flag if maCssStyleVector is already computed (done only once) + bool mbCssStyleVectorBuilt : 1; + + protected: + /// helper to evtl. link to css style + const SvgStyleAttributes* checkForCssStyle(const OUString& rClassStr, const SvgStyleAttributes& rOriginal) const; + + /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt + void fillCssStyleVector(const OUString& rClassStr, const SvgStyleAttributes& rOriginal); + void fillCssStyleVectorUsingHierarchyAndSelectors( + const OUString& rClassStr, + const SvgNode& rCurrent, + const OUString& aConcatenated); + + public: + SvgNode( + SVGToken aType, + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgNode() override; + SvgNode(const SvgNode&) = delete; + SvgNode& operator=(const SvgNode&) = delete; + + void accept(Visitor& rVisitor); + + /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle + void readLocalCssStyle(const OUString& aContent); + + /// style helpers + void parseAttributes(const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs); + virtual const SvgStyleAttributes* getSvgStyleAttributes() const; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent); + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const; + + /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not) + virtual bool supportsParentStyle() const; + + /// basic data read access + SVGToken getType() const { return maType; } + const SvgDocument& getDocument() const { return mrDocument; } + const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; } + const std::vector< std::unique_ptr<SvgNode> > & getChildren() const { return maChildren; } + + /// InfoProvider support for %, em and ex values + virtual basegfx::B2DRange getCurrentViewPort() const override; + virtual double getCurrentFontSizeInherited() const override; + virtual double getCurrentXHeightInherited() const override; + + double getCurrentFontSize() const; + double getCurrentXHeight() const; + + /// Id access + std::optional<OUString> const & getId() const { return mpId; } + void setId(OUString const &); + + /// Class access + std::optional<OUString> const & getClass() const { return mpClass; } + void setClass(OUString const &); + + /// XmlSpace access + XmlSpace getXmlSpace() const; + void setXmlSpace(XmlSpace eXmlSpace) { maXmlSpace = eXmlSpace; } + + /// Display access #i121656# + Display getDisplay() const { return maDisplay; } + void setDisplay(Display eDisplay) { maDisplay = eDisplay; } + + /// alternative parent + void setAlternativeParent(const SvgNode* pAlternativeParent = nullptr) { mpAlternativeParent = pAlternativeParent; } + }; + + class Visitor + { + public: + virtual ~Visitor() = default; + virtual void visit(SvgNode const & pNode) = 0; + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgpaint.hxx b/svgio/inc/svgpaint.hxx new file mode 100644 index 000000000..ad1c232df --- /dev/null +++ b/svgio/inc/svgpaint.hxx @@ -0,0 +1,52 @@ +/* -*- 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 <basegfx/color/bcolor.hxx> + +namespace svgio::svgreader + { + class SvgPaint + { + private: + basegfx::BColor maColor; + + bool mbSet : 1; + bool mbOn : 1; + bool mbCurrent : 1; + + public: + SvgPaint(const basegfx::BColor& rColor = basegfx::BColor(0.0, 0.0, 0.0), bool bSet = false, bool bOn = false, bool bCurrent = false) + : maColor(rColor), + mbSet(bSet), + mbOn(bOn), + mbCurrent(bCurrent) + { + } + + const basegfx::BColor& getBColor() const { return maColor; } + bool isSet() const { return mbSet; } + bool isOn() const { return mbOn; } + bool isCurrent() const { return mbCurrent; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgpathnode.hxx b/svgio/inc/svgpathnode.hxx new file mode 100644 index 000000000..bc962691f --- /dev/null +++ b/svgio/inc/svgpathnode.hxx @@ -0,0 +1,67 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <optional> + +namespace svgio::svgreader + { + class SvgPathNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::optional<basegfx::B2DPolyPolygon> mpPolyPolygon; + std::optional<basegfx::B2DHomMatrix> mpaTransform; + SvgNumber maPathLength; + basegfx::utils::PointIndexSet maHelpPointIndices; + + public: + SvgPathNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgPathNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// path content, set if found in current context + const std::optional<basegfx::B2DPolyPolygon>& getPath() const { return mpPolyPolygon; } + void setPath(const std::optional<basegfx::B2DPolyPolygon>& pPath) { mpPolyPolygon = pPath; } + + /// transform content, set if found in current context + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + + /// PathLength content + const SvgNumber& getPathLength() const { return maPathLength; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgpatternnode.hxx b/svgio/inc/svgpatternnode.hxx new file mode 100644 index 000000000..60c6b7f7c --- /dev/null +++ b/svgio/inc/svgpatternnode.hxx @@ -0,0 +1,116 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <memory> + +namespace svgio::svgreader + { + class SvgPatternNode final : public SvgNode + { + private: + /// buffered decomposition + drawinglayer::primitive2d::Primitive2DContainer aPrimitives; + + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::unique_ptr<basegfx::B2DRange> + mpViewBox; + SvgAspectRatio maSvgAspectRatio; + SvgNumber maX; + SvgNumber maY; + SvgNumber maWidth; + SvgNumber maHeight; + std::unique_ptr<SvgUnits> + mpPatternUnits; + std::unique_ptr<SvgUnits> + mpPatternContentUnits; + std::optional<basegfx::B2DHomMatrix> + mpaPatternTransform; + + /// link to another pattern used as style. If maXLink + /// is set, the node can be fetched on demand by using + // tryToFindLink (buffered) + mutable bool mbResolvingLink; // protect against infinite link recursion + OUString maXLink; + const SvgPatternNode* mpXLink; + + /// link on demand + void tryToFindLink(); + + public: + SvgPatternNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgPatternNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + + /// global helpers + void getValuesRelative(double& rfX, double& rfY, double& rfW, double& rfH, const basegfx::B2DRange& rGeoRange, SvgNode const & rUser) const; + + /// get pattern primitives buffered, uses decomposeSvgNode internally + const drawinglayer::primitive2d::Primitive2DContainer& getPatternPrimitives() const; + + /// InfoProvider support for % values + virtual basegfx::B2DRange getCurrentViewPort() const override; + + /// viewBox content + const basegfx::B2DRange* getViewBox() const; + void setViewBox(const basegfx::B2DRange* pViewBox) { mpViewBox.reset(); if(pViewBox) mpViewBox.reset(new basegfx::B2DRange(*pViewBox)); } + + /// SvgAspectRatio content + const SvgAspectRatio& getSvgAspectRatio() const; + + /// X content, set if found in current context + const SvgNumber& getX() const; + + /// Y content, set if found in current context + const SvgNumber& getY() const; + + /// Width content, set if found in current context + const SvgNumber& getWidth() const; + + /// Height content, set if found in current context + const SvgNumber& getHeight() const; + + /// PatternUnits content + const SvgUnits* getPatternUnits() const; + void setPatternUnits(const SvgUnits aPatternUnits) { mpPatternUnits.reset( new SvgUnits(aPatternUnits) ); } + + /// PatternContentUnits content + const SvgUnits* getPatternContentUnits() const; + void setPatternContentUnits(const SvgUnits aPatternContentUnits) { mpPatternContentUnits.reset( new SvgUnits(aPatternContentUnits) ); } + + /// PatternTransform content + std::optional<basegfx::B2DHomMatrix> getPatternTransform() const; + void setPatternTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaPatternTransform = pMatrix; } + + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgpolynode.hxx b/svgio/inc/svgpolynode.hxx new file mode 100644 index 000000000..fd356cd55 --- /dev/null +++ b/svgio/inc/svgpolynode.hxx @@ -0,0 +1,63 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <optional> + +namespace svgio::svgreader + { + class SvgPolyNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::optional<basegfx::B2DPolygon> mpPolygon; + std::optional<basegfx::B2DHomMatrix> mpaTransform; + + bool mbIsPolyline : 1; // true = polyline, false = polygon + + public: + SvgPolyNode( + SvgDocument& rDocument, + SvgNode* pParent, + bool bIsPolyline); + virtual ~SvgPolyNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// Polygon content, set if found in current context + void setPolygon(const std::optional<basegfx::B2DPolygon>& pPolygon) { mpPolygon = pPolygon; } + + /// transform content, set if found in current context + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgrectnode.hxx b/svgio/inc/svgrectnode.hxx new file mode 100644 index 000000000..5b1dc5bb6 --- /dev/null +++ b/svgio/inc/svgrectnode.hxx @@ -0,0 +1,78 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgRectNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + SvgNumber maX; + SvgNumber maY; + SvgNumber maWidth; + SvgNumber maHeight; + SvgNumber maRx; + SvgNumber maRy; + std::optional<basegfx::B2DHomMatrix> mpaTransform; + + public: + SvgRectNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgRectNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// x content, set if found in current context + const SvgNumber& getX() const { return maX; } + + /// y content, set if found in current context + const SvgNumber& getY() const { return maY; } + + /// width content, set if found in current context + const SvgNumber& getWidth() const { return maWidth; } + + /// height content, set if found in current context + const SvgNumber& getHeight() const { return maHeight; } + + /// Rx content, set if found in current context + const SvgNumber& getRx() const { return maRx; } + + /// Ry content, set if found in current context + const SvgNumber& getRy() const { return maRy; } + + /// transform content, set if found in current context + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx new file mode 100644 index 000000000..0ec531868 --- /dev/null +++ b/svgio/inc/svgstyleattributes.hxx @@ -0,0 +1,445 @@ +/* -*- 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 "svgpaint.hxx" +#include "svgnode.hxx" +#include "svgtools.hxx" +#include <tools/fontenum.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> +#include <drawinglayer/primitive2d/Primitive2DContainer.hxx> + + +// predefines + +namespace svgio::svgreader { + class SvgGradientNode; + class SvgPatternNode; + class SvgMarkerNode; + class SvgClipPathNode; + class SvgMaskNode; +} + + +namespace svgio::svgreader + { + enum class StrokeLinecap + { + notset, + butt, + round, + square + }; + + enum class StrokeLinejoin + { + notset, + miter, + round, + bevel + }; + + enum class FontSize + { + notset, + xx_small, + x_small, + small, + smaller, + medium, + large, + larger, + x_large, + xx_large, + initial + }; + + enum class FontStretch + { + notset, + normal, + wider, + narrower, + ultra_condensed, + extra_condensed, + condensed, + semi_condensed, + semi_expanded, + expanded, + extra_expanded, + ultra_expanded + }; + + FontStretch getWider(FontStretch aSource); + FontStretch getNarrower(FontStretch aSource); + + enum class FontStyle + { + notset, + normal, + italic, + oblique + }; + + enum class FontWeight + { + notset, + N100, + N200, + N300, + N400, // same as normal + N500, + N600, + N700, // same as bold + N800, + N900, + bolder, + lighter, + }; + + FontWeight getBolder(FontWeight aSource); + FontWeight getLighter(FontWeight aSource); + ::FontWeight getVclFontWeight(FontWeight aSource); + + enum class TextAlign + { + notset, + left, + right, + center, + justify + }; + + enum class TextDecoration + { + notset, + none, + underline, + overline, + line_through, + blink + }; + + enum class TextAnchor + { + notset, + start, + middle, + end + }; + + enum class FillRule + { + notset, + nonzero, + evenodd + }; + + enum class BaselineShift + { + Baseline, + Sub, + Super, + Percentage, + Length + }; + + enum class Visibility + { + notset, + visible, + hidden, + collapse, + inherit + }; + + class SvgStyleAttributes + { + private: + SvgNode& mrOwner; + const SvgStyleAttributes* mpCssStyleParent; + SvgPaint maFill; + SvgPaint maStroke; + SvgPaint maStopColor; + SvgNumber maStrokeWidth; + SvgNumber maStopOpacity; + SvgNumber maFillOpacity; + SvgNumberVector maStrokeDasharray; + SvgNumber maStrokeDashOffset; + StrokeLinecap maStrokeLinecap; + StrokeLinejoin maStrokeLinejoin; + SvgNumber maStrokeMiterLimit; + SvgNumber maStrokeOpacity; + SvgStringVector maFontFamily; + FontSize maFontSize; + SvgNumber maFontSizeNumber; + FontStretch maFontStretch; + FontStyle maFontStyle; + FontWeight maFontWeight; + TextAlign maTextAlign; + TextDecoration maTextDecoration; + TextAnchor maTextAnchor; + SvgPaint maColor; + SvgNumber maOpacity; + Visibility maVisibility; + OUString maTitle; + OUString maDesc; + + /// link to content. If set, the node can be fetched on demand + OUString maClipPathXLink; + const SvgClipPathNode* mpClipPathXLink; + OUString maMaskXLink; + const SvgMaskNode* mpMaskXLink; + + /// link to markers. If set, the node can be fetched on demand + OUString maMarkerStartXLink; + const SvgMarkerNode* mpMarkerStartXLink; + OUString maMarkerMidXLink; + const SvgMarkerNode* mpMarkerMidXLink; + OUString maMarkerEndXLink; + const SvgMarkerNode* mpMarkerEndXLink; + + /// fill rule + FillRule maFillRule; + + // ClipRule setting (only valid when mbIsClipPathContent == true, default is FillRule_nonzero) + FillRule maClipRule; + + // BaselineShift: Type and number (in case of BaselineShift_Percentage or BaselineShift_Length) + BaselineShift maBaselineShift; + SvgNumber maBaselineShiftNumber; + + mutable std::vector<sal_uInt16> maResolvingParent; + + // defines if this attributes are part of a ClipPath. If yes, + // rough geometry will be created on decomposition by patching + // values for fill, stroke, strokeWidth and others + bool mbIsClipPathContent : 1; + + // #121221# Defines if evtl. an empty array *is* set + bool mbStrokeDasharraySet : 1; + + // tdf#94765 Check id references in gradient/pattern getters + OUString maNodeFillURL; + OUString maNodeStrokeURL; + + /// internal helpers + void add_fillGradient( + const basegfx::B2DPolyPolygon& rPath, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const SvgGradientNode& rFillGradient, + const basegfx::B2DRange& rGeoRange) const; + void add_fillPatternTransform( + const basegfx::B2DPolyPolygon& rPath, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const SvgPatternNode& rFillGradient, + const basegfx::B2DRange& rGeoRange) const; + void add_fillPattern( + const basegfx::B2DPolyPolygon& rPath, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const SvgPatternNode& rFillGradient, + const basegfx::B2DRange& rGeoRange) const; + void add_fill( + const basegfx::B2DPolyPolygon& rPath, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const basegfx::B2DRange& rGeoRange) const; + void add_stroke( + const basegfx::B2DPolyPolygon& rPath, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const basegfx::B2DRange& rGeoRange) const; + bool prepare_singleMarker( + drawinglayer::primitive2d::Primitive2DContainer& rMarkerPrimitives, + basegfx::B2DHomMatrix& rMarkerTransform, + basegfx::B2DRange& rClipRange, + const SvgMarkerNode& rMarker) const; + void add_markers( + const basegfx::B2DPolyPolygon& rPath, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const basegfx::utils::PointIndexSet* pHelpPointIndices) const; + + + public: + /// local attribute scanner + void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent, + bool bCaseIndependent); + + /// helper which does the necessary with a given path + void add_text( + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + drawinglayer::primitive2d::Primitive2DContainer&& rSource) const; + void add_path( + const basegfx::B2DPolyPolygon& rPath, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const basegfx::utils::PointIndexSet* pHelpPointIndices) const; + void add_postProcess( + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + drawinglayer::primitive2d::Primitive2DContainer&& rSource, + const std::optional<basegfx::B2DHomMatrix>& pTransform) const; + + /// helper to set mpCssStyleParent temporarily for CSS style hierarchies + void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; } + const SvgStyleAttributes* getCssStyleParent() const { return mpCssStyleParent; } + + /// scan helpers + void readCssStyle(const OUString& rCandidate); + const SvgStyleAttributes* getParentStyle() const; + + SvgStyleAttributes(SvgNode& rOwner); + ~SvgStyleAttributes(); + + /// fill content + bool isFillSet() const; // #i125258# ask if fill is a direct hard attribute (no hierarchy) + const basegfx::BColor* getFill() const; + void setFill(const SvgPaint& rFill) { maFill = rFill; } + + /// stroke content + const basegfx::BColor* getStroke() const; + + /// stop color content + const basegfx::BColor& getStopColor() const; + + /// stroke-width content + SvgNumber getStrokeWidth() const; + + /// stop opacity content + SvgNumber getStopOpacity() const; + + /// access to evtl. set fill gradient + const SvgGradientNode* getSvgGradientNodeFill() const; + + /// access to evtl. set fill pattern + const SvgPatternNode* getSvgPatternNodeFill() const; + + /// access to evtl. set stroke gradient + const SvgGradientNode* getSvgGradientNodeStroke() const; + + /// access to evtl. set stroke pattern + const SvgPatternNode* getSvgPatternNodeStroke() const; + + /// fill opacity content + SvgNumber getFillOpacity() const; + + /// fill rule content + FillRule getFillRule() const; + + /// clip rule content + FillRule getClipRule() const; + + /// fill StrokeDasharray content + const SvgNumberVector& getStrokeDasharray() const; + + /// StrokeDashOffset content + SvgNumber getStrokeDashOffset() const; + + /// StrokeLinecap content + StrokeLinecap getStrokeLinecap() const; + void setStrokeLinecap(const StrokeLinecap aStrokeLinecap) { maStrokeLinecap = aStrokeLinecap; } + + /// StrokeLinejoin content + StrokeLinejoin getStrokeLinejoin() const; + void setStrokeLinejoin(const StrokeLinejoin aStrokeLinejoin) { maStrokeLinejoin = aStrokeLinejoin; } + + /// StrokeMiterLimit content + SvgNumber getStrokeMiterLimit() const; + + /// StrokeOpacity content + SvgNumber getStrokeOpacity() const; + + /// Font content + const SvgStringVector& getFontFamily() const; + + /// FontSize content + void setFontSize(const FontSize aFontSize) { maFontSize = aFontSize; } + SvgNumber getFontSizeNumber() const; + + /// FontStretch content + FontStretch getFontStretch() const; + void setFontStretch(const FontStretch aFontStretch) { maFontStretch = aFontStretch; } + + /// FontStyle content + FontStyle getFontStyle() const; + void setFontStyle(const FontStyle aFontStyle) { maFontStyle = aFontStyle; } + + /// FontWeight content + FontWeight getFontWeight() const; + void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; } + + /// TextAlign content + TextAlign getTextAlign() const; + void setTextAlign(const TextAlign aTextAlign) { maTextAlign = aTextAlign; } + + /// TextDecoration content + const SvgStyleAttributes* getTextDecorationDefiningSvgStyleAttributes() const; + TextDecoration getTextDecoration() const; + void setTextDecoration(const TextDecoration aTextDecoration) { maTextDecoration = aTextDecoration; } + + /// TextAnchor content + TextAnchor getTextAnchor() const; + void setTextAnchor(const TextAnchor aTextAnchor) { maTextAnchor = aTextAnchor; } + + /// Color content + const basegfx::BColor* getColor() const; + + /// Resolve current color (defaults to black if no color is specified) + const basegfx::BColor* getCurrentColor() const; + + /// Opacity content + SvgNumber getOpacity() const; + void setOpacity(const SvgNumber& rOpacity) { maOpacity = rOpacity; } + + /// Visibility + Visibility getVisibility() const; + void setVisibility(const Visibility aVisibility) { maVisibility = aVisibility; } + + // Title content + const OUString& getTitle() const { return maTitle; } + + // Desc content + const OUString& getDesc() const { return maDesc; } + + // ClipPathXLink content + OUString getClipPathXLink() const; + const SvgClipPathNode* accessClipPathXLink() const; + + // MaskXLink content + OUString getMaskXLink() const; + const SvgMaskNode* accessMaskXLink() const; + + // MarkerStartXLink content + OUString getMarkerStartXLink() const; + const SvgMarkerNode* accessMarkerStartXLink() const; + + // MarkerMidXLink content + OUString getMarkerMidXLink() const; + const SvgMarkerNode* accessMarkerMidXLink() const; + + // MarkerEndXLink content + OUString getMarkerEndXLink() const; + const SvgMarkerNode* accessMarkerEndXLink() const; + + // BaselineShift + void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; } + BaselineShift getBaselineShift() const { return maBaselineShift; } + SvgNumber getBaselineShiftNumber() const; + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgstylenode.hxx b/svgio/inc/svgstylenode.hxx new file mode 100644 index 000000000..1a5a43ca8 --- /dev/null +++ b/svgio/inc/svgstylenode.hxx @@ -0,0 +1,58 @@ +/* -*- 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 <unordered_map> +#include "svgnode.hxx" +#include "svgstyleattributes.hxx" + +namespace svgio::svgreader + { + class SvgStyleNode final : public SvgNode + { + private: + /// use styles + std::unordered_map< OUString, std::unique_ptr<SvgStyleAttributes> > maSvgStyleAttributes; + + bool mbTextCss : 1; // true == type is 'text/css' + + public: + SvgStyleNode( + SvgDocument& rDocument, + SvgNode* pParent); + + /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not) + virtual bool supportsParentStyle() const override; + + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + + /// CssStyleSheet add helpers + void addCssStyleSheet(const OUString& aSelectors, const SvgStyleAttributes& rNewStyle); + void addCssStyleSheet(const OUString& aSelectors, const OUString& aContent); + void addCssStyleSheet(const OUString& aSelectorsAndContent); + + /// textCss access + bool isTextCss() const { return mbTextCss; } + void setTextCss(bool bNew) { mbTextCss = bNew; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgsvgnode.hxx b/svgio/inc/svgsvgnode.hxx new file mode 100644 index 000000000..5fe92bd08 --- /dev/null +++ b/svgio/inc/svgsvgnode.hxx @@ -0,0 +1,93 @@ +/* -*- 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 "svgstyleattributes.hxx" +#include <memory> + +namespace svgio::svgreader + { + class SvgSvgNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::unique_ptr<basegfx::B2DRange> + mpViewBox; + SvgAspectRatio maSvgAspectRatio; + SvgNumber maX; + SvgNumber maY; + SvgNumber maWidth; + SvgNumber maHeight; + SvgNumber maVersion; + + /// #i125258# bitfield + bool mbStyleAttributesInitialized : 1; + + // #i125258# on-demand init hard attributes when this is the outmost svg element + // and more (see implementation) + void initializeStyleAttributes(); + + public: + SvgSvgNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgSvgNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// Seeks width and height of viewport, which is current before the new viewport is set. + // needed for percentage unit in x, y, width or height + void seekReferenceWidth(double& fWidth, bool& bHasFound) const; + void seekReferenceHeight(double& fHeight, bool& bHasFound) const; + + /// InfoProvider support for % values in children + // The returned 'CurrentViewPort' is the viewport as it is set by this svg element + // and as it is needed to resolve relative values in children + // The method does not check for invalid width and height + virtual basegfx::B2DRange getCurrentViewPort() const override; + + /// viewBox content + const basegfx::B2DRange* getViewBox() const { return mpViewBox.get(); } + void setViewBox(const basegfx::B2DRange* pViewBox) { mpViewBox.reset(); if(pViewBox) mpViewBox.reset( new basegfx::B2DRange(*pViewBox) ); } + + /// SvgAspectRatio content + const SvgAspectRatio& getSvgAspectRatio() const { return maSvgAspectRatio; } + + /// x content + const SvgNumber& getX() const { return maX; } + + /// y content + const SvgNumber& getY() const { return maY; } + + /// width content + const SvgNumber& getWidth() const { return maWidth; } + + /// height content + const SvgNumber& getHeight() const { return maHeight; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgsymbolnode.hxx b/svgio/inc/svgsymbolnode.hxx new file mode 100644 index 000000000..c0822e9be --- /dev/null +++ b/svgio/inc/svgsymbolnode.hxx @@ -0,0 +1,46 @@ +/* -*- 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 "svgstyleattributes.hxx" + +namespace svgio::svgreader + { + class SvgSymbolNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + SvgAspectRatio maSvgAspectRatio; + + public: + SvgSymbolNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgSymbolNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgtextnode.hxx b/svgio/inc/svgtextnode.hxx new file mode 100644 index 000000000..0cc78f130 --- /dev/null +++ b/svgio/inc/svgtextnode.hxx @@ -0,0 +1,67 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include "svgcharacternode.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> + +namespace svgio::svgreader + { + class SvgTextNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::optional<basegfx::B2DHomMatrix> + mpaTransform; + SvgTextPositions maSvgTextPositions; + + /// local helpers + void DecomposeChild( + const SvgNode& rCandidate, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + SvgTextPosition& rSvgTextPosition) const; + static void addTextPrimitives( + const SvgNode& rCandidate, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + drawinglayer::primitive2d::Primitive2DContainer&& rSource); + + public: + SvgTextNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgTextNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// transform content, set if found in current context + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgtextpathnode.hxx b/svgio/inc/svgtextpathnode.hxx new file mode 100644 index 000000000..bafd8e9e4 --- /dev/null +++ b/svgio/inc/svgtextpathnode.hxx @@ -0,0 +1,60 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" + +namespace svgio::svgreader + { + class SvgTextPathNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// link to path content. If maXLink + /// is set, the node can be fetched on demand + OUString maXLink; + + /// variable scan values, dependent of given XAttributeList + SvgNumber maStartOffset; + + public: + SvgTextPathNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgTextPathNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + void decomposePathNode( + const drawinglayer::primitive2d::Primitive2DContainer& rPathContent, + drawinglayer::primitive2d::Primitive2DContainer& rTarget, + const basegfx::B2DPoint& rTextStart) const; + bool isValid() const; + + /// StartOffset content + const SvgNumber& getStartOffset() const { return maStartOffset; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgtitledescnode.hxx b/svgio/inc/svgtitledescnode.hxx new file mode 100644 index 000000000..78394d81e --- /dev/null +++ b/svgio/inc/svgtitledescnode.hxx @@ -0,0 +1,52 @@ +/* -*- 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 <string_view> + +#include "svgnode.hxx" + + +namespace svgio::svgreader + { + class SvgTitleDescNode final : public SvgNode + { + private: + /// contained chars + OUString maText; + + public: + SvgTitleDescNode( + SVGToken aType, + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgTitleDescNode() override; + + /// add new chars + void concatenate(std::u16string_view rChars); + + /// x content, set if found in current context + const OUString& getText() const { return maText; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgtoken.hxx b/svgio/inc/svgtoken.hxx new file mode 100644 index 000000000..0a24d272b --- /dev/null +++ b/svgio/inc/svgtoken.hxx @@ -0,0 +1,190 @@ +/* -*- 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 <rtl/ustring.hxx> + +namespace svgio::svgreader + { + // SVG token mapper with hashing + enum class SVGToken + { + Unknown = 0, + + // diverse attribute tokens + Width, + Height, + ViewBox, + Transform, + Style, + Display, // #i121656# + D, + X, + Y, + Xmlns, + Version, + Id, + Rx, + Ry, + Points, + Dx, + Dy, + Rotate, + TextLength, + LengthAdjust, + Font, + FontFamily, + FontSize, + FontSizeAdjust, + FontStretch, + FontStyle, + FontVariant, + FontWeight, + Direction, + LetterSpacing, + TextDecoration, + UnicodeBidi, + WordSpacing, + Character, // not in the hash, just for simple text handling in SvgCharacterNode + Tspan, + Tref, + TextPath, + StartOffset, + Method, + Spacing, + TextAlign, + PathLength, + Type, + Class, + TextAnchor, + XmlSpace, + Color, + ClipPathNode, + ClipPathProperty, + Mask, + ClipPathUnits, + MaskUnits, + MaskContentUnits, + ClipRule, + Marker, + MarkerStart, + MarkerMid, + MarkerEnd, + RefX, + RefY, + MarkerUnits, + MarkerWidth, + MarkerHeight, + Orient, + Pattern, + PatternUnits, + PatternContentUnits, + PatternTransform, + Opacity, + Visibility, + Title, + Desc, + + // AspectRatio and params + PreserveAspectRatio, + Defer, + None, + XMinYMin, + XMidYMin, + XMaxYMin, + XMinYMid, + XMidYMid, + XMaxYMid, + XMinYMax, + XMidYMax, + XMaxYMax, + Meet, + Slice, + + // structural elements + Defs, + G, + Svg, + Symbol, + Use, + A, + + // shape elements + Circle, + Ellipse, + Line, + Path, + Polygon, + Polyline, + Rect, + Image, + + // gradient elements and tokens + LinearGradient, + RadialGradient, + Stop, + Offset, + X1, + Y1, + X2, + Y2, + Cx, + Cy, + Fx, + Fy, + R, + GradientUnits, + GradientTransform, + SpreadMethod, + Href, + XlinkHref, + StopColor, + StopOpacity, + + // fill tokens + Fill, + FillOpacity, + FillRule, + + // stroke tokens + Stroke, + StrokeDasharray, + StrokeDashoffset, + StrokeLinecap, + StrokeLinejoin, + StrokeMiterlimit, + StrokeOpacity, + StrokeWidth, + + // text tokens + Text, + BaselineShift, + + FlowRoot + }; + + SVGToken StrToSVGToken(const OUString& rStr, bool bCaseIndependent); + + OUString getStrTitle(); + OUString getStrDesc(); + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgtools.hxx b/svgio/inc/svgtools.hxx new file mode 100644 index 000000000..5effa7df3 --- /dev/null +++ b/svgio/inc/svgtools.hxx @@ -0,0 +1,137 @@ +/* -*- 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 <basegfx/color/bcolor.hxx> +#include <basegfx/range/b2drange.hxx> +#include <basegfx/vector/b2ivector.hxx> +#include <rtl/ustrbuf.hxx> +#include "svgpaint.hxx" +#include "SvgNumber.hxx" + +#include <string_view> +#include <vector> + + +namespace svgio::svgreader + { + // common non-token strings + struct commonStrings + { + static constexpr OUStringLiteral aStrUserSpaceOnUse = u"userSpaceOnUse"; + static constexpr OUStringLiteral aStrObjectBoundingBox = u"objectBoundingBox"; + static constexpr OUStringLiteral aStrNonzero = u"nonzero"; + static constexpr OUStringLiteral aStrEvenOdd = u"evenodd"; + }; + + enum class SvgUnits + { + userSpaceOnUse, + objectBoundingBox + }; + + enum class SvgAlign + { + none, + xMinYMin, + xMidYMin, + xMaxYMin, + xMinYMid, + xMidYMid, // default + xMaxYMid, + xMinYMax, + xMidYMax, + xMaxYMax + }; + + class SvgAspectRatio + { + private: + SvgAlign maSvgAlign; + + bool mbMeetOrSlice : 1; // true = meet (default), false = slice + bool mbSet : 1; + + public: + SvgAspectRatio() + : maSvgAlign(SvgAlign::xMidYMid), + mbMeetOrSlice(true), + mbSet(false) + { + } + + SvgAspectRatio(SvgAlign aSvgAlign, bool bMeetOrSlice) + : maSvgAlign(aSvgAlign), + mbMeetOrSlice(bMeetOrSlice), + mbSet(true) + { + } + + /// data read access + SvgAlign getSvgAlign() const { return maSvgAlign; } + bool isMeetOrSlice() const { return mbMeetOrSlice; } + bool isSet() const { return mbSet; } + + /// tooling + static basegfx::B2DHomMatrix createLinearMapping(const basegfx::B2DRange& rTarget, const basegfx::B2DRange& rSource); + basegfx::B2DHomMatrix createMapping(const basegfx::B2DRange& rTarget, const basegfx::B2DRange& rSource) const; + }; + + void skip_char(std::u16string_view rCandidate, sal_Unicode aChar, sal_Int32& nPos, const sal_Int32 nLen); + void skip_char(std::u16string_view rCandidate, sal_Unicode aCharA, sal_Unicode nCharB, sal_Int32& nPos, const sal_Int32 nLen); + void copySign(std::u16string_view rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen); + void copyNumber(std::u16string_view rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen); + void copyHex(std::u16string_view rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen); + void copyString(std::u16string_view rCandidate, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen); + void copyToLimiter(std::u16string_view rCandidate, sal_Unicode aLimiter, sal_Int32& nPos, OUStringBuffer& rTarget, const sal_Int32 nLen); + bool readNumber(std::u16string_view rCandidate, sal_Int32& nPos, double& fNum, const sal_Int32 nLen); + SvgUnit readUnit(std::u16string_view rCandidate, sal_Int32& nPos, const sal_Int32 nLen); + bool readNumberAndUnit(std::u16string_view rCandidate, sal_Int32& nPos, SvgNumber& aNum, const sal_Int32 nLen); + bool readAngle(std::u16string_view rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen); + sal_Int32 read_hex(sal_Unicode aChar); + bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName); + bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, SvgNumber& rOpacity); + basegfx::B2DRange readViewBox(const OUString& rCandidate, InfoProvider const & rInfoProvider); + basegfx::B2DHomMatrix readTransform(const OUString& rCandidate, InfoProvider const & rInfoProvider); + bool readSingleNumber(const OUString& rCandidate, SvgNumber& aNum); + bool readLocalUrl(const OUString& rCandidate, OUString& rURL); + bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, OUString& rURL, SvgNumber& rOpacity); + + bool readSvgNumberVector(const OUString& rCandidate, SvgNumberVector& rSvgNumberVector); + ::std::vector< double > solveSvgNumberVector(const SvgNumberVector& rInput, const InfoProvider& rInfoProvider); + + SvgAspectRatio readSvgAspectRatio(const OUString& rCandidate); + + typedef ::std::vector< OUString > SvgStringVector; + bool readSvgStringVector(const OUString& rCandidate, SvgStringVector& rSvgStringVector); + + void readImageLink(const OUString& rCandidate, OUString& rXLink, OUString& rUrl, OUString& rMimeType, OUString& rData); + + OUString convert(const OUString& rCandidate, sal_Unicode nPattern, sal_Unicode nNew, bool bRemove); + OUString consolidateContiguousSpace(const OUString& rCandidate); + OUString xmlSpaceHandling(const OUString& rCandidate, bool bIsDefault); + + // #125325# removes block comment of the general form '/* ... */', returns + // an adapted string or the original if no comments included + OUString removeBlockComments(const OUString& rCandidate); + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgtrefnode.hxx b/svgio/inc/svgtrefnode.hxx new file mode 100644 index 000000000..04fbb509c --- /dev/null +++ b/svgio/inc/svgtrefnode.hxx @@ -0,0 +1,53 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include "svgtextnode.hxx" + +namespace svgio::svgreader + { + class SvgTrefNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// link to text content. If maXLink + /// is set, the node can be fetched on demand + OUString maXLink; + + public: + SvgTrefNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgTrefNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + + /// access to referenced SvgTextNode + const SvgTextNode* getReferencedSvgTextNode() const; + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgtspannode.hxx b/svgio/inc/svgtspannode.hxx new file mode 100644 index 000000000..10a7b7ee1 --- /dev/null +++ b/svgio/inc/svgtspannode.hxx @@ -0,0 +1,53 @@ +/* -*- 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 "svgcharacternode.hxx" +#include "svgstyleattributes.hxx" + +namespace svgio::svgreader + { + class SvgTspanNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + SvgTextPositions maSvgTextPositions; + + public: + SvgTspanNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgTspanNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + + double getCurrentFontSize() const; + + /// access to SvgTextPositions + const SvgTextPositions& getSvgTextPositions() const { return maSvgTextPositions; } + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgusenode.hxx b/svgio/inc/svgusenode.hxx new file mode 100644 index 000000000..a672fb038 --- /dev/null +++ b/svgio/inc/svgusenode.hxx @@ -0,0 +1,73 @@ +/* -*- 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 "svgnode.hxx" +#include "svgstyleattributes.hxx" +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <optional> + +namespace svgio::svgreader + { + class SvgUseNode final : public SvgNode + { + private: + /// use styles + SvgStyleAttributes maSvgStyleAttributes; + + /// variable scan values, dependent of given XAttributeList + std::optional<basegfx::B2DHomMatrix> + mpaTransform; + SvgNumber maX; + SvgNumber maY; + SvgNumber maWidth; + SvgNumber maHeight; + + /// link to content. If maXLink is set, the node can be fetched + // on demand + OUString maXLink; + /// detect if maXLink causes a loop to ourself during decomposing + mutable bool mbDecomposingSvgNode; + + public: + SvgUseNode( + SvgDocument& rDocument, + SvgNode* pParent); + virtual ~SvgUseNode() override; + + virtual const SvgStyleAttributes* getSvgStyleAttributes() const override; + virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override; + virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override; + + /// transform content + const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; } + void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; } + + /// x content + const SvgNumber& getX() const { return maX; } + + /// y content + const SvgNumber& getY() const { return maY; } + + }; + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/inc/svgvisitor.hxx b/svgio/inc/svgvisitor.hxx new file mode 100644 index 000000000..2aa1f978f --- /dev/null +++ b/svgio/inc/svgvisitor.hxx @@ -0,0 +1,35 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <basegfx/DrawCommands.hxx> +#include <memory> +#include "svgnode.hxx" + +namespace svgio::svgreader +{ +class SvgDrawVisitor final : public Visitor +{ +private: + std::shared_ptr<gfx::DrawRoot> mpDrawRoot; + std::shared_ptr<gfx::DrawBase> mpCurrent; + +public: + SvgDrawVisitor(); + + void visit(svgio::svgreader::SvgNode const& rNode) override; + void goToChildren(svgio::svgreader::SvgNode const& rNode); + + std::shared_ptr<gfx::DrawRoot> const& getDrawRoot() const { return mpDrawRoot; } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |