1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26 
27 #include <outact.hxx>
28 #include <vcl/gradient.hxx>
29 
30 using namespace ::com::sun::star;
31 
32 // ---------------------------------------------------------------
33 
CGMOutAct(CGM & rCGM)34 CGMOutAct::CGMOutAct( CGM& rCGM )
35 {
36 	mpCGM = &rCGM;
37 	mnCurrentPage = 0;
38     mnGroupActCount = mnGroupLevel = 0;
39 	mpGroupLevel = new sal_uInt32[ CGM_OUTACT_MAX_GROUP_LEVEL ];
40 	mpPoints = (Point*)new sal_Int8[ 0x2000 * sizeof( Point ) ];
41 	mpFlags = new sal_uInt8[ 0x2000 ];
42 
43 	mnIndex = 0;
44 	mpGradient = NULL;
45 };
46 
47 // ---------------------------------------------------------------
48 
~CGMOutAct()49 CGMOutAct::~CGMOutAct()
50 {
51 	delete[] (sal_Int8*) mpPoints;
52 	delete[] mpFlags;
53 	delete[] mpGroupLevel;
54 
55 	if ( mpGradient )
56 		delete mpGradient;
57 };
58 
59 // ---------------------------------------------------------------
60 
BeginFigure()61 void CGMOutAct::BeginFigure()
62 {
63 	if ( mnIndex )
64 		EndFigure();
65 
66 	BeginGroup();
67 	mnIndex = 0;
68 }
69 
70 // ---------------------------------------------------------------
71 
CloseRegion()72 void CGMOutAct::CloseRegion()
73 {
74 	if ( mnIndex > 2 )
75 	{
76 		NewRegion();
77 		DrawPolyPolygon( maPolyPolygon );
78 		maPolyPolygon.Clear();
79 	}
80 }
81 
82 // ---------------------------------------------------------------
83 
NewRegion()84 void CGMOutAct::NewRegion()
85 {
86 	if ( mnIndex > 2 )
87 	{
88 		Polygon aPolygon( mnIndex, mpPoints, mpFlags );
89 		maPolyPolygon.Insert( aPolygon );
90 	}
91 	mnIndex = 0;
92 }
93 
94 // ---------------------------------------------------------------
95 
EndFigure()96 void CGMOutAct::EndFigure()
97 {
98 	NewRegion();
99 	DrawPolyPolygon( maPolyPolygon );
100 	maPolyPolygon.Clear();
101 	EndGroup();
102 	mnIndex = 0;
103 }
104 
105 // ---------------------------------------------------------------
106 
RegPolyLine(Polygon & rPolygon,sal_Bool bReverse)107 void CGMOutAct::RegPolyLine( Polygon& rPolygon, sal_Bool bReverse )
108 {
109 	sal_uInt16 nPoints = rPolygon.GetSize();
110 	if ( nPoints )
111 	{
112 		if ( bReverse )
113 		{
114 			for ( sal_uInt16 i = 0; i <  nPoints; i++ )
115 			{
116 				mpPoints[ mnIndex + i ] = rPolygon.GetPoint( nPoints - i - 1 );
117 				mpFlags[ mnIndex + i ] = (sal_Int8)rPolygon.GetFlags( nPoints - i - 1 );
118 			}
119 		}
120 		else
121 		{
122 			for ( sal_uInt16 i = 0; i <  nPoints; i++ )
123 			{
124 				mpPoints[ mnIndex + i ] = rPolygon.GetPoint( i );
125 				mpFlags[ mnIndex + i ] = (sal_Int8)rPolygon.GetFlags( i );
126 			}
127 		}
128 		mnIndex = mnIndex + nPoints;
129 	}
130 }
131 
132 // ---------------------------------------------------------------
133 
SetGradientOffset(long nHorzOfs,long nVertOfs,sal_uInt32)134 void CGMOutAct::SetGradientOffset( long nHorzOfs, long nVertOfs, sal_uInt32 /*nType*/ )
135 {
136 	if ( !mpGradient )
137 		mpGradient = new awt::Gradient;
138 	mpGradient->XOffset = ( (sal_uInt16)nHorzOfs & 0x7f );
139 	mpGradient->YOffset = ( (sal_uInt16)nVertOfs & 0x7f );
140 }
141 
142 // ---------------------------------------------------------------
143 
SetGradientAngle(long nAngle)144 void CGMOutAct::SetGradientAngle( long nAngle )
145 {
146 	if ( !mpGradient )
147 		mpGradient = new awt::Gradient;
148 	mpGradient->Angle = sal::static_int_cast< sal_Int16 >(nAngle);
149 }
150 
151 // ---------------------------------------------------------------
152 
SetGradientDescriptor(sal_uInt32 nColorFrom,sal_uInt32 nColorTo)153 void CGMOutAct::SetGradientDescriptor( sal_uInt32 nColorFrom, sal_uInt32 nColorTo )
154 {
155 	if ( !mpGradient )
156 		mpGradient = new awt::Gradient;
157 	mpGradient->StartColor = nColorFrom;
158 	mpGradient->EndColor = nColorTo;
159 }
160 
161 // ---------------------------------------------------------------
162 
SetGradientStyle(sal_uInt32 nStyle,double)163 void CGMOutAct::SetGradientStyle( sal_uInt32 nStyle, double /*fRatio*/ )
164 {
165 	if ( !mpGradient )
166 		mpGradient = new awt::Gradient;
167 	switch ( nStyle )
168 	{
169 		case 0xff :
170 		{
171 			mpGradient->Style = awt::GradientStyle_AXIAL;
172 		}
173 		break;
174 		case 4 :
175 		{
176 			mpGradient->Style = awt::GradientStyle_RADIAL;			// CONICAL
177 		}
178 		break;
179 		case 3 :
180 		{
181 			mpGradient->Style = awt::GradientStyle_RECT;
182 		}
183 		break;
184 		case 2 :
185 		{
186 			mpGradient->Style = awt::GradientStyle_ELLIPTICAL;
187 		}
188 		break;
189 		default :
190 		{
191 			mpGradient->Style = awt::GradientStyle_LINEAR;
192 		}
193 	}
194 }
195 
196 
197