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 <drawinglayer/primitive2d/graphicprimitive2d.hxx>
22 #include <basegfx/polygon/b2dpolygon.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <drawinglayer/texture/texture.hxx>
25 #include <basegfx/matrix/b2dhommatrixtools.hxx>
26 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
27 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
29 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
30 #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx>
33 using namespace com::sun::star
;
36 namespace drawinglayer
40 void FillGraphicPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*rViewInformation*/) const
42 const attribute::FillGraphicAttribute
& rAttribute
= getFillGraphic();
44 if(!rAttribute
.isDefault())
46 const Graphic
& rGraphic
= rAttribute
.getGraphic();
48 if(GraphicType::Bitmap
== rGraphic
.GetType() || GraphicType::GdiMetafile
== rGraphic
.GetType())
50 const Size
aSize(rGraphic
.GetPrefSize());
52 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(size_t a(0); a
< aMatrices
.size(); a
++)
75 rContainer
.push_back(new TransformPrimitive2D(
76 getTransformation() * aMatrices
[a
],
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
,
97 FillGraphicPrimitive2D::FillGraphicPrimitive2D(
98 const basegfx::B2DHomMatrix
& rTransformation
,
99 const attribute::FillGraphicAttribute
& rFillGraphic
)
100 : BufferedDecompositionPrimitive2D(),
101 maTransformation(rTransformation
),
102 maFillGraphic(rFillGraphic
)
106 bool FillGraphicPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
108 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
110 const FillGraphicPrimitive2D
& rCompare
= static_cast< const FillGraphicPrimitive2D
& >(rPrimitive
);
112 return (getTransformation() == rCompare
.getTransformation()
113 && getFillGraphic() == rCompare
.getFillGraphic());
119 basegfx::B2DRange
FillGraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
121 // return range of it
122 basegfx::B2DPolygon
aPolygon(basegfx::utils::createUnitPolygon());
123 aPolygon
.transform(getTransformation());
125 return basegfx::utils::getRange(aPolygon
);
129 ImplPrimitive2DIDBlock(FillGraphicPrimitive2D
, PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D
)
131 } // end of namespace primitive2d
132 } // end of namespace drawinglayer
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */