summaryrefslogtreecommitdiffstats
path: root/cppcanvas/source/inc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
commit267c6f2ac71f92999e969232431ba04678e7437e (patch)
tree358c9467650e1d0a1d7227a21dac2e3d08b622b2 /cppcanvas/source/inc
parentInitial commit. (diff)
downloadlibreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz
libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cppcanvas/source/inc')
-rw-r--r--cppcanvas/source/inc/action.hxx145
-rw-r--r--cppcanvas/source/inc/canvasgraphichelper.hxx67
-rw-r--r--cppcanvas/source/inc/implrenderer.hxx247
-rw-r--r--cppcanvas/source/inc/outdevstate.hxx123
-rw-r--r--cppcanvas/source/inc/tools.hxx32
5 files changed, 614 insertions, 0 deletions
diff --git a/cppcanvas/source/inc/action.hxx b/cppcanvas/source/inc/action.hxx
new file mode 100644
index 0000000000..082e6d43f5
--- /dev/null
+++ b/cppcanvas/source/inc/action.hxx
@@ -0,0 +1,145 @@
+/* -*- 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::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 0000000000..03f6b91b6f
--- /dev/null
+++ b/cppcanvas/source/inc/canvasgraphichelper.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 <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::internal
+ {
+
+ class CanvasGraphicHelper : public virtual CanvasGraphic
+ {
+ public:
+ CanvasGraphicHelper( CanvasSharedPtr xParentCanvas );
+
+ // 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 0000000000..1f36728059
--- /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 <utility>
+#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 <span>
+#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::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(vcl::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( std::shared_ptr<Action> xAction,
+ sal_Int32 nOrigIndex ) :
+ mpAction(std::move( xAction )),
+ 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,
+ KernArraySpan pCharWidths,
+ std::span<const sal_Bool> pKashidaArray,
+ 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 0000000000..275b7b4314
--- /dev/null
+++ b/cppcanvas/source/inc/outdevstate.hxx
@@ -0,0 +1,123 @@
+/* -*- 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/rendercontext/State.hxx>
+
+namespace cppcanvas::internal
+ {
+ struct OutDevState
+ {
+ OutDevState() :
+ clip(),
+ clipRect(),
+ xClipPoly(),
+
+ lineColor(),
+ fillColor(),
+ textColor(),
+ textFillColor(),
+ textOverlineColor(),
+ textLineColor(),
+
+ xFont(),
+ transform(),
+ mapModeTransform(),
+ fontRotation(0.0),
+
+ textEmphasisMark(FontEmphasisMark::NONE),
+ pushFlags(vcl::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;
+ vcl::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 0000000000..dadd1b3a0b
--- /dev/null
+++ b/cppcanvas/source/inc/tools.hxx
@@ -0,0 +1,32 @@
+/* -*- 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::tools
+ {
+ css::uno::Sequence< double > intSRGBAToDoubleSequence( IntSRGBA );
+
+ IntSRGBA doubleSequenceToIntSRGBA( const css::uno::Sequence< double >& rColor );
+ }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */