summaryrefslogtreecommitdiffstats
path: root/cppcanvas/source/inc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /cppcanvas/source/inc
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cppcanvas/source/inc')
-rw-r--r--cppcanvas/source/inc/action.hxx148
-rw-r--r--cppcanvas/source/inc/canvasgraphichelper.hxx71
-rw-r--r--cppcanvas/source/inc/implrenderer.hxx247
-rw-r--r--cppcanvas/source/inc/outdevstate.hxx126
-rw-r--r--cppcanvas/source/inc/tools.hxx35
5 files changed, 627 insertions, 0 deletions
diff --git a/cppcanvas/source/inc/action.hxx b/cppcanvas/source/inc/action.hxx
new file mode 100644
index 000000000..bf122292a
--- /dev/null
+++ b/cppcanvas/source/inc/action.hxx
@@ -0,0 +1,148 @@
+/* -*- 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/types.h>
+
+namespace basegfx
+{
+ class B2DHomMatrix;
+ class B2DRange;
+}
+
+
+/* Definition of Action interface */
+
+namespace cppcanvas
+{
+ namespace internal
+ {
+ /** Interface for internal render actions
+
+ This interface is implemented by all objects generated
+ from the metafile renderer, and corresponds roughly to the
+ VCL meta action.
+ */
+ class Action
+ {
+ public:
+ /** Used for rendering action subsets
+
+ There are several cases where an Action might have
+ subsettable content, e.g. text, or referenced
+ metafiles, like the transparent action.
+
+ Generally, at the metafile renderer, all actions are
+ 'flattened' out, i.e. a meta action rendering the
+ string "Hello" counts five indices, and a transparent
+ action containing a metafile with 100 actions counts
+ at least 100 indices (contained transparency or text
+ actions recursively add to this value). From the
+ outside, the subset to render is referenced via this
+ flat index range
+ */
+ struct Subset
+ {
+ /** Denotes start of the subset.
+
+ The index given here specifies the first subaction
+ to render.
+ */
+ sal_Int32 mnSubsetBegin;
+
+ /** Denotes end of the subset
+
+ The index given here specifies the first subaction
+ <em>not<em> to render, i.e. one action behind the
+ subset to be rendered
+ */
+ sal_Int32 mnSubsetEnd;
+ };
+
+ virtual ~Action() {}
+
+ /** Render this action to the associated canvas
+
+ @param rTransformation
+ Transformation matrix to apply before rendering
+
+ @return true, if rendering was successful. If
+ rendering failed, false is returned.
+ */
+ virtual bool render( const ::basegfx::B2DHomMatrix& rTransformation ) const = 0;
+
+ /** Render the given part of the action to the associated
+ canvas.
+
+ @param rTransformation
+ Transformation matrix to apply before rendering
+
+ @param rSubset
+ Subset of the action to render. See Subset description
+ for index semantics.
+
+ @return true, if rendering was successful. If the
+ specified subset is invalid for this action, or if
+ rendering failed for other reasons, false is returned.
+ */
+ virtual bool renderSubset( const ::basegfx::B2DHomMatrix& rTransformation,
+ const Subset& rSubset ) const = 0;
+
+ /** Query bounds of this action on the associated canvas
+
+ @param rTransformation
+ Transformation matrix to apply
+
+ @return the bounds for this action in device
+ coordinate space.
+ */
+ virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation ) const = 0;
+
+ /** Query bounds for the given part of the action on the
+ associated canvas.
+
+ @param rTransformation
+ Transformation matrix to apply.
+
+ @param rSubset
+ Subset of the action to query. See Subset description
+ for index semantics.
+
+ @return the bounds for the given subset in device
+ coordinate space.
+ */
+ virtual ::basegfx::B2DRange getBounds( const ::basegfx::B2DHomMatrix& rTransformation,
+ const Subset& rSubset ) const = 0;
+
+ /** Query action count.
+
+ This method returns the number of subset actions
+ contained in this action. The render( Subset ) method
+ must accept subset ranges up to the value returned
+ here.
+
+ @return the number of subset actions
+ */
+ virtual sal_Int32 getActionCount() const = 0;
+ };
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cppcanvas/source/inc/canvasgraphichelper.hxx b/cppcanvas/source/inc/canvasgraphichelper.hxx
new file mode 100644
index 000000000..f003ec977
--- /dev/null
+++ b/cppcanvas/source/inc/canvasgraphichelper.hxx
@@ -0,0 +1,71 @@
+/* -*- 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/rendering/RenderState.hpp>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+
+#include <cppcanvas/canvasgraphic.hxx>
+#include <cppcanvas/canvas.hxx>
+
+#include <optional>
+
+namespace com::sun::star::rendering
+{
+ class XGraphicDevice;
+}
+
+
+/* Definition of CanvasGraphicHelper class */
+
+namespace cppcanvas
+{
+
+ namespace internal
+ {
+
+ class CanvasGraphicHelper : public virtual CanvasGraphic
+ {
+ public:
+ CanvasGraphicHelper( const CanvasSharedPtr& rParentCanvas );
+
+ // CanvasGraphic implementation
+ virtual void setTransformation( const ::basegfx::B2DHomMatrix& rMatrix ) override;
+ virtual void setClip( const ::basegfx::B2DPolyPolygon& rClipPoly ) override;
+ virtual void setClip() override;
+ virtual void setCompositeOp( sal_Int8 aOp ) override;
+
+ protected:
+ // for our clients
+ // ===============
+ const CanvasSharedPtr& getCanvas() const { return mpCanvas; }
+ const css::rendering::RenderState& getRenderState() const;
+
+ private:
+ mutable css::rendering::RenderState maRenderState;
+
+ std::optional<basegfx::B2DPolyPolygon> maClipPolyPolygon;
+ CanvasSharedPtr mpCanvas;
+ };
+
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cppcanvas/source/inc/implrenderer.hxx b/cppcanvas/source/inc/implrenderer.hxx
new file mode 100644
index 000000000..6c260c3f3
--- /dev/null
+++ b/cppcanvas/source/inc/implrenderer.hxx
@@ -0,0 +1,247 @@
+/* -*- 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 <sal/types.h>
+#include <tools/stream.hxx>
+#include <vcl/metaactiontypes.hxx>
+#include <cppcanvas/renderer.hxx>
+#include <cppcanvas/canvas.hxx>
+
+#include "canvasgraphichelper.hxx"
+#include "action.hxx"
+#include "outdevstate.hxx"
+
+#include <osl/diagnose.h>
+
+#include <memory>
+#include <vector>
+
+class GDIMetaFile;
+class VirtualDevice;
+class Gradient;
+namespace tools { class Rectangle; }
+namespace vcl { class Font; }
+namespace tools { class PolyPolygon; }
+class Point;
+class MetaCommentAction;
+
+namespace basegfx {
+ class B2DPolyPolygon;
+ class B2DPolygon;
+}
+
+namespace cppcanvas
+{
+
+ namespace internal
+ {
+ struct OutDevState;
+ struct ActionFactoryParameters;
+ struct XForm;
+
+ // state stack of OutputDevice, to correctly handle
+ // push/pop actions
+ class VectorOfOutDevStates
+ {
+ public:
+ OutDevState& getState();
+ const OutDevState& getState() const;
+ void pushState(PushFlags nFlags);
+ void popState();
+ void clearStateStack();
+ private:
+ std::vector< OutDevState > m_aStates;
+ };
+
+ // EMF+
+ // Transformation matrix (used for Affine Transformation)
+ // [ eM11, eM12, eDx ]
+ // [ eM21, eM22, eDy ]
+ // [ 0, 0, 1 ]
+ // that consists of a linear map (eM11, eM12, eM21, eM22)
+ // More info: https://en.wikipedia.org/wiki/Linear_map
+ // followed by a translation (eDx, eDy)
+
+ struct XForm
+ {
+ float eM11; // M1,1 value in the matrix. Increases or decreases the size of the pixels horizontally.
+ float eM12; // M1,2 value in the matrix. This effectively angles the X axis up or down.
+ float eM21; // M2,1 value in the matrix. This effectively angles the Y axis left or right.
+ float eM22; // M2,2 value in the matrix. Increases or decreases the size of the pixels vertically.
+ float eDx; // Delta x (Dx) value in the matrix. Moves the whole coordinate system horizontally.
+ float eDy; // Delta y (Dy) value in the matrix. Moves the whole coordinate system vertically.
+ XForm()
+ {
+ SetIdentity ();
+ }
+
+ void SetIdentity ()
+ {
+ eM11 = eM22 = 1.0f;
+ eDx = eDy = eM12 = eM21 = 0.0f;
+ }
+
+ friend SvStream& ReadXForm( SvStream& rIn, XForm& rXForm )
+ {
+ if ( sizeof( float ) != 4 )
+ {
+ OSL_FAIL( "EnhWMFReader::sizeof( float ) != 4" );
+ rXForm = XForm();
+ }
+ else
+ {
+ rIn.ReadFloat( rXForm.eM11 ).ReadFloat( rXForm.eM12 ).ReadFloat( rXForm.eM21 ).ReadFloat( rXForm.eM22 )
+ .ReadFloat( rXForm.eDx ).ReadFloat( rXForm.eDy );
+ }
+ return rIn;
+ }
+ };
+
+ // EMF+
+
+ class ImplRenderer : public virtual Renderer, protected CanvasGraphicHelper
+ {
+ public:
+ ImplRenderer( const CanvasSharedPtr& rCanvas,
+ const GDIMetaFile& rMtf,
+ const Parameters& rParms );
+
+ virtual ~ImplRenderer() override;
+
+ virtual bool draw() const override;
+ virtual bool drawSubset( sal_Int32 nStartIndex,
+ sal_Int32 nEndIndex ) const override;
+ virtual ::basegfx::B2DRange getSubsetArea( sal_Int32 nStartIndex,
+ sal_Int32 nEndIndex ) const override;
+
+
+ // element of the Renderer's action vector. Need to be
+ // public, since some functors need it, too.
+ struct MtfAction
+ {
+ MtfAction( const std::shared_ptr<Action>& rAction,
+ sal_Int32 nOrigIndex ) :
+ mpAction( rAction ),
+ mnOrigIndex( nOrigIndex )
+ {
+ }
+
+ std::shared_ptr<Action> mpAction;
+ sal_Int32 mnOrigIndex;
+ };
+
+ // prefetched and prepared canvas actions
+ // (externally not visible)
+ typedef std::vector< MtfAction > ActionVector;
+
+ private:
+ ImplRenderer(const ImplRenderer&) = delete;
+ ImplRenderer& operator=( const ImplRenderer& ) = delete;
+
+ static void updateClipping( const ::basegfx::B2DPolyPolygon& rClipPoly,
+ const ActionFactoryParameters& rParms,
+ bool bIntersect );
+
+ static void updateClipping( const ::tools::Rectangle& rClipRect,
+ const ActionFactoryParameters& rParms,
+ bool bIntersect );
+
+ static css::uno::Reference<
+ css::rendering::XCanvasFont > createFont( double& o_rFontRotation,
+ const vcl::Font& rFont,
+ const ActionFactoryParameters& rParms );
+ void createActions( GDIMetaFile& rMtf,
+ const ActionFactoryParameters& rParms,
+ bool bSubsettableActions );
+ bool createFillAndStroke( const ::basegfx::B2DPolyPolygon& rPolyPoly,
+ const ActionFactoryParameters& rParms );
+ bool createFillAndStroke( const ::basegfx::B2DPolygon& rPoly,
+ const ActionFactoryParameters& rParms );
+ static void skipContent( GDIMetaFile& rMtf,
+ const char* pCommentString,
+ sal_Int32& io_rCurrActionIndex );
+
+ static bool isActionContained( GDIMetaFile& rMtf,
+ const char* pCommentString,
+ MetaActionType nType );
+
+ void createGradientAction( const ::tools::PolyPolygon& rPoly,
+ const ::Gradient& rGradient,
+ const ActionFactoryParameters& rParms,
+ bool bIsPolygonRectangle,
+ bool bSubsettableActions );
+
+ void createTextAction( const ::Point& rStartPoint,
+ const OUString& rString,
+ int nIndex,
+ int nLength,
+ const long* pCharWidths,
+ const ActionFactoryParameters& rParms,
+ bool bSubsettable );
+
+ bool getSubsetIndices( sal_Int32& io_rStartIndex,
+ sal_Int32& io_rEndIndex,
+ ActionVector::const_iterator& o_rRangeBegin,
+ ActionVector::const_iterator& o_rRangeEnd ) const;
+
+ ActionVector maActions;
+
+ /* EMF+ */
+ XForm aBaseTransform;
+ /* EMF+ emf header info */
+ sal_Int32 nFrameLeft;
+ sal_Int32 nFrameTop;
+ sal_Int32 nFrameRight;
+ sal_Int32 nFrameBottom;
+ sal_Int32 nPixX;
+ sal_Int32 nPixY;
+ sal_Int32 nMmX;
+ sal_Int32 nMmY;
+ };
+
+
+ /// Common parameters when creating actions
+ struct ActionFactoryParameters
+ {
+ ActionFactoryParameters( VectorOfOutDevStates& rStates,
+ const CanvasSharedPtr& rCanvas,
+ ::VirtualDevice& rVDev,
+ const Renderer::Parameters& rParms,
+ sal_Int32& io_rCurrActionIndex ) :
+ mrStates(rStates),
+ mrCanvas(rCanvas),
+ mrVDev(rVDev),
+ mrParms(rParms),
+ mrCurrActionIndex(io_rCurrActionIndex)
+ {}
+
+ VectorOfOutDevStates& mrStates;
+ const CanvasSharedPtr& mrCanvas;
+ ::VirtualDevice& mrVDev;
+ const Renderer::Parameters& mrParms;
+ sal_Int32& mrCurrActionIndex;
+ };
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cppcanvas/source/inc/outdevstate.hxx b/cppcanvas/source/inc/outdevstate.hxx
new file mode 100644
index 000000000..590a7b2ec
--- /dev/null
+++ b/cppcanvas/source/inc/outdevstate.hxx
@@ -0,0 +1,126 @@
+/* -*- 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/uno/Reference.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+
+#include <com/sun/star/rendering/XPolyPolygon2D.hpp>
+#include <com/sun/star/rendering/XCanvasFont.hpp>
+#include <com/sun/star/rendering/TextDirection.hpp>
+#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <tools/fontenum.hxx>
+#include <tools/gen.hxx>
+#include <vcl/fntstyle.hxx>
+#include <vcl/outdevstate.hxx>
+
+
+namespace cppcanvas
+{
+ namespace internal
+ {
+ struct OutDevState
+ {
+ OutDevState() :
+ clip(),
+ clipRect(),
+ xClipPoly(),
+
+ lineColor(),
+ fillColor(),
+ textColor(),
+ textFillColor(),
+ textOverlineColor(),
+ textLineColor(),
+
+ xFont(),
+ transform(),
+ mapModeTransform(),
+ fontRotation(0.0),
+
+ textEmphasisMark(FontEmphasisMark::NONE),
+ pushFlags(PushFlags::ALL),
+ textDirection(css::rendering::TextDirection::WEAK_LEFT_TO_RIGHT),
+ textAlignment(0), // TODO(Q2): Synchronize with implrenderer
+ // and possibly new rendering::TextAlignment
+ textReliefStyle(FontRelief::NONE),
+ textOverlineStyle(LINESTYLE_NONE),
+ textUnderlineStyle(LINESTYLE_NONE),
+ textStrikeoutStyle(STRIKEOUT_NONE),
+ textReferencePoint(ALIGN_BASELINE),
+
+ isTextOutlineModeSet( false ),
+ isTextEffectShadowSet( false ),
+ isTextWordUnderlineSet( false ),
+
+ isLineColorSet( false ),
+ isFillColorSet( false ),
+ isTextFillColorSet( false ),
+ isTextOverlineColorSet( false ),
+ isTextLineColorSet( false )
+ {
+ }
+
+ ::basegfx::B2DPolyPolygon clip;
+ ::tools::Rectangle clipRect;
+ css::uno::Reference< css::rendering::XPolyPolygon2D > xClipPoly;
+
+ css::uno::Sequence< double > lineColor;
+ css::uno::Sequence< double > fillColor;
+ css::uno::Sequence< double > textColor;
+ css::uno::Sequence< double > textFillColor;
+ css::uno::Sequence< double > textOverlineColor;
+ css::uno::Sequence< double > textLineColor;
+
+ /** Current font.
+
+ @attention Beware, this member can be NULL, and
+ nevertheless text output is generated.
+ */
+ css::uno::Reference< css::rendering::XCanvasFont > xFont;
+ ::basegfx::B2DHomMatrix transform;
+ ::basegfx::B2DHomMatrix mapModeTransform;
+ double fontRotation;
+
+ FontEmphasisMark textEmphasisMark;
+ PushFlags pushFlags;
+ sal_Int8 textDirection;
+ sal_Int8 textAlignment;
+ FontRelief textReliefStyle;
+ sal_Int8 textOverlineStyle;
+ sal_Int8 textUnderlineStyle;
+ sal_Int8 textStrikeoutStyle;
+ TextAlign textReferencePoint;
+
+ bool isTextOutlineModeSet;
+ bool isTextEffectShadowSet;
+ bool isTextWordUnderlineSet;
+
+ bool isLineColorSet;
+ bool isFillColorSet;
+ bool isTextFillColorSet;
+ bool isTextOverlineColorSet;
+ bool isTextLineColorSet;
+ };
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cppcanvas/source/inc/tools.hxx b/cppcanvas/source/inc/tools.hxx
new file mode 100644
index 000000000..fab00805a
--- /dev/null
+++ b/cppcanvas/source/inc/tools.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/.
+ *
+ * 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/uno/Sequence.hxx>
+#include <cppcanvas/color.hxx>
+
+namespace cppcanvas
+{
+ namespace tools
+ {
+ css::uno::Sequence< double > intSRGBAToDoubleSequence( IntSRGBA );
+
+ IntSRGBA doubleSequenceToIntSRGBA( const css::uno::Sequence< double >& rColor );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */