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 :
29 : //////////////////////////////////////////////////////////////////////////////
30 :
31 : using namespace com::sun::star;
32 :
33 : //////////////////////////////////////////////////////////////////////////////
34 :
35 : namespace drawinglayer
36 : {
37 : namespace primitive2d
38 : {
39 0 : Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
40 : {
41 0 : Primitive2DSequence aRetval;
42 0 : if(!getFillHatch().isDefault())
43 : {
44 : // create hatch
45 0 : const basegfx::BColor aHatchColor(getFillHatch().getColor());
46 0 : const double fAngle(getFillHatch().getAngle());
47 0 : ::std::vector< basegfx::B2DHomMatrix > aMatrices;
48 :
49 : // get hatch transformations
50 0 : switch(getFillHatch().getStyle())
51 : {
52 : case attribute::HATCHSTYLE_TRIPLE:
53 : {
54 : // rotated 45 degrees
55 0 : texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI4);
56 0 : aHatch.appendTransformations(aMatrices);
57 :
58 : // fall-through by purpose
59 : }
60 : case attribute::HATCHSTYLE_DOUBLE:
61 : {
62 : // rotated 90 degrees
63 0 : texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI2);
64 0 : aHatch.appendTransformations(aMatrices);
65 :
66 : // fall-through by purpose
67 : }
68 : case attribute::HATCHSTYLE_SINGLE:
69 : {
70 : // angle as given
71 0 : texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle);
72 0 : aHatch.appendTransformations(aMatrices);
73 : }
74 : }
75 :
76 : // prepare return value
77 0 : const bool bFillBackground(getFillHatch().isFillBackground());
78 0 : aRetval.realloc(bFillBackground ? aMatrices.size() + 1L : aMatrices.size());
79 :
80 : // evtl. create filled background
81 0 : if(bFillBackground)
82 : {
83 : // create primitive for background
84 : const Primitive2DReference xRef(
85 : new PolyPolygonColorPrimitive2D(
86 : basegfx::B2DPolyPolygon(
87 0 : basegfx::tools::createPolygonFromRect(getObjectRange())), getBColor()));
88 0 : aRetval[0] = xRef;
89 : }
90 :
91 : // create primitives
92 0 : const basegfx::B2DPoint aStart(0.0, 0.0);
93 0 : const basegfx::B2DPoint aEnd(1.0, 0.0);
94 :
95 0 : for(sal_uInt32 a(0L); a < aMatrices.size(); a++)
96 : {
97 0 : const basegfx::B2DHomMatrix& rMatrix = aMatrices[a];
98 0 : basegfx::B2DPolygon aNewLine;
99 :
100 0 : aNewLine.append(rMatrix * aStart);
101 0 : aNewLine.append(rMatrix * aEnd);
102 :
103 : // create hairline
104 0 : const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor));
105 0 : aRetval[bFillBackground ? (a + 1) : a] = xRef;
106 0 : }
107 : }
108 :
109 0 : return aRetval;
110 : }
111 :
112 0 : FillHatchPrimitive2D::FillHatchPrimitive2D(
113 : const basegfx::B2DRange& rObjectRange,
114 : const basegfx::BColor& rBColor,
115 : const attribute::FillHatchAttribute& rFillHatch)
116 : : BufferedDecompositionPrimitive2D(),
117 : maObjectRange(rObjectRange),
118 : maFillHatch(rFillHatch),
119 0 : maBColor(rBColor)
120 : {
121 0 : }
122 :
123 0 : bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
124 : {
125 0 : if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
126 : {
127 0 : const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive;
128 :
129 0 : return (getObjectRange() == rCompare.getObjectRange()
130 0 : && getFillHatch() == rCompare.getFillHatch()
131 0 : && getBColor() == rCompare.getBColor());
132 : }
133 :
134 0 : return false;
135 : }
136 :
137 0 : basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
138 : {
139 : // return ObjectRange
140 0 : return getObjectRange();
141 : }
142 :
143 : // provide unique ID
144 0 : ImplPrimitrive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D)
145 :
146 : } // end of namespace primitive2d
147 : } // end of namespace drawinglayer
148 :
149 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|