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/PolyPolygonGraphicPrimitive2D.hxx>
22 #include <basegfx/matrix/b2dhommatrix.hxx>
23 #include <basegfx/matrix/b2dhommatrixtools.hxx>
24 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
25 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
28 #include <vcl/graph.hxx>
30 using namespace com::sun::star
;
32 namespace drawinglayer::primitive2d
34 void PolyPolygonGraphicPrimitive2D::create2DDecomposition(
35 Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*rViewInformation*/) const
37 if (getFillGraphic().isDefault())
40 const Graphic
& rGraphic
= getFillGraphic().getGraphic();
41 const GraphicType
aType(rGraphic
.GetType());
43 // is there a bitmap or a metafile (do we have content)?
44 if (GraphicType::Bitmap
!= aType
&& GraphicType::GdiMetafile
!= aType
)
47 const Size
aPrefSize(rGraphic
.GetPrefSize());
49 // does content have a size?
50 if (!(aPrefSize
.Width() && aPrefSize
.Height()))
53 // create SubSequence with FillGraphicPrimitive2D based on polygon range
54 const basegfx::B2DRange
aOutRange(getB2DPolyPolygon().getB2DRange());
55 const basegfx::B2DHomMatrix
aNewObjectTransform(
56 basegfx::utils::createScaleTranslateB2DHomMatrix(aOutRange
.getRange(),
57 aOutRange
.getMinimum()));
58 Primitive2DReference xSubRef
;
60 if (aOutRange
!= getDefinitionRange())
62 // we want to paint (tiled) content which is defined relative to DefinitionRange
63 // with the same tiling and offset(s) in the target range of the geometry (the
64 // polygon). The range given in the local FillGraphicAttribute defines the position
65 // of the graphic in unit coordinates relative to the DefinitionRange. Transform
66 // this using DefinitionRange to get to the global definition and then with the
67 // inverse transformation from the target range to go to unit coordinates relative
68 // to that target coordinate system.
69 basegfx::B2DRange
aAdaptedRange(getFillGraphic().getGraphicRange());
71 const basegfx::B2DHomMatrix
aFromDefinitionRangeToGlobal(
72 basegfx::utils::createScaleTranslateB2DHomMatrix(getDefinitionRange().getRange(),
73 getDefinitionRange().getMinimum()));
75 aAdaptedRange
.transform(aFromDefinitionRangeToGlobal
);
77 basegfx::B2DHomMatrix
aFromGlobalToOutRange(
78 basegfx::utils::createScaleTranslateB2DHomMatrix(aOutRange
.getRange(),
79 aOutRange
.getMinimum()));
80 aFromGlobalToOutRange
.invert();
82 aAdaptedRange
.transform(aFromGlobalToOutRange
);
84 const drawinglayer::attribute::FillGraphicAttribute
aAdaptedFillGraphicAttribute(
85 getFillGraphic().getGraphic(), aAdaptedRange
, getFillGraphic().getTiling(),
86 getFillGraphic().getOffsetX(), getFillGraphic().getOffsetY());
88 xSubRef
= new FillGraphicPrimitive2D(aNewObjectTransform
, aAdaptedFillGraphicAttribute
);
92 xSubRef
= new FillGraphicPrimitive2D(aNewObjectTransform
, getFillGraphic());
95 // embed to mask primitive
96 rContainer
.push_back(new MaskPrimitive2D(getB2DPolyPolygon(), Primitive2DContainer
{ xSubRef
}));
99 PolyPolygonGraphicPrimitive2D::PolyPolygonGraphicPrimitive2D(
100 basegfx::B2DPolyPolygon aPolyPolygon
, const basegfx::B2DRange
& rDefinitionRange
,
101 const attribute::FillGraphicAttribute
& rFillGraphic
)
102 : maPolyPolygon(std::move(aPolyPolygon
))
103 , maDefinitionRange(rDefinitionRange
)
104 , maFillGraphic(rFillGraphic
)
108 bool PolyPolygonGraphicPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
110 if (BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
112 const PolyPolygonGraphicPrimitive2D
& rCompare
113 = static_cast<const PolyPolygonGraphicPrimitive2D
&>(rPrimitive
);
115 return (getB2DPolyPolygon() == rCompare
.getB2DPolyPolygon()
116 && getDefinitionRange() == rCompare
.getDefinitionRange()
117 && getFillGraphic() == rCompare
.getFillGraphic());
124 sal_uInt32
PolyPolygonGraphicPrimitive2D::getPrimitive2DID() const
126 return PRIMITIVE2D_ID_POLYPOLYGONGRAPHICPRIMITIVE2D
;
129 } // end drawinglayer::primitive2d namespace
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */