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 "elements.hxx"
28 
29 // ---------------------------------------------------------------
30 
31 
CGMElements(CGM & rCGM)32 CGMElements::CGMElements( CGM& rCGM ) :
33 	mpCGM ( &rCGM )
34 {
35 	Init();
36 };
37 
38 // ---------------------------------------------------------------
39 
~CGMElements()40 CGMElements::~CGMElements()
41 {
42 	DeleteTable( aHatchTable );
43 	DeleteAllBundles( aLineList );
44 	DeleteAllBundles( aMarkerList );
45 	DeleteAllBundles( aEdgeList );
46 	DeleteAllBundles( aTextList );
47 	DeleteAllBundles( aFillList );
48 }
49 
50 // ---------------------------------------------------------------
51 
operator =(CGMElements & rSource)52 CGMElements& CGMElements::operator=( CGMElements& rSource )
53 {
54 	sal_uInt32 nIndex;
55 
56 	nVDCIntegerPrecision = rSource.nVDCIntegerPrecision;
57 	nIntegerPrecision = rSource.nIntegerPrecision;
58 	eRealPrecision = rSource.eRealPrecision;
59 	nRealSize = rSource.nRealSize;
60 	nIndexPrecision = rSource.nIndexPrecision;
61 	nColorPrecision = rSource.nColorPrecision;
62 	nColorIndexPrecision = rSource.nColorIndexPrecision;
63 
64 	nMetaFileVersion = rSource.nMetaFileVersion;
65 	eScalingMode = rSource.eScalingMode;
66 	nScalingFactor = rSource.nScalingFactor;
67 	eVDCType = rSource.eVDCType;
68 	eVDCRealPrecision = rSource.eVDCRealPrecision;
69 	nVDCRealSize = rSource.nVDCRealSize;
70 	aVDCExtent = rSource.aVDCExtent;
71 	aVDCExtentMaximum = rSource.aVDCExtentMaximum;
72 	eDeviceViewPortMode = rSource.eDeviceViewPortMode;
73 	nDeviceViewPortScale = rSource.nDeviceViewPortScale;
74 	eDeviceViewPortMap = rSource.eDeviceViewPortMap;
75 	eDeviceViewPortMapH = rSource.eDeviceViewPortMapH;
76 	eDeviceViewPortMapV = rSource.eDeviceViewPortMapV;
77 	aDeviceViewPort = rSource.aDeviceViewPort;
78 	nMitreLimit = rSource.nMitreLimit;
79 	eClipIndicator = rSource.eClipIndicator;
80 	aClipRect = rSource.aClipRect;
81 	eColorSelectionMode = rSource.eColorSelectionMode;
82 	eColorModel = rSource.eColorModel;
83 	nColorMaximumIndex = rSource.nColorMaximumIndex;
84 	nLatestColorMaximumIndex = rSource.nLatestColorMaximumIndex;
85 
86 	for ( nIndex = 1; nIndex < 256; nIndex++ )		// do not overwrite the background color
87 	{
88 		aColorTableEntryIs[ nIndex ] = rSource.aColorTableEntryIs[ nIndex ];
89 		aColorTable[ nIndex ] = rSource.aColorTable[ nIndex ];
90 		aLatestColorTable[ nIndex ] = rSource.aColorTable[ nIndex ];
91 	}
92 
93 	for ( nIndex = 0; nIndex < 8; nIndex++ )
94 	{
95 		nColorValueExtent[ nIndex ] = rSource.nColorValueExtent[ nIndex ];
96 	}
97 	nAspectSourceFlags = rSource.nAspectSourceFlags;
98 
99 	CopyAllBundles( rSource.aLineList, aLineList );
100 	aLineBundle = rSource.aLineBundle;
101 	pLineBundle = (LineBundle*)GetBundle( aLineList, rSource.pLineBundle->GetIndex() );
102 	eLineWidthSpecMode = rSource.eLineWidthSpecMode;
103 	eLineCapType = rSource.eLineCapType;
104 	eLineJoinType = rSource.eLineJoinType;
105 
106 	CopyAllBundles( rSource.aMarkerList, aMarkerList );
107 	aMarkerBundle = rSource.aMarkerBundle;
108 	pMarkerBundle = (MarkerBundle*)GetBundle( aMarkerList, rSource.pMarkerBundle->GetIndex() );
109 	eMarkerSizeSpecMode = rSource.eMarkerSizeSpecMode;
110 
111 	CopyAllBundles( rSource.aEdgeList, aEdgeList );
112 	aEdgeBundle = rSource.aEdgeBundle;
113 	pEdgeBundle = (EdgeBundle*)GetBundle( aEdgeList, rSource.pEdgeBundle->GetIndex() );
114 	eEdgeVisibility = rSource.eEdgeVisibility;
115 	eEdgeWidthSpecMode = rSource.eEdgeWidthSpecMode;
116 
117 	CopyAllBundles( rSource.aTextList, aTextList );
118 	aTextBundle = rSource.aTextBundle;
119 	pTextBundle = (TextBundle*)GetBundle( aTextList, rSource.pTextBundle->GetIndex() );
120 	nCharacterHeight = rSource.nCharacterHeight;
121 	nCharacterOrientation[ 0 ] = rSource.nCharacterOrientation[ 0 ];
122 	nCharacterOrientation[ 1 ] = rSource.nCharacterOrientation[ 1 ];
123 	nCharacterOrientation[ 2 ] = rSource.nCharacterOrientation[ 2 ];
124 	nCharacterOrientation[ 3 ] = rSource.nCharacterOrientation[ 3 ];
125 	eUnderlineMode = rSource.eUnderlineMode;
126 	nUnderlineColor = rSource.nUnderlineColor;
127 	eTextPath = rSource.eTextPath;
128 	eTextAlignmentH = rSource.eTextAlignmentH;
129 	eTextAlignmentV = rSource.eTextAlignmentV;
130 	nTextAlignmentHCont = rSource.nTextAlignmentHCont;
131 	nTextAlignmentVCont = rSource.nTextAlignmentVCont;
132 	nCharacterSetIndex = rSource.nCharacterSetIndex;
133 	nAlternateCharacterSetIndex = rSource.nAlternateCharacterSetIndex;
134 	aFontList = rSource.aFontList;
135 	eCharacterCodingA = rSource.eCharacterCodingA;
136 
137 	CopyAllBundles( rSource.aFillList, aFillList );
138 	aFillBundle = rSource.aFillBundle;
139 	pFillBundle = (FillBundle*)GetBundle( aFillList, rSource.pFillBundle->GetIndex() );
140 	aFillRefPoint = rSource.aFillRefPoint;
141 	eTransparency = rSource.eTransparency;
142 	nAuxiliaryColor = rSource.nAuxiliaryColor;
143 
144 	DeleteTable( aHatchTable );
145 	HatchEntry*	pSource = (HatchEntry*)rSource.aHatchTable.First();
146 	while ( pSource )
147 	{
148 		sal_uInt32	nKey = rSource.aHatchTable.GetKey( pSource );
149 		aHatchTable.Insert( nKey, new HatchEntry( *pSource ) );
150 		pSource = (HatchEntry*)rSource.aHatchTable.Next();
151 	}
152 	bSegmentCount = rSource.bSegmentCount;
153 	return (*this);
154 }
155 
156 // ---------------------------------------------------------------
157 
Init()158 void CGMElements::Init()
159 {
160 
161 	nIntegerPrecision = nIndexPrecision = 2;
162 	nRealSize = nVDCRealSize = 4;
163 	nColorIndexPrecision = 1;
164 	nColorPrecision = 1;
165 	nVDCIntegerPrecision = 2;
166 	eRealPrecision = eVDCRealPrecision = RP_FIXED;		//RP_FLOAT;
167 
168 	nMetaFileVersion = 1;
169 	eScalingMode = SM_ABSTRACT;
170 	eVDCType = VDC_INTEGER;
171 	aVDCExtent.Left = aVDCExtent.Bottom = 0;
172 //	aVDCExtent.Right = aVDCExtent.Top = 32767;
173 	aVDCExtent.Right = aVDCExtent.Top = 1.0;
174 	aVDCExtentMaximum.Left = aVDCExtentMaximum.Bottom = 0;
175 //	aVDCExtentMaximum.Right = aVDCExtentMaximum.Top = 32767;
176 	aVDCExtentMaximum.Right = aVDCExtentMaximum.Top = 1.0;
177 
178 	eDeviceViewPortMode = DVPM_FRACTION;
179 	nDeviceViewPortScale = 1;
180 	eDeviceViewPortMap = DVPM_FORCED;
181 	eDeviceViewPortMapH = DVPMH_LEFT;
182 	eDeviceViewPortMapV = DVPMV_BOTTOM;
183 	aDeviceViewPort.Left = 0;
184 	aDeviceViewPort.Top = 1;
185 	aDeviceViewPort.Right = 0;
186 	aDeviceViewPort.Bottom = 1;
187 
188 	nMitreLimit = 32767;
189 	eClipIndicator = CI_ON;
190 	aClipRect = aVDCExtent;
191 
192 	eColorSelectionMode = CSM_INDEXED;
193 	eColorModel = CM_RGB;
194 	nColorMaximumIndex = 63;
195 	int i;
196 	for ( i = 0; i < 256; aColorTableEntryIs[ i++ ] = 0 ) ;
197 	aColorTable[ 0 ] = 0;
198 	for ( i = 1; i < 256; aColorTable[ i++ ] = 0xffffff ) ;
199 	nLatestColorMaximumIndex = 63;
200 	aLatestColorTable[ 0 ] = 0;
201 	for ( i = 1; i < 256; aLatestColorTable[ i++ ] = 0xffffff ) ;
202 	nColorValueExtent[ 0 ] = nColorValueExtent[ 1 ] = nColorValueExtent[ 2 ] = 0;
203 	nColorValueExtent[ 3 ] = nColorValueExtent[ 4 ] = nColorValueExtent[ 5 ] = 255;
204 
205 	nAspectSourceFlags = 0;		// all flags are individual
206 
207 	eLineWidthSpecMode = SM_SCALED;			// line parameter
208 	eLineCapType = LCT_NONE;
209 	eLineJoinType = LJT_NONE;
210 	pLineBundle = &aLineBundle;					// line bundle parameter
211 	aLineBundle.SetIndex( 1 );
212 	aLineBundle.eLineType = LT_SOLID;
213 	aLineBundle.nLineWidth = 1;
214 	aLineBundle.SetColor( 0xffffff );
215 	InsertBundle( aLineList, aLineBundle );
216 
217 	eMarkerSizeSpecMode = SM_SCALED;			// marker parameter
218 	pMarkerBundle = &aMarkerBundle;				// marker bundle parameter
219 	aMarkerBundle.SetIndex( 1 );
220 	aMarkerBundle.eMarkerType = MT_STAR;
221 	aMarkerBundle.nMarkerSize = 1;
222 	aMarkerBundle.SetColor( 0xffffff );
223 	InsertBundle( aMarkerList, aMarkerBundle );
224 
225 	eEdgeVisibility = EV_OFF;					// edge parameter
226 	eEdgeWidthSpecMode = SM_SCALED;
227 	pEdgeBundle = &aEdgeBundle;					// edge bundle parameter
228 	aEdgeBundle.SetIndex( 1 );
229 	aEdgeBundle.eEdgeType = ET_SOLID;
230 	aEdgeBundle.nEdgeWidth = 1;
231 	aEdgeBundle.SetColor( 0xffffff );
232 	InsertBundle( aEdgeList, aEdgeBundle );
233 
234 	nCharacterHeight = 327;						// text parameter
235 	nCharacterOrientation[0] = 0;
236 	nCharacterOrientation[1] = 1;
237 	nCharacterOrientation[2] = 1;
238 	nCharacterOrientation[3] = 0;
239 	eUnderlineMode = UM_OFF;
240 	nUnderlineColor = 0xffffff;
241 	eTextPath = TPR_RIGHT;
242 	eTextAlignmentH = TAH_NORMAL;
243 	eTextAlignmentV = TAV_NORMAL;
244 	nCharacterSetIndex = nAlternateCharacterSetIndex = 1;
245 	eCharacterCodingA = CCA_BASIC_7;
246 	pTextBundle = &aTextBundle;					// text bundle parameter
247 	aTextBundle.SetIndex( 1 );
248 	aTextBundle.nTextFontIndex = 1;
249 	aTextBundle.eTextPrecision = TPR_STRING;
250 	aTextBundle.nCharacterExpansion = 1;
251 	aTextBundle.nCharacterSpacing = 0;
252 	aTextBundle.SetColor( 0xffffff );
253 	InsertBundle( aTextList, aTextBundle );
254 
255 	pFillBundle = &aFillBundle;					// fill bundle parameter
256 	aFillBundle.SetIndex( 1 );
257 	aFillBundle.eFillInteriorStyle = FIS_HOLLOW;
258 	aFillBundle.nFillHatchIndex = 1;
259 	aFillBundle.nFillPatternIndex = 1;
260 	aFillBundle.SetColor( 0xffffff );
261 	InsertBundle( aFillList, aFillBundle );
262 
263 	ImplInsertHatch( 0, 0, 0, 0 );
264 	ImplInsertHatch( 1, 0, 125, 0 );
265 	ImplInsertHatch( 2, 0, 125, 900 );
266 	ImplInsertHatch( 3, 0, 125, 450 );
267 	ImplInsertHatch( 4, 0, 125, 1350 );
268 	ImplInsertHatch( 5, 1, 125, 0 );
269 	ImplInsertHatch( 6, 1, 125, 450 );
270 	ImplInsertHatch( -1, 0, 75, 0 );
271 	ImplInsertHatch( -2, 0, 75, 900 );
272 	ImplInsertHatch( -3, 0, 75, 450 );
273 	ImplInsertHatch( -4, 0, 75, 1350 );
274 	ImplInsertHatch( -5, 1, 75, 0 );
275 	ImplInsertHatch( -6, 1, 75, 450 );
276 	ImplInsertHatch( -7, 2, 125, 0 );
277 	ImplInsertHatch( -8, 2, 125, 900 );
278 	ImplInsertHatch( -9, 2, 125, 450 );
279 	ImplInsertHatch( -10, 2, 125, 1350 );
280 	ImplInsertHatch( -11, 0, 40, 0 );
281 	ImplInsertHatch( -12, 0, 40, 900 );
282 	ImplInsertHatch( -13, 0, 40, 450 );
283 	ImplInsertHatch( -14, 0, 40, 1350 );
284 	ImplInsertHatch( -15, 1, 40, 0 );
285 	ImplInsertHatch( -16, 1, 40, 900 );
286 	ImplInsertHatch( -21, 0, 250, 0 );
287 	ImplInsertHatch( -22, 0, 250, 900 );
288 	ImplInsertHatch( -23, 0, 250, 450 );
289 	ImplInsertHatch( -24, 0, 250, 1350 );
290 	ImplInsertHatch( -25, 1, 250, 0 );
291 	ImplInsertHatch( -26, 1, 250, 450 );
292 
293 	eTransparency = T_ON;
294 
295 	nBackGroundColor = nAuxiliaryColor = 0;
296 
297 	bSegmentCount = sal_False;
298 }
299 
300 // ---------------------------------------------------------------
301 
ImplInsertHatch(sal_Int32 nKey,int nStyle,long nDistance,long nAngle)302 void CGMElements::ImplInsertHatch( sal_Int32 nKey, int nStyle, long nDistance, long nAngle )
303 {
304 	HatchEntry*		pHatchEntry;
305 	pHatchEntry = new HatchEntry;
306 	aHatchTable.Insert( (sal_uInt32)nKey, pHatchEntry );
307 	pHatchEntry->HatchStyle = nStyle;
308 	pHatchEntry->HatchDistance = nDistance;
309 	pHatchEntry->HatchAngle = nAngle;
310 }
311 
312 // ---------------------------------------------------------------
313 
DeleteTable(Table & rTable)314 void CGMElements::DeleteTable( Table& rTable )
315 {
316 	HatchEntry*	pPtr = (HatchEntry*)rTable.First();
317 	while ( pPtr )
318 	{
319 		delete pPtr;
320 		pPtr = (HatchEntry*)rTable.Next();
321 	}
322 	rTable.Clear();
323 }
324 
325 // ---------------------------------------------------------------
326 
DeleteAllBundles(List & rList)327 void CGMElements::DeleteAllBundles( List& rList )
328 {
329 	void* pPtr = rList.First();
330 	while( pPtr )
331 	{
332 		delete (Bundle*)pPtr;
333 		pPtr = rList.Next();
334 	}
335 };
336 
337 
338 // ---------------------------------------------------------------
339 
CopyAllBundles(List & rSource,List & rDest)340 void CGMElements::CopyAllBundles( List& rSource, List& rDest )
341 {
342 	DeleteAllBundles( rDest );
343 	rDest.Clear();
344 
345 	void* pPtr = rSource.First();
346 	while( pPtr )
347 	{
348 		Bundle*	pTempBundle = ( (Bundle*)pPtr)->Clone();
349 		rDest.Insert( pTempBundle, LIST_APPEND );
350 		pPtr = rSource.Next();
351 	}
352 };
353 
354 // ---------------------------------------------------------------
355 
GetBundleIndex(sal_uInt32 nIndex,List & rList,Bundle & rBundle)356 Bundle* CGMElements::GetBundleIndex( sal_uInt32 nIndex, List& rList, Bundle& rBundle )
357 {
358 	rBundle.SetIndex( nIndex );
359 	Bundle* pBundle = GetBundle( rList, nIndex );
360 	if ( !pBundle )
361 		pBundle = InsertBundle( rList, rBundle );
362 	return pBundle;
363 }
364 
365 // ---------------------------------------------------------------
366 
GetBundle(List & rList,long nIndex)367 Bundle* CGMElements::GetBundle( List& rList, long nIndex )
368 {
369 	Bundle* pBundle = (Bundle*)rList.First();
370 	while( pBundle && ( pBundle->GetIndex() != nIndex ) )
371 	{
372 		pBundle = (Bundle*)rList.Next();
373 	}
374 	return pBundle;
375 }
376 
377 // ---------------------------------------------------------------
378 
InsertBundle(List & rList,Bundle & rBundle)379 Bundle* CGMElements::InsertBundle( List& rList, Bundle& rBundle )
380 {
381 	Bundle* pBundle = GetBundle( rList, rBundle.GetIndex() );
382 	if ( pBundle )
383 	{
384 		rList.Remove( pBundle );
385 		delete pBundle;
386 	}
387 	pBundle = rBundle.Clone();
388 	rList.Insert( pBundle, LIST_APPEND );
389 	return pBundle;
390 };
391 
392