LibreOffice Module drawinglayer (master) 1
PolyPolygonGraphicPrimitive2D.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
27#include <utility>
28#include <vcl/graph.hxx>
29
30using namespace com::sun::star;
31
33{
35 Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*rViewInformation*/) const
36{
37 if (getFillGraphic().isDefault())
38 return;
39
40 const Graphic& rGraphic = getFillGraphic().getGraphic();
41 const GraphicType aType(rGraphic.GetType());
42
43 // is there a bitmap or a metafile (do we have content)?
44 if (GraphicType::Bitmap != aType && GraphicType::GdiMetafile != aType)
45 return;
46
47 const Size aPrefSize(rGraphic.GetPrefSize());
48
49 // does content have a size?
50 if (!(aPrefSize.Width() && aPrefSize.Height()))
51 return;
52
53 // create SubSequence with FillGraphicPrimitive2D based on polygon range
55 const basegfx::B2DHomMatrix aNewObjectTransform(
57 aOutRange.getMinimum()));
59
60 if (aOutRange != getDefinitionRange())
61 {
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());
70
71 const basegfx::B2DHomMatrix aFromDefinitionRangeToGlobal(
73 getDefinitionRange().getMinimum()));
74
75 aAdaptedRange.transform(aFromDefinitionRangeToGlobal);
76
77 basegfx::B2DHomMatrix aFromGlobalToOutRange(
79 aOutRange.getMinimum()));
80 aFromGlobalToOutRange.invert();
81
82 aAdaptedRange.transform(aFromGlobalToOutRange);
83
84 const drawinglayer::attribute::FillGraphicAttribute aAdaptedFillGraphicAttribute(
85 getFillGraphic().getGraphic(), aAdaptedRange, getFillGraphic().getTiling(),
86 getFillGraphic().getOffsetX(), getFillGraphic().getOffsetY());
87
88 xSubRef = new FillGraphicPrimitive2D(aNewObjectTransform, aAdaptedFillGraphicAttribute);
89 }
90 else
91 {
92 xSubRef = new FillGraphicPrimitive2D(aNewObjectTransform, getFillGraphic());
93 }
94
95 // embed to mask primitive
96 rContainer.push_back(new MaskPrimitive2D(getB2DPolyPolygon(), Primitive2DContainer{ xSubRef }));
97}
98
100 basegfx::B2DPolyPolygon aPolyPolygon, const basegfx::B2DRange& rDefinitionRange,
101 const attribute::FillGraphicAttribute& rFillGraphic)
102 : maPolyPolygon(std::move(aPolyPolygon))
103 , maDefinitionRange(rDefinitionRange)
104 , maFillGraphic(rFillGraphic)
105{
106}
107
109{
110 if (BufferedDecompositionPrimitive2D::operator==(rPrimitive))
111 {
112 const PolyPolygonGraphicPrimitive2D& rCompare
113 = static_cast<const PolyPolygonGraphicPrimitive2D&>(rPrimitive);
114
115 return (getB2DPolyPolygon() == rCompare.getB2DPolyPolygon()
116 && getDefinitionRange() == rCompare.getDefinitionRange()
117 && getFillGraphic() == rCompare.getFillGraphic());
118 }
119
120 return false;
121}
122
123// provide unique ID
125{
127}
128
129} // end drawinglayer::primitive2d namespace
130
131/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Size GetPrefSize() const
GraphicType GetType() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
B2DVector getRange() const
B2DPoint getMinimum() const
css::geometry::RealRectangle2D getRange(const css::uno::Sequence< css::beans::PropertyValue > &rViewParameters)
The getRange implementation for UNO API will use getRange from this implementation.
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const
The default implementation will use getDecomposition results to create the range.
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition.
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
const attribute::FillGraphicAttribute & getFillGraphic() const
PolyPolygonGraphicPrimitive2D(basegfx::B2DPolyPolygon aPolyPolygon, const basegfx::B2DRange &rDefinitionRange, const attribute::FillGraphicAttribute &rFillGraphic)
const basegfx::B2DPolyPolygon & getB2DPolyPolygon() const
data read access
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
#define PRIMITIVE2D_ID_POLYPOLYGONGRAPHICPRIMITIVE2D
GraphicType
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
basegfx::B2DPolyPolygon maPolyPolygon