diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-02-07 21:08:00 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-02-11 18:53:46 +0100 |
commit | 26ba295e5517dd85de5b972631b3a73beb8db7a0 (patch) | |
tree | 79ab0c302756f05b7b51fc0f0909548c592efb2e | |
parent | e8f26dc13b65b1a05d948d9c95110c86315e8f20 (diff) |
remove graphicprimitive2d.{cxx,hxx} from clang-format blacklist
Change-Id: Ice9a6813743e4238d28d6007bb0092c69685a9fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88241
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | drawinglayer/source/primitive2d/graphicprimitive2d.cxx | 356 | ||||
-rw-r--r-- | include/drawinglayer/primitive2d/graphicprimitive2d.hxx | 117 | ||||
-rw-r--r-- | solenv/clang-format/blacklist | 2 |
3 files changed, 229 insertions, 246 deletions
diff --git a/drawinglayer/source/primitive2d/graphicprimitive2d.cxx b/drawinglayer/source/primitive2d/graphicprimitive2d.cxx index 51625c60a491..f3793d4bcf73 100644 --- a/drawinglayer/source/primitive2d/graphicprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/graphicprimitive2d.cxx @@ -30,202 +30,188 @@ namespace drawinglayer::primitive2d { - void GraphicPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& ) const +void GraphicPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, + const geometry::ViewInformation2D&) const +{ + if (255 == getGraphicAttr().GetTransparency()) + { + // content is invisible, done + return; + } + + // do not apply mirroring from GraphicAttr to the Metafile by calling + // GetTransformedGraphic, this will try to mirror the Metafile using Scale() + // at the Metafile. This again calls Scale at the single MetaFile actions, + // but this implementation never worked. I reworked that implementations, + // but for security reasons i will try not to use it. + basegfx::B2DHomMatrix aTransform(getTransform()); + + if (getGraphicAttr().IsMirrored()) + { + // content needs mirroring + const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BmpMirrorFlags::Horizontal); + const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BmpMirrorFlags::Vertical); + + // mirror by applying negative scale to the unit primitive and + // applying the object transformation on it. + aTransform + = basegfx::utils::createScaleB2DHomMatrix(bHMirr ? -1.0 : 1.0, bVMirr ? -1.0 : 1.0); + aTransform.translate(bHMirr ? 1.0 : 0.0, bVMirr ? 1.0 : 0.0); + aTransform = getTransform() * aTransform; + } + + // Get transformed graphic. Suppress rotation and cropping, only filtering is needed + // here (and may be replaced later on). Cropping is handled below as mask primitive (if set). + // Also need to suppress mirroring, it is part of the transformation now (see above). + // Also move transparency handling to embedding to a UnifiedTransparencePrimitive2D; do + // that by remembering original transparency and applying that later if needed + GraphicAttr aSuppressGraphicAttr(getGraphicAttr()); + + aSuppressGraphicAttr.SetCrop(0, 0, 0, 0); + aSuppressGraphicAttr.SetRotation(0); + aSuppressGraphicAttr.SetMirrorFlags(BmpMirrorFlags::NONE); + aSuppressGraphicAttr.SetTransparency(0); + + const GraphicObject& rGraphicObject = getGraphicObject(); + Graphic aTransformedGraphic(rGraphicObject.GetGraphic()); + const bool isBitmap(GraphicType::Bitmap == aTransformedGraphic.GetType() + && !aTransformedGraphic.getVectorGraphicData().get()); + const bool isAdjusted(getGraphicAttr().IsAdjusted()); + const bool isDrawMode(GraphicDrawMode::Standard != getGraphicAttr().GetDrawMode()); + + 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 + Primitive2DContainer aRetval; + create2DDecompositionOfGraphic(aRetval, aTransformedGraphic, aTransform); + + if (aRetval.empty()) + { + // content is invisible, done + return; + } + + if (isAdjusted || isDrawMode) + { + // embed to needed ModifiedColorPrimitive2D's if necessary. Do this for + // adjustments and draw mode specials + aRetval = create2DColorModifierEmbeddingsAsNeeded( + 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), + std::clamp(aSuppressGraphicAttr.GetChannelG() * 0.01, -1.0, 1.0), + std::clamp(aSuppressGraphicAttr.GetChannelB() * 0.01, -1.0, 1.0), + std::clamp(aSuppressGraphicAttr.GetGamma(), 0.0, 10.0), + aSuppressGraphicAttr.IsInvert()); + + if (aRetval.empty()) { - if(255 == getGraphicAttr().GetTransparency()) - { - // content is invisible, done - return; - } - - // do not apply mirroring from GraphicAttr to the Metafile by calling - // GetTransformedGraphic, this will try to mirror the Metafile using Scale() - // at the Metafile. This again calls Scale at the single MetaFile actions, - // but this implementation never worked. I reworked that implementations, - // but for security reasons i will try not to use it. - basegfx::B2DHomMatrix aTransform(getTransform()); - - if(getGraphicAttr().IsMirrored()) - { - // content needs mirroring - const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BmpMirrorFlags::Horizontal); - const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BmpMirrorFlags::Vertical); - - // mirror by applying negative scale to the unit primitive and - // applying the object transformation on it. - aTransform = basegfx::utils::createScaleB2DHomMatrix( - bHMirr ? -1.0 : 1.0, - bVMirr ? -1.0 : 1.0); - aTransform.translate( - bHMirr ? 1.0 : 0.0, - bVMirr ? 1.0 : 0.0); - aTransform = getTransform() * aTransform; - } - - // Get transformed graphic. Suppress rotation and cropping, only filtering is needed - // here (and may be replaced later on). Cropping is handled below as mask primitive (if set). - // Also need to suppress mirroring, it is part of the transformation now (see above). - // Also move transparency handling to embedding to a UnifiedTransparencePrimitive2D; do - // that by remembering original transparency and applying that later if needed - GraphicAttr aSuppressGraphicAttr(getGraphicAttr()); - - aSuppressGraphicAttr.SetCrop(0, 0, 0, 0); - aSuppressGraphicAttr.SetRotation(0); - aSuppressGraphicAttr.SetMirrorFlags(BmpMirrorFlags::NONE); - aSuppressGraphicAttr.SetTransparency(0); - - const GraphicObject& rGraphicObject = getGraphicObject(); - Graphic aTransformedGraphic(rGraphicObject.GetGraphic()); - const bool isBitmap(GraphicType::Bitmap == aTransformedGraphic.GetType() && !aTransformedGraphic.getVectorGraphicData().get()); - const bool isAdjusted(getGraphicAttr().IsAdjusted()); - const bool isDrawMode(GraphicDrawMode::Standard != getGraphicAttr().GetDrawMode()); - - 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 - Primitive2DContainer aRetval; - create2DDecompositionOfGraphic( - aRetval, - aTransformedGraphic, - aTransform); - - if(aRetval.empty()) - { - // content is invisible, done - return; - } - - if(isAdjusted || isDrawMode) - { - // embed to needed ModifiedColorPrimitive2D's if necessary. Do this for - // adjustments and draw mode specials - aRetval = create2DColorModifierEmbeddingsAsNeeded( - 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), - std::clamp(aSuppressGraphicAttr.GetChannelG() * 0.01, -1.0, 1.0), - std::clamp(aSuppressGraphicAttr.GetChannelB() * 0.01, -1.0, 1.0), - std::clamp(aSuppressGraphicAttr.GetGamma(), 0.0, 10.0), - aSuppressGraphicAttr.IsInvert()); - - 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 }; - } - } - - if(getGraphicAttr().IsCropped()) - { - // check for cropping - // calculate scalings between real image size and logic object size. This - // is necessary since the crop values are relative to original bitmap size - const basegfx::B2DVector aObjectScale(aTransform * basegfx::B2DVector(1.0, 1.0)); - const basegfx::B2DVector aCropScaleFactor( - rGraphicObject.calculateCropScaling( - aObjectScale.getX(), - aObjectScale.getY(), - getGraphicAttr().GetLeftCrop(), - getGraphicAttr().GetTopCrop(), - getGraphicAttr().GetRightCrop(), - getGraphicAttr().GetBottomCrop())); - - // embed content in cropPrimitive - Primitive2DReference xPrimitive( - new CropPrimitive2D( - aRetval, - aTransform, - getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(), - getGraphicAttr().GetTopCrop() * aCropScaleFactor.getY(), - getGraphicAttr().GetRightCrop() * aCropScaleFactor.getX(), - getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY())); - - aRetval = Primitive2DContainer { xPrimitive }; - } - - rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end()); + // content is invisible, done + return; } + } - GraphicPrimitive2D::GraphicPrimitive2D( - const basegfx::B2DHomMatrix& rTransform, - const GraphicObject& rGraphicObject, - const GraphicAttr& rGraphicAttr) - : BufferedDecompositionPrimitive2D(), - maTransform(rTransform), - maGraphicObject(rGraphicObject), - maGraphicAttr(rGraphicAttr) - { - } + if (getGraphicAttr().IsTransparent()) + { + // check for transparency + const double fTransparency( + std::clamp(getGraphicAttr().GetTransparency() * (1.0 / 255.0), 0.0, 1.0)); - GraphicPrimitive2D::GraphicPrimitive2D( - const basegfx::B2DHomMatrix& rTransform, - const GraphicObject& rGraphicObject) - : BufferedDecompositionPrimitive2D(), - maTransform(rTransform), - maGraphicObject(rGraphicObject), - maGraphicAttr() + if (!basegfx::fTools::equalZero(fTransparency)) { + const Primitive2DReference aUnifiedTransparence( + new UnifiedTransparencePrimitive2D(aRetval, fTransparency)); + + aRetval = Primitive2DContainer{ aUnifiedTransparence }; } + } + + if (getGraphicAttr().IsCropped()) + { + // check for cropping + // calculate scalings between real image size and logic object size. This + // is necessary since the crop values are relative to original bitmap size + const basegfx::B2DVector aObjectScale(aTransform * basegfx::B2DVector(1.0, 1.0)); + const basegfx::B2DVector aCropScaleFactor(rGraphicObject.calculateCropScaling( + aObjectScale.getX(), aObjectScale.getY(), getGraphicAttr().GetLeftCrop(), + getGraphicAttr().GetTopCrop(), getGraphicAttr().GetRightCrop(), + getGraphicAttr().GetBottomCrop())); + + // embed content in cropPrimitive + Primitive2DReference xPrimitive(new CropPrimitive2D( + aRetval, aTransform, getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(), + getGraphicAttr().GetTopCrop() * aCropScaleFactor.getY(), + getGraphicAttr().GetRightCrop() * aCropScaleFactor.getX(), + getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY())); + + aRetval = Primitive2DContainer{ xPrimitive }; + } + + rContainer.insert(rContainer.end(), aRetval.begin(), aRetval.end()); +} + +GraphicPrimitive2D::GraphicPrimitive2D(const basegfx::B2DHomMatrix& rTransform, + const GraphicObject& rGraphicObject, + const GraphicAttr& rGraphicAttr) + : BufferedDecompositionPrimitive2D() + , maTransform(rTransform) + , maGraphicObject(rGraphicObject) + , maGraphicAttr(rGraphicAttr) +{ +} + +GraphicPrimitive2D::GraphicPrimitive2D(const basegfx::B2DHomMatrix& rTransform, + const GraphicObject& rGraphicObject) + : BufferedDecompositionPrimitive2D() + , maTransform(rTransform) + , maGraphicObject(rGraphicObject) + , maGraphicAttr() +{ +} - bool GraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const - { - if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) - { - const GraphicPrimitive2D& rCompare = static_cast<const GraphicPrimitive2D&>(rPrimitive); +bool GraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const +{ + if (BufferedDecompositionPrimitive2D::operator==(rPrimitive)) + { + const GraphicPrimitive2D& rCompare = static_cast<const GraphicPrimitive2D&>(rPrimitive); - return (getTransform() == rCompare.getTransform() - && getGraphicObject() == rCompare.getGraphicObject() - && getGraphicAttr() == rCompare.getGraphicAttr()); - } + return (getTransform() == rCompare.getTransform() + && getGraphicObject() == rCompare.getGraphicObject() + && getGraphicAttr() == rCompare.getGraphicAttr()); + } - return false; - } + return false; +} - basegfx::B2DRange GraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const - { - basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0); - aRetval.transform(getTransform()); - return aRetval; - } +basegfx::B2DRange +GraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const +{ + basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0); + aRetval.transform(getTransform()); + return aRetval; +} - // provide unique ID - ImplPrimitive2DIDBlock(GraphicPrimitive2D, PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D) +// provide unique ID +ImplPrimitive2DIDBlock(GraphicPrimitive2D, PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D) } // end of namespace diff --git a/include/drawinglayer/primitive2d/graphicprimitive2d.hxx b/include/drawinglayer/primitive2d/graphicprimitive2d.hxx index b9dd4d4c0610..3bfe40ec53d7 100644 --- a/include/drawinglayer/primitive2d/graphicprimitive2d.hxx +++ b/include/drawinglayer/primitive2d/graphicprimitive2d.hxx @@ -25,67 +25,66 @@ #include <basegfx/matrix/b2dhommatrix.hxx> #include <vcl/GraphicObject.hxx> - namespace drawinglayer { - namespace primitive2d - { - /** GraphicPrimitive2D class - - Primitive to hold graphics defined by GraphicObject and GraphicAttr - combination. This includes MetaFiles and diverse pixel-oriented graphic - formats. It even includes animated GIFs, Croppings and other changes - defined in GraphicAttr. - - This makes the decomposition contain a wide variety of possibilities, - too. From a simple BitmapPrimitive over AnimatedSwitchPrimitive2D, - MetafilePrimitive2D (with and without embedding in a masking when e.g. - the Metafile is bigger than the geometry) and embeddings in - TransformPrimitive2D and MaskPrimitive2D for croppings. - - The primitive geometry area is defined by Transform. - */ - class DRAWINGLAYER_DLLPUBLIC GraphicPrimitive2D final : public BufferedDecompositionPrimitive2D - { - private: - /// the geometric definition - basegfx::B2DHomMatrix maTransform; - - /// the GraphicObject with all its content possibilities - GraphicObject maGraphicObject; - - /// The GraphicAttr with all its modification possibilities - GraphicAttr maGraphicAttr; - - /// local decomposition - virtual void create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& rViewInformation) const override; - - public: - /// constructor(s) - GraphicPrimitive2D( - const basegfx::B2DHomMatrix& rTransform, - const GraphicObject& rGraphicObject, - const GraphicAttr& rGraphicAttr); - GraphicPrimitive2D( - const basegfx::B2DHomMatrix& rTransform, - const GraphicObject& rGraphicObject); - - /// data read access - const basegfx::B2DHomMatrix& getTransform() const { return maTransform; } - const GraphicObject& getGraphicObject() const { return maGraphicObject; } - const GraphicAttr& getGraphicAttr() const { return maGraphicAttr; } - - /// compare operator - virtual bool operator==(const BasePrimitive2D& rPrimitive) const override; - - /// get range - virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override; - - /// provide unique ID - virtual sal_uInt32 getPrimitive2DID() const override; - }; - } // end of namespace primitive2d -} // end of namespace drawinglayer +namespace primitive2d +{ +/** GraphicPrimitive2D class + + Primitive to hold graphics defined by GraphicObject and GraphicAttr + combination. This includes MetaFiles and diverse pixel-oriented graphic + formats. It even includes animated GIFs, Croppings and other changes + defined in GraphicAttr. + + This makes the decomposition contain a wide variety of possibilities, + too. From a simple BitmapPrimitive over AnimatedSwitchPrimitive2D, + MetafilePrimitive2D (with and without embedding in a masking when e.g. + the Metafile is bigger than the geometry) and embeddings in + TransformPrimitive2D and MaskPrimitive2D for croppings. + + The primitive geometry area is defined by Transform. + */ +class DRAWINGLAYER_DLLPUBLIC GraphicPrimitive2D final : public BufferedDecompositionPrimitive2D +{ +private: + /// the geometric definition + basegfx::B2DHomMatrix maTransform; + + /// the GraphicObject with all its content possibilities + GraphicObject maGraphicObject; + /// The GraphicAttr with all its modification possibilities + GraphicAttr maGraphicAttr; + + /// local decomposition + virtual void + create2DDecomposition(Primitive2DContainer& rContainer, + const geometry::ViewInformation2D& rViewInformation) const override; + +public: + /// constructor(s) + GraphicPrimitive2D(const basegfx::B2DHomMatrix& rTransform, const GraphicObject& rGraphicObject, + const GraphicAttr& rGraphicAttr); + GraphicPrimitive2D(const basegfx::B2DHomMatrix& rTransform, + const GraphicObject& rGraphicObject); + + /// data read access + const basegfx::B2DHomMatrix& getTransform() const { return maTransform; } + const GraphicObject& getGraphicObject() const { return maGraphicObject; } + const GraphicAttr& getGraphicAttr() const { return maGraphicAttr; } + + /// compare operator + virtual bool operator==(const BasePrimitive2D& rPrimitive) const override; + + /// get range + virtual basegfx::B2DRange + getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override; + + /// provide unique ID + virtual sal_uInt32 getPrimitive2DID() const override; +}; + +} // end of namespace primitive2d +} // end of namespace drawinglayer /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist index 85aa95514dc4..5314fd4ccd79 100644 --- a/solenv/clang-format/blacklist +++ b/solenv/clang-format/blacklist @@ -3673,7 +3673,6 @@ drawinglayer/source/primitive2d/epsprimitive2d.cxx drawinglayer/source/primitive2d/fillgradientprimitive2d.cxx drawinglayer/source/primitive2d/fillgraphicprimitive2d.cxx drawinglayer/source/primitive2d/fillhatchprimitive2d.cxx -drawinglayer/source/primitive2d/graphicprimitive2d.cxx drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx drawinglayer/source/primitive2d/gridprimitive2d.cxx drawinglayer/source/primitive2d/groupprimitive2d.cxx @@ -5917,7 +5916,6 @@ include/drawinglayer/primitive2d/epsprimitive2d.hxx include/drawinglayer/primitive2d/fillgradientprimitive2d.hxx include/drawinglayer/primitive2d/fillgraphicprimitive2d.hxx include/drawinglayer/primitive2d/fillhatchprimitive2d.hxx -include/drawinglayer/primitive2d/graphicprimitive2d.hxx include/drawinglayer/primitive2d/graphicprimitivehelper2d.hxx include/drawinglayer/primitive2d/gridprimitive2d.hxx include/drawinglayer/primitive2d/groupprimitive2d.hxx |