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/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>
29 :
30 : //////////////////////////////////////////////////////////////////////////////
31 :
32 : using namespace com::sun::star;
33 :
34 : //////////////////////////////////////////////////////////////////////////////
35 :
36 : namespace drawinglayer
37 : {
38 : namespace primitive2d
39 : {
40 0 : Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
41 : {
42 0 : Primitive2DSequence aRetval;
43 :
44 0 : if(!getFillHatch().isDefault())
45 : {
46 : // create hatch
47 0 : const basegfx::BColor aHatchColor(getFillHatch().getColor());
48 0 : const double fAngle(getFillHatch().getAngle());
49 0 : ::std::vector< basegfx::B2DHomMatrix > aMatrices;
50 0 : double fDistance(getFillHatch().getDistance());
51 0 : const bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
52 :
53 : // #i120230# evtl. adapt distance
54 0 : if(bAdaptDistance)
55 : {
56 0 : const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit());
57 :
58 0 : if(fDiscreteDistance < (double)getFillHatch().getMinimalDiscreteDistance())
59 : {
60 0 : fDistance = (double)getFillHatch().getMinimalDiscreteDistance() * getDiscreteUnit();
61 : }
62 : }
63 :
64 : // get hatch transformations
65 0 : switch(getFillHatch().getStyle())
66 : {
67 : case attribute::HATCHSTYLE_TRIPLE:
68 : {
69 : // rotated 45 degrees
70 0 : texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle - F_PI4);
71 0 : aHatch.appendTransformations(aMatrices);
72 :
73 : // fall-through by purpose
74 : }
75 : case attribute::HATCHSTYLE_DOUBLE:
76 : {
77 : // rotated 90 degrees
78 0 : texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle - F_PI2);
79 0 : aHatch.appendTransformations(aMatrices);
80 :
81 : // fall-through by purpose
82 : }
83 : case attribute::HATCHSTYLE_SINGLE:
84 : {
85 : // angle as given
86 0 : texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle);
87 0 : aHatch.appendTransformations(aMatrices);
88 : }
89 : }
90 :
91 : // prepare return value
92 0 : const bool bFillBackground(getFillHatch().isFillBackground());
93 0 : aRetval.realloc(bFillBackground ? aMatrices.size() + 1L : aMatrices.size());
94 :
95 : // evtl. create filled background
96 0 : if(bFillBackground)
97 : {
98 : // create primitive for background
99 : const Primitive2DReference xRef(
100 : new PolyPolygonColorPrimitive2D(
101 : basegfx::B2DPolyPolygon(
102 0 : basegfx::tools::createPolygonFromRect(getObjectRange())), getBColor()));
103 0 : aRetval[0] = xRef;
104 : }
105 :
106 : // create primitives
107 0 : const basegfx::B2DPoint aStart(0.0, 0.0);
108 0 : const basegfx::B2DPoint aEnd(1.0, 0.0);
109 :
110 0 : for(sal_uInt32 a(0L); a < aMatrices.size(); a++)
111 : {
112 0 : const basegfx::B2DHomMatrix& rMatrix = aMatrices[a];
113 0 : basegfx::B2DPolygon aNewLine;
114 :
115 0 : aNewLine.append(rMatrix * aStart);
116 0 : aNewLine.append(rMatrix * aEnd);
117 :
118 : // create hairline
119 0 : const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor));
120 0 : aRetval[bFillBackground ? (a + 1) : a] = xRef;
121 0 : }
122 : }
123 :
124 0 : return aRetval;
125 : }
126 :
127 572 : 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 572 : maBColor(rBColor)
135 : {
136 572 : }
137 :
138 0 : bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
139 : {
140 0 : if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
141 : {
142 0 : const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive;
143 :
144 0 : return (getObjectRange() == rCompare.getObjectRange()
145 0 : && getFillHatch() == rCompare.getFillHatch()
146 0 : && getBColor() == rCompare.getBColor());
147 : }
148 :
149 0 : return false;
150 : }
151 :
152 0 : basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
153 : {
154 : // return ObjectRange
155 0 : return getObjectRange();
156 : }
157 :
158 0 : Primitive2DSequence FillHatchPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
159 : {
160 0 : ::osl::MutexGuard aGuard( m_aMutex );
161 0 : bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
162 :
163 0 : if(bAdaptDistance)
164 : {
165 : // behave view-dependent
166 0 : return DiscreteMetricDependentPrimitive2D::get2DDecomposition(rViewInformation);
167 : }
168 : else
169 : {
170 : // behave view-independent
171 0 : return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
172 0 : }
173 : }
174 :
175 : // provide unique ID
176 238 : ImplPrimitive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D)
177 :
178 : } // end of namespace primitive2d
179 : } // end of namespace drawinglayer
180 :
181 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|