1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <primitive2d/graphicprimitivehelper2d.hxx>
29 #include <vcl/graph.hxx>
32 using namespace com::sun::star
;
35 namespace drawinglayer::primitive2d
37 void FillGraphicPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*rViewInformation*/) const
39 const attribute::FillGraphicAttribute
& rAttribute
= getFillGraphic();
41 if(rAttribute
.isDefault())
44 const Graphic
& rGraphic
= rAttribute
.getGraphic();
46 if(GraphicType::Bitmap
!= rGraphic
.GetType() && GraphicType::GdiMetafile
!= rGraphic
.GetType())
49 const Size
aSize(rGraphic
.GetPrefSize());
51 if(!(aSize
.Width() && aSize
.Height()))
54 // we have a graphic (bitmap or metafile) with some size
55 if(rAttribute
.getTiling())
57 // get object range and create tiling matrices
58 std::vector
< basegfx::B2DHomMatrix
> aMatrices
;
59 texture::GeoTexSvxTiled
aTiling(
60 rAttribute
.getGraphicRange(),
61 rAttribute
.getOffsetX(),
62 rAttribute
.getOffsetY());
64 // get matrices and realloc retval
65 aTiling
.appendTransformations(aMatrices
);
67 // prepare content primitive
68 Primitive2DContainer xSeq
;
69 create2DDecompositionOfGraphic(xSeq
,
71 basegfx::B2DHomMatrix());
73 for(const auto &a
: aMatrices
)
75 rContainer
.push_back(new TransformPrimitive2D(
76 getTransformation() * a
,
77 Primitive2DContainer(xSeq
)));
82 // add graphic without tiling
83 const basegfx::B2DHomMatrix
aObjectTransform(
84 getTransformation() * basegfx::utils::createScaleTranslateB2DHomMatrix(
85 rAttribute
.getGraphicRange().getRange(),
86 rAttribute
.getGraphicRange().getMinimum()));
88 create2DDecompositionOfGraphic(rContainer
,
94 FillGraphicPrimitive2D::FillGraphicPrimitive2D(
95 basegfx::B2DHomMatrix aTransformation
,
96 const attribute::FillGraphicAttribute
& rFillGraphic
)
97 : maTransformation(std::move(aTransformation
)),
98 maFillGraphic(rFillGraphic
)
102 bool FillGraphicPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
104 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
106 const FillGraphicPrimitive2D
& rCompare
= static_cast< const FillGraphicPrimitive2D
& >(rPrimitive
);
108 return (getTransformation() == rCompare
.getTransformation()
109 && getFillGraphic() == rCompare
.getFillGraphic());
115 basegfx::B2DRange
FillGraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
117 // return range of it
118 basegfx::B2DPolygon
aPolygon(basegfx::utils::createUnitPolygon());
119 aPolygon
.transform(getTransformation());
121 return basegfx::utils::getRange(aPolygon
);
125 sal_uInt32
FillGraphicPrimitive2D::getPrimitive2DID() const
127 return PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D
;
130 } // end of namespace
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */