Update ooo320-m1
[ooovba.git] / goodies / source / filter.vcl / icgm / bundles.cxx
bloba8f606462f0e817b76b4a01bf9b2ff1a88bc2502
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bundles.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
34 #include "bundles.hxx"
36 #include <vcl/salbtype.hxx>
37 #include <tools/stream.hxx>
38 #include <tools/list.hxx>
40 Bundle& Bundle::operator=( Bundle& rSource )
42 mnColor = rSource.mnColor;
43 mnBundleIndex = rSource.mnBundleIndex;
44 return *this;
47 // ---------------------------------------------------------------
49 void Bundle::SetColor( sal_uInt32 nColor )
51 mnColor = nColor;
54 sal_uInt32 Bundle::GetColor()
56 return mnColor;
59 // ---------------------------------------------------------------
61 LineBundle& LineBundle::operator=( LineBundle& rSource )
63 SetIndex( rSource.GetIndex() );
64 eLineType = rSource.eLineType;
65 nLineWidth = rSource.nLineWidth;
66 return *this;
69 MarkerBundle& MarkerBundle::operator=( MarkerBundle& rSource )
71 SetIndex( rSource.GetIndex() );
72 eMarkerType = rSource.eMarkerType;
73 nMarkerSize = rSource.nMarkerSize;
74 return *this;
77 EdgeBundle& EdgeBundle::operator=( EdgeBundle& rSource )
79 SetIndex( rSource.GetIndex() );
80 eEdgeType = rSource.eEdgeType;
81 nEdgeWidth = rSource.nEdgeWidth;
82 return *this;
85 TextBundle& TextBundle::operator=( TextBundle& rSource )
87 SetIndex( rSource.GetIndex() );
88 nTextFontIndex = rSource.nTextFontIndex;
89 eTextPrecision = rSource.eTextPrecision;
90 nCharacterExpansion = rSource.nCharacterExpansion;
91 nCharacterSpacing = rSource.nCharacterSpacing;
92 return *this;
95 FillBundle& FillBundle::operator=( FillBundle& rSource )
97 SetIndex( rSource.GetIndex() );
98 eFillInteriorStyle = rSource.eFillInteriorStyle;
99 nFillPatternIndex = rSource.nFillPatternIndex;
100 nFillHatchIndex = rSource.nFillHatchIndex;
101 return *this;
104 // ---------------------------------------------------------------
106 FontEntry::FontEntry() :
107 pFontName ( NULL ),
108 eCharSetType ( CST_CCOMPLETE ),
109 pCharSetValue ( NULL ),
110 nFontType ( 0 )
114 FontEntry::~FontEntry()
116 delete pFontName;
117 delete pCharSetValue;
120 // ---------------------------------------------------------------
122 CGMFList::CGMFList() :
123 nFontNameCount ( 0 ),
124 nCharSetCount ( 0 ),
125 nFontsAvailable ( 0 )
127 aFontEntryList.Clear();
130 CGMFList::~CGMFList()
132 ImplDeleteList();
135 // ---------------------------------------------------------------
137 CGMFList& CGMFList::operator=( CGMFList& rSource )
139 ImplDeleteList();
140 nFontsAvailable = rSource.nFontsAvailable;
141 nFontNameCount = rSource.nFontNameCount;
142 nCharSetCount = rSource.nCharSetCount;
143 FontEntry* pPtr = (FontEntry*)rSource.aFontEntryList.First();
144 while( pPtr )
146 FontEntry* pCFontEntry = new FontEntry;
147 if ( pPtr->pFontName )
149 sal_uInt32 nSize = strlen( (const char*)pPtr->pFontName ) + 1;
150 pCFontEntry->pFontName = new sal_Int8[ nSize ];
151 memcpy( pCFontEntry->pFontName, pPtr->pFontName, nSize );
153 if ( pPtr->pCharSetValue )
155 sal_uInt32 nSize = strlen( (const char*)pPtr->pCharSetValue ) + 1;
156 pCFontEntry->pCharSetValue = new sal_Int8[ nSize ];
157 memcpy( pCFontEntry->pCharSetValue, pPtr->pCharSetValue, nSize );
159 pCFontEntry->eCharSetType = pPtr->eCharSetType;
160 pCFontEntry->nFontType = pPtr->nFontType;
161 aFontEntryList.Insert( pCFontEntry, LIST_APPEND );
162 pPtr = (FontEntry*)rSource.aFontEntryList.Next();
164 return *this;
167 // ---------------------------------------------------------------
169 FontEntry* CGMFList::GetFontEntry( sal_uInt32 nIndex )
171 sal_uInt32 nInd = nIndex;
172 if ( nInd )
173 nInd--;
174 return (FontEntry*)aFontEntryList.GetObject( nInd );
177 // ---------------------------------------------------------------
179 static sal_Int8* ImplSearchEntry( sal_Int8* pSource, sal_Int8* pDest, sal_uInt32 nComp, sal_uInt32 nSize )
181 while ( nComp-- >= nSize )
183 sal_uInt32 i;
184 for ( i = 0; i < nSize; i++ )
186 if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) )
187 break;
189 if ( i == nSize )
190 return pSource;
191 pSource++;
193 return NULL;
196 void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize )
198 FontEntry* pFontEntry;
199 if ( nFontsAvailable == nFontNameCount )
201 nFontsAvailable++;
202 pFontEntry = new FontEntry;
203 aFontEntryList.Insert( pFontEntry, LIST_APPEND );
205 else
207 pFontEntry = (FontEntry*)aFontEntryList.GetObject( nFontNameCount );
209 nFontNameCount++;
210 sal_Int8* pBuf = new sal_Int8[ nSize ];
211 memcpy( pBuf, pSource, nSize );
212 sal_Int8* pFound = ImplSearchEntry( pBuf, (sal_Int8*)"ITALIC", nSize, 6 );
213 if ( pFound )
215 pFontEntry->nFontType |= 1;
216 sal_uInt32 nPrev = ( pFound - pBuf );
217 sal_uInt32 nToCopyOfs = 6;
218 if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
220 nPrev--;
221 pFound--;
222 nToCopyOfs++;
224 sal_uInt32 nToCopy = nSize - nToCopyOfs - nPrev;
225 if ( nToCopy )
227 memcpy( pFound, pFound + nToCopyOfs, nToCopy );
229 nSize -= nToCopyOfs;
231 pFound = ImplSearchEntry( pBuf, (sal_Int8*)"BOLD", nSize, 4 );
232 if ( pFound )
234 pFontEntry->nFontType |= 2;
236 sal_uInt32 nPrev = ( pFound - pBuf );
237 sal_uInt32 nToCopyOfs = 4;
238 if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
240 nPrev--;
241 pFound--;
242 nToCopyOfs++;
244 sal_uInt32 nToCopy = nSize - nToCopyOfs - nPrev;
245 if ( nToCopy )
247 memcpy( pFound, pFound + nToCopyOfs, nToCopy );
249 nSize -= nToCopyOfs;
251 pFontEntry->pFontName = new sal_Int8[ nSize + 1 ];
252 pFontEntry->pFontName[ nSize ] = 0;
253 memcpy( pFontEntry->pFontName, pBuf, nSize );
254 delete[] pBuf;
257 //--------------------------------------------------------------------------
259 void CGMFList::InsertCharSet( CharSetType eCharSetType, sal_uInt8* pSource, sal_uInt32 nSize )
261 FontEntry* pFontEntry;
262 if ( nFontsAvailable == nCharSetCount )
264 nFontsAvailable++;
265 pFontEntry = new FontEntry;
266 aFontEntryList.Insert( pFontEntry, LIST_APPEND );
268 else
270 pFontEntry = (FontEntry*)aFontEntryList.GetObject( nCharSetCount );
272 nCharSetCount++;
273 pFontEntry->eCharSetType = eCharSetType;
274 pFontEntry->pCharSetValue = new sal_Int8[ nSize + 1 ];
275 pFontEntry->pCharSetValue[ nSize ] = 0;
276 memcpy( pFontEntry->pCharSetValue, pSource , nSize );
279 // ---------------------------------------------------------------
281 void CGMFList::ImplDeleteList()
283 FontEntry* pFontEntry = (FontEntry*)aFontEntryList.First();
284 while( pFontEntry )
286 delete pFontEntry;
287 pFontEntry = (FontEntry*)aFontEntryList.Next();
289 aFontEntryList.Clear();