tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / drawinglayer / source / primitive2d / fillgraphicprimitive2d.cxx
blob5ef71c97aa33a603dd08d347e0bd22a01f3678d1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <texture/texture.hxx>
24 #include <basegfx/matrix/b2dhommatrixtools.hxx>
25 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
27 #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx>
28 #include <utility>
29 #include <vcl/graph.hxx>
32 using namespace com::sun::star;
35 namespace drawinglayer::primitive2d
37 Primitive2DReference FillGraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
39 const attribute::FillGraphicAttribute& rAttribute = getFillGraphic();
41 if(rAttribute.isDefault())
42 return nullptr;
44 const Graphic& rGraphic = rAttribute.getGraphic();
46 if(GraphicType::Bitmap != rGraphic.GetType() && GraphicType::GdiMetafile != rGraphic.GetType())
47 return nullptr;
49 const Size aSize(rGraphic.GetPrefSize());
51 if(!(aSize.Width() && aSize.Height()))
52 return nullptr;
54 // we have a graphic (bitmap or metafile) with some size
55 Primitive2DContainer aContainer;
56 if(rAttribute.getTiling())
58 // get object range and create tiling matrices
59 std::vector< basegfx::B2DHomMatrix > aMatrices;
60 texture::GeoTexSvxTiled aTiling(
61 rAttribute.getGraphicRange(),
62 rAttribute.getOffsetX(),
63 rAttribute.getOffsetY());
65 // get matrices and realloc retval
66 aTiling.appendTransformations(aMatrices);
68 // prepare content primitive
69 Primitive2DContainer xSeq;
70 create2DDecompositionOfGraphic(xSeq,
71 rGraphic,
72 basegfx::B2DHomMatrix(),
73 getTransparency());
75 rtl::Reference<GroupPrimitive2D> xGroup = new GroupPrimitive2D(std::move(xSeq));
76 for(const auto &a : aMatrices)
78 aContainer.push_back(new TransformPrimitive2D(
79 getTransformation() * a,
80 *xGroup));
83 else
85 // add graphic without tiling
86 const basegfx::B2DHomMatrix aObjectTransform(
87 getTransformation() * basegfx::utils::createScaleTranslateB2DHomMatrix(
88 rAttribute.getGraphicRange().getRange(),
89 rAttribute.getGraphicRange().getMinimum()));
91 create2DDecompositionOfGraphic(aContainer,
92 rGraphic,
93 aObjectTransform,
94 getTransparency());
97 return new GroupPrimitive2D(std::move(aContainer));
100 FillGraphicPrimitive2D::FillGraphicPrimitive2D(
101 basegfx::B2DHomMatrix aTransformation,
102 const attribute::FillGraphicAttribute& rFillGraphic,
103 double fTransparency)
104 : maTransformation(std::move(aTransformation))
105 , maFillGraphic(rFillGraphic)
106 , maOffsetXYCreatedBitmap()
107 , mfTransparency(std::max(0.0, std::min(1.0, fTransparency)))
111 bool FillGraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
113 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
115 const FillGraphicPrimitive2D& rCompare = static_cast< const FillGraphicPrimitive2D& >(rPrimitive);
117 return (getTransformation() == rCompare.getTransformation()
118 && getFillGraphic() == rCompare.getFillGraphic()
119 && basegfx::fTools::equal(getTransparency(), rCompare.getTransparency()));
122 return false;
125 basegfx::B2DRange FillGraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
127 // return range of it
128 basegfx::B2DPolygon aPolygon(basegfx::utils::createUnitPolygon());
129 aPolygon.transform(getTransformation());
131 return basegfx::utils::getRange(aPolygon);
134 // provide unique ID
135 sal_uInt32 FillGraphicPrimitive2D::getPrimitive2DID() const
137 return PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D;
140 } // end of namespace
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */