summaryrefslogtreecommitdiff
path: root/drawinglayer/source/primitive2d/graphicprimitive2d.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'drawinglayer/source/primitive2d/graphicprimitive2d.cxx')
-rw-r--r--drawinglayer/source/primitive2d/graphicprimitive2d.cxx122
1 files changed, 63 insertions, 59 deletions
diff --git a/drawinglayer/source/primitive2d/graphicprimitive2d.cxx b/drawinglayer/source/primitive2d/graphicprimitive2d.cxx
index f86b1585b13f..0f0d3771867f 100644
--- a/drawinglayer/source/primitive2d/graphicprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/graphicprimitive2d.cxx
@@ -24,19 +24,20 @@
#include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
#include <primitive2d/cropprimitive2d.hxx>
#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
-#include <primitive2d/graphicprimitivehelper2d.hxx>
+#include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx>
#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <utility>
namespace drawinglayer::primitive2d
{
-void GraphicPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer,
- const geometry::ViewInformation2D&) const
+Primitive2DReference
+GraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D&) const
{
- if (255 == getGraphicAttr().GetTransparency())
+ if (0 == getGraphicAttr().GetAlpha())
{
// content is invisible, done
- return;
+ return nullptr;
}
// do not apply mirroring from GraphicAttr to the Metafile by calling
@@ -68,45 +69,60 @@ void GraphicPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer,
GraphicAttr aSuppressGraphicAttr(getGraphicAttr());
aSuppressGraphicAttr.SetCrop(0, 0, 0, 0);
- aSuppressGraphicAttr.SetRotation(0);
+ aSuppressGraphicAttr.SetRotation(0_deg10);
aSuppressGraphicAttr.SetMirrorFlags(BmpMirrorFlags::NONE);
- aSuppressGraphicAttr.SetTransparency(0);
+ aSuppressGraphicAttr.SetAlpha(255);
const GraphicObject& rGraphicObject = getGraphicObject();
Graphic aTransformedGraphic(rGraphicObject.GetGraphic());
- const bool isBitmap(GraphicType::Bitmap == aTransformedGraphic.GetType()
- && !aTransformedGraphic.getVectorGraphicData());
const bool isAdjusted(getGraphicAttr().IsAdjusted());
const bool isDrawMode(GraphicDrawMode::Standard != getGraphicAttr().GetDrawMode());
- if (isBitmap && (isAdjusted || isDrawMode))
+ // I have now added buffering BColorModifierStack-adapted Bitmaps,
+ // see Bitmap::Modify, thus the primitive case is fast now.
+ // It buffers the adapted bitmap and at that the SDPRs can then buffer
+ // the system-dependent representation.
+ // I keep the code below (adding a static switch). It modifies the
+ // Graphic and is a reliable fallback - just in case. Remember that
+ // it does *not* buffer and has to modify again at each re-use...
+ static bool bUseOldModification(false);
+
+ if (bUseOldModification)
{
- // the pure primitive solution with the color modifiers works well, too, but when
- // it is a bitmap graphic the old modification currently is faster; so use it here
- // instead of creating all as in create2DColorModifierEmbeddingsAsNeeded (see below).
- // Still, crop, rotation, mirroring and transparency is handled by primitives already
- // (see above).
- // This could even be done when vector graphic, but we explicitly want to have the
- // pure primitive solution for this; this will allow vector graphics to stay vector
- // graphics, independent from the color filtering stuff. This will enhance e.g.
- // SVG and print quality while reducing data size at the same time.
- // The other way around the old modifications when only used on already bitmap objects
- // will not lose any quality.
- aTransformedGraphic = rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr);
-
- // reset GraphicAttr after use to not apply double
- aSuppressGraphicAttr = GraphicAttr();
+ const bool isBitmap(GraphicType::Bitmap == aTransformedGraphic.GetType()
+ && !aTransformedGraphic.getVectorGraphicData());
+
+ if (isBitmap && (isAdjusted || isDrawMode))
+ {
+ // the pure primitive solution with the color modifiers works well, too, but when
+ // it is a bitmap graphic the old modification currently is faster; so use it here
+ // instead of creating all as in create2DColorModifierEmbeddingsAsNeeded (see below).
+ // Still, crop, rotation, mirroring and transparency is handled by primitives already
+ // (see above).
+ // This could even be done when vector graphic, but we explicitly want to have the
+ // pure primitive solution for this; this will allow vector graphics to stay vector
+ // graphics, independent from the color filtering stuff. This will enhance e.g.
+ // SVG and print quality while reducing data size at the same time.
+ // The other way around the old modifications when only used on already bitmap objects
+ // will not lose any quality.
+ aTransformedGraphic = rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr);
+
+ // reset GraphicAttr after use to not apply double
+ aSuppressGraphicAttr = GraphicAttr();
+ }
}
// create sub-content; helper takes care of correct handling of
- // bitmap, svg or metafile content
+ // bitmap, svg or metafile content. also handle alpha there directly
Primitive2DContainer aRetval;
- create2DDecompositionOfGraphic(aRetval, aTransformedGraphic, aTransform);
+ const double fTransparency(
+ std::clamp((255 - getGraphicAttr().GetAlpha()) * (1.0 / 255.0), 0.0, 1.0));
+ create2DDecompositionOfGraphic(aRetval, aTransformedGraphic, aTransform, fTransparency);
if (aRetval.empty())
{
// content is invisible, done
- return;
+ return nullptr;
}
if (isAdjusted || isDrawMode)
@@ -114,7 +130,7 @@ void GraphicPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer,
// embed to needed ModifiedColorPrimitive2D's if necessary. Do this for
// adjustments and draw mode specials
aRetval = create2DColorModifierEmbeddingsAsNeeded(
- aRetval, aSuppressGraphicAttr.GetDrawMode(),
+ std::move(aRetval), aSuppressGraphicAttr.GetDrawMode(),
std::clamp(aSuppressGraphicAttr.GetLuminance() * 0.01, -1.0, 1.0),
std::clamp(aSuppressGraphicAttr.GetContrast() * 0.01, -1.0, 1.0),
std::clamp(aSuppressGraphicAttr.GetChannelR() * 0.01, -1.0, 1.0),
@@ -126,22 +142,7 @@ void GraphicPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer,
if (aRetval.empty())
{
// content is invisible, done
- return;
- }
- }
-
- if (getGraphicAttr().IsTransparent())
- {
- // check for transparency
- const double fTransparency(
- std::clamp(getGraphicAttr().GetTransparency() * (1.0 / 255.0), 0.0, 1.0));
-
- if (!basegfx::fTools::equalZero(fTransparency))
- {
- const Primitive2DReference aUnifiedTransparence(
- new UnifiedTransparencePrimitive2D(aRetval, fTransparency));
-
- aRetval = Primitive2DContainer{ aUnifiedTransparence };
+ return nullptr;
}
}
@@ -157,35 +158,35 @@ void GraphicPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer,
getGraphicAttr().GetBottomCrop()));
// embed content in cropPrimitive
- Primitive2DReference xPrimitive(new CropPrimitive2D(
- aRetval, aTransform, getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(),
+ aRetval = Primitive2DContainer{ new CropPrimitive2D(
+ std::move(aRetval), aTransform,
+ getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(),
getGraphicAttr().GetTopCrop() * aCropScaleFactor.getY(),
getGraphicAttr().GetRightCrop() * aCropScaleFactor.getX(),
- getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY()));
-
- aRetval = Primitive2DContainer{ xPrimitive };
+ getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY()) };
}
- rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end());
+ return new GroupPrimitive2D(std::move(aRetval));
}
-GraphicPrimitive2D::GraphicPrimitive2D(const basegfx::B2DHomMatrix& rTransform,
+GraphicPrimitive2D::GraphicPrimitive2D(basegfx::B2DHomMatrix aTransform,
const GraphicObject& rGraphicObject,
const GraphicAttr& rGraphicAttr)
- : BufferedDecompositionPrimitive2D()
- , maTransform(rTransform)
+ : maTransform(std::move(aTransform))
, maGraphicObject(rGraphicObject)
, maGraphicAttr(rGraphicAttr)
{
+ // activate callback to flush buffered decomposition content
+ activateFlushOnTimer();
}
-GraphicPrimitive2D::GraphicPrimitive2D(const basegfx::B2DHomMatrix& rTransform,
+GraphicPrimitive2D::GraphicPrimitive2D(basegfx::B2DHomMatrix aTransform,
const GraphicObject& rGraphicObject)
- : BufferedDecompositionPrimitive2D()
- , maTransform(rTransform)
+ : maTransform(std::move(aTransform))
, maGraphicObject(rGraphicObject)
- , maGraphicAttr()
{
+ // activate callback to flush buffered decomposition content
+ activateFlushOnTimer();
}
bool GraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
@@ -211,7 +212,10 @@ GraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInform
}
// provide unique ID
-ImplPrimitive2DIDBlock(GraphicPrimitive2D, PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D)
+sal_uInt32 GraphicPrimitive2D::getPrimitive2DID() const
+{
+ return PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D;
+}
} // end of namespace