diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-02-22 09:52:45 +0000 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-02-22 13:01:16 +0100 |
commit | 006a8e3186c26c43560b2d616dde453437a49b47 (patch) | |
tree | 9f78343f8f28f01f0c9c650b152dbbb941667935 | |
parent | 29b109dfc0f836e34b61b2fbbe69d2b0728dc7b8 (diff) |
split TextAsPolygonExtractor2D for more general reuse
Change-Id: I102ccab2a423c38b0414c9565fec349aa6ffb5af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163725
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
5 files changed, 166 insertions, 67 deletions
diff --git a/drawinglayer/Library_drawinglayer.mk b/drawinglayer/Library_drawinglayer.mk index bb36fc2847d9..e5c02487741a 100644 --- a/drawinglayer/Library_drawinglayer.mk +++ b/drawinglayer/Library_drawinglayer.mk @@ -193,6 +193,7 @@ $(eval $(call gb_Library_add_exception_objects,drawinglayer,\ drawinglayer/source/processor2d/hittestprocessor2d \ drawinglayer/source/processor2d/linegeometryextractor2d \ drawinglayer/source/processor2d/objectinfoextractor2d \ + drawinglayer/source/processor2d/textextractor2d \ drawinglayer/source/processor2d/textaspolygonextractor2d \ drawinglayer/source/processor2d/vclhelperbufferdevice \ drawinglayer/source/processor2d/vclmetafileprocessor2d \ diff --git a/drawinglayer/source/processor2d/textaspolygonextractor2d.cxx b/drawinglayer/source/processor2d/textaspolygonextractor2d.cxx index c98fae69d301..1a091d027a85 100644 --- a/drawinglayer/source/processor2d/textaspolygonextractor2d.cxx +++ b/drawinglayer/source/processor2d/textaspolygonextractor2d.cxx @@ -28,56 +28,47 @@ namespace drawinglayer::processor2d { + void TextAsPolygonExtractor2D::processTextPrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) + { + // PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D + // TextDecoratedPortionPrimitive2D can produce the following primitives + // when being decomposed: + // + // - TextSimplePortionPrimitive2D + // - PolygonWavePrimitive2D + // - PolygonStrokePrimitive2D + // - PolygonStrokePrimitive2D + // - PolyPolygonColorPrimitive2D + // - PolyPolygonHairlinePrimitive2D + // - PolygonHairlinePrimitive2D + // - ShadowPrimitive2D + // - ModifiedColorPrimitive2D + // - TransformPrimitive2D + // - TextEffectPrimitive2D + // - ModifiedColorPrimitive2D + // - TransformPrimitive2D + // - GroupPrimitive2D + + // PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D + // TextSimplePortionPrimitive2D can produce the following primitives + // when being decomposed: + // + // - PolyPolygonColorPrimitive2D + // - TextEffectPrimitive2D + // - ModifiedColorPrimitive2D + // - TransformPrimitive2D + // - GroupPrimitive2D + + // encapsulate with flag and use decomposition + mnInText++; + process(rCandidate); + mnInText--; + } + void TextAsPolygonExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) { - switch(rCandidate.getPrimitive2DID()) + switch (rCandidate.getPrimitive2DID()) { - case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D : - { - // TextDecoratedPortionPrimitive2D can produce the following primitives - // when being decomposed: - // - // - TextSimplePortionPrimitive2D - // - PolygonWavePrimitive2D - // - PolygonStrokePrimitive2D - // - PolygonStrokePrimitive2D - // - PolyPolygonColorPrimitive2D - // - PolyPolygonHairlinePrimitive2D - // - PolygonHairlinePrimitive2D - // - ShadowPrimitive2D - // - ModifiedColorPrimitive2D - // - TransformPrimitive2D - // - TextEffectPrimitive2D - // - ModifiedColorPrimitive2D - // - TransformPrimitive2D - // - GroupPrimitive2D - - // encapsulate with flag and use decomposition - mnInText++; - process(rCandidate); - mnInText--; - - break; - } - case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D : - { - // TextSimplePortionPrimitive2D can produce the following primitives - // when being decomposed: - // - // - PolyPolygonColorPrimitive2D - // - TextEffectPrimitive2D - // - ModifiedColorPrimitive2D - // - TransformPrimitive2D - // - GroupPrimitive2D - - // encapsulate with flag and use decomposition - mnInText++; - process(rCandidate); - mnInText--; - - break; - } - // as can be seen from the TextSimplePortionPrimitive2D and the // TextDecoratedPortionPrimitive2D, inside of the mnInText marks // the following primitives can occur containing geometry data @@ -190,29 +181,14 @@ namespace drawinglayer::processor2d break; } - // ignorable primitives - case PRIMITIVE2D_ID_SCENEPRIMITIVE2D : - case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D : - case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D : - case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D : - case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D : - case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D : - case PRIMITIVE2D_ID_MASKPRIMITIVE2D : - { + default: + TextExtractor2D::processBasePrimitive2D(rCandidate); break; - } - - default : - { - // process recursively - process(rCandidate); - break; - } } } TextAsPolygonExtractor2D::TextAsPolygonExtractor2D(const geometry::ViewInformation2D& rViewInformation) - : BaseProcessor2D(rViewInformation), + : TextExtractor2D(rViewInformation), maBColorModifierStack(), mnInText(0) { diff --git a/drawinglayer/source/processor2d/textextractor2d.cxx b/drawinglayer/source/processor2d/textextractor2d.cxx new file mode 100644 index 000000000000..105014a750ca --- /dev/null +++ b/drawinglayer/source/processor2d/textextractor2d.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawinglayer/processor2d/textextractor2d.hxx> +#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> +#include <drawinglayer/primitive2d/transformprimitive2d.hxx> + +namespace drawinglayer::processor2d +{ +void TextExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) +{ + switch (rCandidate.getPrimitive2DID()) + { + case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D: + case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D: + { + processTextPrimitive2D(rCandidate); + break; + } + + // usage of transformation stack is needed + case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D: + { + // remember current transformation and ViewInformation + const primitive2d::TransformPrimitive2D& rTransformCandidate( + static_cast<const primitive2d::TransformPrimitive2D&>(rCandidate)); + const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D()); + + // create new transformations for CurrentTransformation and for local ViewInformation2D + geometry::ViewInformation2D aViewInformation2D(getViewInformation2D()); + aViewInformation2D.setObjectTransformation( + getViewInformation2D().getObjectTransformation() + * rTransformCandidate.getTransformation()); + updateViewInformation(aViewInformation2D); + + // process content + process(rTransformCandidate.getChildren()); + + // restore transformations + updateViewInformation(aLastViewInformation2D); + + break; + } + + // ignorable primitives + case PRIMITIVE2D_ID_SCENEPRIMITIVE2D: + case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D: + case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D: + case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D: + case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D: + case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D: + case PRIMITIVE2D_ID_MASKPRIMITIVE2D: + break; + + default: + { + // process recursively + process(rCandidate); + break; + } + } +} + +TextExtractor2D::TextExtractor2D(const geometry::ViewInformation2D& rViewInformation) + : BaseProcessor2D(rViewInformation) +{ +} + +TextExtractor2D::~TextExtractor2D() {} +} // end of namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/drawinglayer/processor2d/textaspolygonextractor2d.hxx b/include/drawinglayer/processor2d/textaspolygonextractor2d.hxx index feaea118e147..a7189778a7f2 100644 --- a/include/drawinglayer/processor2d/textaspolygonextractor2d.hxx +++ b/include/drawinglayer/processor2d/textaspolygonextractor2d.hxx @@ -22,7 +22,7 @@ #include <drawinglayer/drawinglayerdllapi.h> -#include <drawinglayer/processor2d/baseprocessor2d.hxx> +#include <drawinglayer/processor2d/textextractor2d.hxx> #include <basegfx/polygon/b2dpolypolygon.hxx> #include <basegfx/color/bcolor.hxx> #include <basegfx/color/bcolormodifier.hxx> @@ -64,7 +64,7 @@ namespace drawinglayer::processor2d This processor extracts text in the fed primitives to filled polygons */ - class DRAWINGLAYER_DLLPUBLIC TextAsPolygonExtractor2D final : public BaseProcessor2D + class DRAWINGLAYER_DLLPUBLIC TextAsPolygonExtractor2D final : public TextExtractor2D { private: // extraction target @@ -78,6 +78,7 @@ namespace drawinglayer::processor2d // tooling methods void processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) override; + void processTextPrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) override; public: explicit TextAsPolygonExtractor2D(const geometry::ViewInformation2D& rViewInformation); diff --git a/include/drawinglayer/processor2d/textextractor2d.hxx b/include/drawinglayer/processor2d/textextractor2d.hxx new file mode 100644 index 000000000000..8f68f7ec8026 --- /dev/null +++ b/include/drawinglayer/processor2d/textextractor2d.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 <drawinglayer/drawinglayerdllapi.h> +#include <drawinglayer/processor2d/baseprocessor2d.hxx> + +namespace drawinglayer::processor2d +{ +/** TextExtractor2D class + + This processor extracts text in the fed primitives and calls + processTextPrimitive2D for those while calling processBasePrimitive2D + for everything else. + */ +class DRAWINGLAYER_DLLPUBLIC TextExtractor2D : public BaseProcessor2D +{ +public: + explicit TextExtractor2D(const geometry::ViewInformation2D& rViewInformation); + void processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) override; + virtual void processTextPrimitive2D(const primitive2d::BasePrimitive2D& rCandidate) = 0; + virtual ~TextExtractor2D() override; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |