Branch data Line data Source code
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/fillbitmapprimitive2d.hxx>
21 : : #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
22 : : #include <basegfx/polygon/b2dpolygon.hxx>
23 : : #include <basegfx/polygon/b2dpolygontools.hxx>
24 : : #include <drawinglayer/texture/texture.hxx>
25 : : #include <basegfx/tools/canvastools.hxx>
26 : : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
27 : :
28 : : //////////////////////////////////////////////////////////////////////////////
29 : :
30 : : using namespace com::sun::star;
31 : :
32 : : //////////////////////////////////////////////////////////////////////////////
33 : :
34 : : namespace drawinglayer
35 : : {
36 : : namespace primitive2d
37 : : {
38 : 0 : Primitive2DSequence FillBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
39 : : {
40 : 0 : Primitive2DSequence aRetval;
41 : :
42 [ # # ][ # # ]: 0 : if(!getFillBitmap().isDefault())
43 : : {
44 [ # # ]: 0 : const Size aTileSizePixel(getFillBitmap().getBitmapEx().GetSizePixel());
45 : :
46 : : // is there a tile with some size at all?
47 [ # # ][ # # ]: 0 : if(aTileSizePixel.getWidth() && aTileSizePixel.getHeight())
[ # # ]
48 : : {
49 [ # # ][ # # ]: 0 : if(getFillBitmap().getTiling())
50 : : {
51 : : // get object range and create tiling matrices
52 [ # # ]: 0 : ::std::vector< basegfx::B2DHomMatrix > aMatrices;
53 [ # # ][ # # ]: 0 : texture::GeoTexSvxTiled aTiling(getFillBitmap().getTopLeft(), getFillBitmap().getSize());
[ # # ]
54 [ # # ]: 0 : aTiling.appendTransformations(aMatrices);
55 : :
56 : : // resize result
57 [ # # ]: 0 : aRetval.realloc(aMatrices.size());
58 : :
59 : : // create one primitive for each matrix
60 [ # # ]: 0 : for(sal_uInt32 a(0L); a < aMatrices.size(); a++)
61 : : {
62 [ # # ][ # # ]: 0 : basegfx::B2DHomMatrix aNewMatrix = aMatrices[a];
63 [ # # ]: 0 : aNewMatrix *= getTransformation();
64 : :
65 : : // create bitmap primitive and add to result
66 : : const Primitive2DReference xRef(
67 [ # # ][ # # ]: 0 : new BitmapPrimitive2D(getFillBitmap().getBitmapEx(), aNewMatrix));
[ # # ][ # # ]
68 : :
69 [ # # ][ # # ]: 0 : aRetval[a] = xRef;
70 [ # # ][ # # ]: 0 : }
71 : : }
72 : : else
73 : : {
74 : : // create new object transform
75 [ # # ]: 0 : basegfx::B2DHomMatrix aObjectTransform;
76 [ # # ][ # # ]: 0 : aObjectTransform.set(0L, 0L, getFillBitmap().getSize().getX());
77 [ # # ][ # # ]: 0 : aObjectTransform.set(1L, 1L, getFillBitmap().getSize().getY());
78 [ # # ][ # # ]: 0 : aObjectTransform.set(0L, 2L, getFillBitmap().getTopLeft().getX());
79 [ # # ][ # # ]: 0 : aObjectTransform.set(1L, 2L, getFillBitmap().getTopLeft().getY());
80 [ # # ]: 0 : aObjectTransform *= getTransformation();
81 : :
82 : : // create bitmap primitive and add exclusive to decomposition (hand over ownership)
83 : : const Primitive2DReference xRef(
84 [ # # ][ # # ]: 0 : new BitmapPrimitive2D(getFillBitmap().getBitmapEx(), aObjectTransform));
[ # # ][ # # ]
85 : :
86 [ # # ][ # # ]: 0 : aRetval = Primitive2DSequence(&xRef, 1L);
[ # # ][ # # ]
87 : : }
88 : : }
89 : : }
90 : :
91 : 0 : return aRetval;
92 : : }
93 : :
94 : 262 : FillBitmapPrimitive2D::FillBitmapPrimitive2D(
95 : : const basegfx::B2DHomMatrix& rTransformation,
96 : : const attribute::FillBitmapAttribute& rFillBitmap)
97 : : : BufferedDecompositionPrimitive2D(),
98 : : maTransformation(rTransformation),
99 [ + - ][ + - ]: 262 : maFillBitmap(rFillBitmap)
100 : : {
101 : 262 : }
102 : :
103 : 0 : bool FillBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
104 : : {
105 [ # # ]: 0 : if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
106 : : {
107 : 0 : const FillBitmapPrimitive2D& rCompare = static_cast< const FillBitmapPrimitive2D& >(rPrimitive);
108 : :
109 : 0 : return (getTransformation() == rCompare.getTransformation()
110 [ # # ][ # # ]: 0 : && getFillBitmap() == rCompare.getFillBitmap());
111 : : }
112 : :
113 : 0 : return false;
114 : : }
115 : :
116 : 0 : basegfx::B2DRange FillBitmapPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
117 : : {
118 : : // return range of it
119 [ # # ]: 0 : basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
120 [ # # ]: 0 : aPolygon.transform(getTransformation());
121 [ # # ][ # # ]: 0 : return basegfx::tools::getRange(aPolygon);
122 : : }
123 : :
124 : : // provide unique ID
125 : 313 : ImplPrimitrive2DIDBlock(FillBitmapPrimitive2D, PRIMITIVE2D_ID_FILLBITMAPPRIMITIVE2D)
126 : :
127 : : } // end of namespace primitive2d
128 : : } // end of namespace drawinglayer
129 : :
130 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|