fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / drawinglayer / source / primitive2d / fillhatchprimitive2d.cxx
blob6229268646cb2120a1cdb3abc82bba7537f44c00
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/fillhatchprimitive2d.hxx>
21 #include <drawinglayer/texture/texture.hxx>
22 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <basegfx/polygon/b2dpolygon.hxx>
25 #include <basegfx/tools/canvastools.hxx>
26 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
27 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
28 #include <drawinglayer/geometry/viewinformation2d.hxx>
30 //////////////////////////////////////////////////////////////////////////////
32 using namespace com::sun::star;
34 //////////////////////////////////////////////////////////////////////////////
36 namespace drawinglayer
38 namespace primitive2d
40 Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
42 Primitive2DSequence aRetval;
44 if(!getFillHatch().isDefault())
46 // create hatch
47 const basegfx::BColor aHatchColor(getFillHatch().getColor());
48 const double fAngle(getFillHatch().getAngle());
49 ::std::vector< basegfx::B2DHomMatrix > aMatrices;
50 double fDistance(getFillHatch().getDistance());
51 const bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
53 // #i120230# evtl. adapt distance
54 if(bAdaptDistance)
56 const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit());
58 if(fDiscreteDistance < (double)getFillHatch().getMinimalDiscreteDistance())
60 fDistance = (double)getFillHatch().getMinimalDiscreteDistance() * getDiscreteUnit();
64 // get hatch transformations
65 switch(getFillHatch().getStyle())
67 case attribute::HATCHSTYLE_TRIPLE:
69 // rotated 45 degrees
70 texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle - F_PI4);
71 aHatch.appendTransformations(aMatrices);
73 // fall-through by purpose
75 case attribute::HATCHSTYLE_DOUBLE:
77 // rotated 90 degrees
78 texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle - F_PI2);
79 aHatch.appendTransformations(aMatrices);
81 // fall-through by purpose
83 case attribute::HATCHSTYLE_SINGLE:
85 // angle as given
86 texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle);
87 aHatch.appendTransformations(aMatrices);
91 // prepare return value
92 const bool bFillBackground(getFillHatch().isFillBackground());
93 aRetval.realloc(bFillBackground ? aMatrices.size() + 1L : aMatrices.size());
95 // evtl. create filled background
96 if(bFillBackground)
98 // create primitive for background
99 const Primitive2DReference xRef(
100 new PolyPolygonColorPrimitive2D(
101 basegfx::B2DPolyPolygon(
102 basegfx::tools::createPolygonFromRect(getObjectRange())), getBColor()));
103 aRetval[0] = xRef;
106 // create primitives
107 const basegfx::B2DPoint aStart(0.0, 0.0);
108 const basegfx::B2DPoint aEnd(1.0, 0.0);
110 for(sal_uInt32 a(0L); a < aMatrices.size(); a++)
112 const basegfx::B2DHomMatrix& rMatrix = aMatrices[a];
113 basegfx::B2DPolygon aNewLine;
115 aNewLine.append(rMatrix * aStart);
116 aNewLine.append(rMatrix * aEnd);
118 // create hairline
119 const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor));
120 aRetval[bFillBackground ? (a + 1) : a] = xRef;
124 return aRetval;
127 FillHatchPrimitive2D::FillHatchPrimitive2D(
128 const basegfx::B2DRange& rObjectRange,
129 const basegfx::BColor& rBColor,
130 const attribute::FillHatchAttribute& rFillHatch)
131 : DiscreteMetricDependentPrimitive2D(),
132 maObjectRange(rObjectRange),
133 maFillHatch(rFillHatch),
134 maBColor(rBColor)
138 bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
140 if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
142 const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive;
144 return (getObjectRange() == rCompare.getObjectRange()
145 && getFillHatch() == rCompare.getFillHatch()
146 && getBColor() == rCompare.getBColor());
149 return false;
152 basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
154 // return ObjectRange
155 return getObjectRange();
158 Primitive2DSequence FillHatchPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
160 ::osl::MutexGuard aGuard( m_aMutex );
161 bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
163 if(bAdaptDistance)
165 // behave view-dependent
166 return DiscreteMetricDependentPrimitive2D::get2DDecomposition(rViewInformation);
168 else
170 // behave view-independent
171 return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
175 // provide unique ID
176 ImplPrimitive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D)
178 } // end of namespace primitive2d
179 } // end of namespace drawinglayer
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */