/src/libreoffice/drawinglayer/source/primitive2d/fillgraphicprimitive2d.cxx
Line | Count | Source |
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 | | |
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> |
30 | | |
31 | | |
32 | | using namespace com::sun::star; |
33 | | |
34 | | |
35 | | namespace drawinglayer::primitive2d |
36 | | { |
37 | | Primitive2DReference FillGraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const |
38 | 0 | { |
39 | 0 | const attribute::FillGraphicAttribute& rAttribute = getFillGraphic(); |
40 | |
|
41 | 0 | if(rAttribute.isDefault()) |
42 | 0 | return nullptr; |
43 | | |
44 | 0 | const Graphic& rGraphic = rAttribute.getGraphic(); |
45 | |
|
46 | 0 | if(GraphicType::Bitmap != rGraphic.GetType() && GraphicType::GdiMetafile != rGraphic.GetType()) |
47 | 0 | return nullptr; |
48 | | |
49 | 0 | const Size aSize(rGraphic.GetPrefSize()); |
50 | |
|
51 | 0 | if(!(aSize.Width() && aSize.Height())) |
52 | 0 | return nullptr; |
53 | | |
54 | | // we have a graphic (bitmap or metafile) with some size |
55 | 0 | Primitive2DContainer aContainer; |
56 | 0 | if(rAttribute.getTiling()) |
57 | 0 | { |
58 | | // get object range and create tiling matrices |
59 | 0 | std::vector< basegfx::B2DHomMatrix > aMatrices; |
60 | 0 | texture::GeoTexSvxTiled aTiling( |
61 | 0 | rAttribute.getGraphicRange(), |
62 | 0 | rAttribute.getOffsetX(), |
63 | 0 | rAttribute.getOffsetY()); |
64 | | |
65 | | // get matrices and realloc retval |
66 | 0 | aTiling.appendTransformations(aMatrices); |
67 | | |
68 | | // prepare content primitive |
69 | 0 | Primitive2DContainer xSeq; |
70 | 0 | create2DDecompositionOfGraphic(xSeq, |
71 | 0 | rGraphic, |
72 | 0 | basegfx::B2DHomMatrix(), |
73 | 0 | getTransparency()); |
74 | |
|
75 | 0 | rtl::Reference<GroupPrimitive2D> xGroup = new GroupPrimitive2D(std::move(xSeq)); |
76 | 0 | for(const auto &a : aMatrices) |
77 | 0 | { |
78 | 0 | aContainer.push_back(new TransformPrimitive2D( |
79 | 0 | getTransformation() * a, |
80 | 0 | *xGroup)); |
81 | 0 | } |
82 | 0 | } |
83 | 0 | else |
84 | 0 | { |
85 | | // add graphic without tiling |
86 | 0 | const basegfx::B2DHomMatrix aObjectTransform( |
87 | 0 | getTransformation() * basegfx::utils::createScaleTranslateB2DHomMatrix( |
88 | 0 | rAttribute.getGraphicRange().getRange(), |
89 | 0 | rAttribute.getGraphicRange().getMinimum())); |
90 | |
|
91 | 0 | create2DDecompositionOfGraphic(aContainer, |
92 | 0 | rGraphic, |
93 | 0 | aObjectTransform, |
94 | 0 | getTransparency()); |
95 | 0 | } |
96 | |
|
97 | 0 | return new GroupPrimitive2D(std::move(aContainer)); |
98 | 0 | } |
99 | | |
100 | | FillGraphicPrimitive2D::FillGraphicPrimitive2D( |
101 | | basegfx::B2DHomMatrix aTransformation, |
102 | | const attribute::FillGraphicAttribute& rFillGraphic, |
103 | | double fTransparency) |
104 | 0 | : maTransformation(std::move(aTransformation)) |
105 | 0 | , maFillGraphic(rFillGraphic) |
106 | 0 | , maOffsetXYCreatedBitmap() |
107 | 0 | , mfTransparency(std::max(0.0, std::min(1.0, fTransparency))) |
108 | 0 | { |
109 | 0 | } |
110 | | |
111 | | bool FillGraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const |
112 | 0 | { |
113 | 0 | if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) |
114 | 0 | { |
115 | 0 | const FillGraphicPrimitive2D& rCompare = static_cast< const FillGraphicPrimitive2D& >(rPrimitive); |
116 | |
|
117 | 0 | return (getTransformation() == rCompare.getTransformation() |
118 | 0 | && getFillGraphic() == rCompare.getFillGraphic() |
119 | 0 | && basegfx::fTools::equal(getTransparency(), rCompare.getTransparency())); |
120 | 0 | } |
121 | | |
122 | 0 | return false; |
123 | 0 | } |
124 | | |
125 | | basegfx::B2DRange FillGraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const |
126 | 0 | { |
127 | | // return range of it |
128 | 0 | basegfx::B2DPolygon aPolygon(basegfx::utils::createUnitPolygon()); |
129 | 0 | aPolygon.transform(getTransformation()); |
130 | |
|
131 | 0 | return aPolygon.getB2DRange(); |
132 | 0 | } |
133 | | |
134 | | // provide unique ID |
135 | | sal_uInt32 FillGraphicPrimitive2D::getPrimitive2DID() const |
136 | 0 | { |
137 | 0 | return PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D; |
138 | 0 | } |
139 | | |
140 | | } // end of namespace |
141 | | |
142 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |