xref: /AOO41X/main/filter/source/graphicfilter/icgm/bundles.cxx (revision 9e0fc027f109ec4ffcb6033aeec742a099701108)
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 "bundles.hxx"
28 
29 #include <vcl/salbtype.hxx>
30 #include <tools/stream.hxx>
31 #include <tools/list.hxx>
32 
operator =(Bundle & rSource)33 Bundle& Bundle::operator=( Bundle& rSource )
34 {
35     mnColor = rSource.mnColor;
36     mnBundleIndex = rSource.mnBundleIndex;
37     return *this;
38 };
39 
40 // ---------------------------------------------------------------
41 
SetColor(sal_uInt32 nColor)42 void Bundle::SetColor( sal_uInt32 nColor )
43 {
44     mnColor = nColor;
45 }
46 
GetColor()47 sal_uInt32 Bundle::GetColor()
48 {
49     return mnColor;
50 }
51 
52 // ---------------------------------------------------------------
53 
operator =(LineBundle & rSource)54 LineBundle& LineBundle::operator=( LineBundle& rSource )
55 {
56     SetIndex( rSource.GetIndex() );
57     eLineType = rSource.eLineType;
58     nLineWidth = rSource.nLineWidth;
59     return *this;
60 };
61 
operator =(MarkerBundle & rSource)62 MarkerBundle& MarkerBundle::operator=( MarkerBundle& rSource )
63 {
64     SetIndex( rSource.GetIndex() );
65     eMarkerType = rSource.eMarkerType;
66     nMarkerSize = rSource.nMarkerSize;
67     return *this;
68 };
69 
operator =(EdgeBundle & rSource)70 EdgeBundle& EdgeBundle::operator=( EdgeBundle& rSource )
71 {
72     SetIndex( rSource.GetIndex() );
73     eEdgeType = rSource.eEdgeType;
74     nEdgeWidth = rSource.nEdgeWidth;
75     return *this;
76 };
77 
operator =(TextBundle & rSource)78 TextBundle& TextBundle::operator=( TextBundle& rSource )
79 {
80     SetIndex( rSource.GetIndex() );
81     nTextFontIndex = rSource.nTextFontIndex;
82     eTextPrecision = rSource.eTextPrecision;
83     nCharacterExpansion = rSource.nCharacterExpansion;
84     nCharacterSpacing = rSource.nCharacterSpacing;
85     return *this;
86 };
87 
operator =(FillBundle & rSource)88 FillBundle& FillBundle::operator=( FillBundle& rSource )
89 {
90     SetIndex( rSource.GetIndex() );
91     eFillInteriorStyle = rSource.eFillInteriorStyle;
92     nFillPatternIndex = rSource.nFillPatternIndex;
93     nFillHatchIndex = rSource.nFillHatchIndex;
94     return *this;
95 };
96 
97 // ---------------------------------------------------------------
98 
FontEntry()99 FontEntry::FontEntry() :
100     pFontName       ( NULL ),
101     eCharSetType    ( CST_CCOMPLETE ),
102     pCharSetValue   ( NULL ),
103     nFontType       ( 0 )
104 {
105 }
106 
~FontEntry()107 FontEntry::~FontEntry()
108 {
109     delete pFontName;
110     delete pCharSetValue;
111 }
112 
113 // ---------------------------------------------------------------
114 
CGMFList()115 CGMFList::CGMFList() :
116     nFontNameCount      ( 0 ),
117     nCharSetCount       ( 0 ),
118     nFontsAvailable     ( 0 )
119 {
120     aFontEntryList.Clear();
121 }
122 
~CGMFList()123 CGMFList::~CGMFList()
124 {
125     ImplDeleteList();
126 }
127 
128 // ---------------------------------------------------------------
129 
operator =(CGMFList & rSource)130 CGMFList& CGMFList::operator=( CGMFList& rSource )
131 {
132     ImplDeleteList();
133     nFontsAvailable = rSource.nFontsAvailable;
134     nFontNameCount = rSource.nFontNameCount;
135     nCharSetCount = rSource.nCharSetCount;
136     FontEntry* pPtr = (FontEntry*)rSource.aFontEntryList.First();
137     while( pPtr )
138     {
139         FontEntry* pCFontEntry = new FontEntry;
140         if ( pPtr->pFontName )
141         {
142             sal_uInt32 nSize = strlen( (const char*)pPtr->pFontName ) + 1;
143             pCFontEntry->pFontName = new sal_Int8[ nSize ];
144             memcpy( pCFontEntry->pFontName, pPtr->pFontName, nSize );
145         }
146         if ( pPtr->pCharSetValue )
147         {
148             sal_uInt32 nSize = strlen( (const char*)pPtr->pCharSetValue ) + 1;
149             pCFontEntry->pCharSetValue = new sal_Int8[ nSize ];
150             memcpy( pCFontEntry->pCharSetValue, pPtr->pCharSetValue, nSize );
151         }
152         pCFontEntry->eCharSetType = pPtr->eCharSetType;
153         pCFontEntry->nFontType = pPtr->nFontType;
154         aFontEntryList.Insert( pCFontEntry, LIST_APPEND );
155         pPtr = (FontEntry*)rSource.aFontEntryList.Next();
156     }
157     return *this;
158 }
159 
160 // ---------------------------------------------------------------
161 
GetFontEntry(sal_uInt32 nIndex)162 FontEntry* CGMFList::GetFontEntry( sal_uInt32 nIndex )
163 {
164     sal_uInt32 nInd = nIndex;
165     if ( nInd )
166         nInd--;
167     return (FontEntry*)aFontEntryList.GetObject( nInd );
168 }
169 
170 // ---------------------------------------------------------------
171 
ImplSearchEntry(sal_Int8 * pSource,sal_Int8 * pDest,sal_uInt32 nComp,sal_uInt32 nSize)172 static sal_Int8* ImplSearchEntry( sal_Int8* pSource, sal_Int8* pDest, sal_uInt32 nComp, sal_uInt32 nSize )
173 {
174     while ( nComp-- >= nSize )
175     {
176         sal_uInt32 i;
177         for ( i = 0; i < nSize; i++ )
178         {
179             if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) )
180                 break;
181         }
182         if ( i == nSize )
183             return pSource;
184         pSource++;
185     }
186     return NULL;
187 }
188 
InsertName(sal_uInt8 * pSource,sal_uInt32 nSize)189 void CGMFList::InsertName( sal_uInt8* pSource, sal_uInt32 nSize )
190 {
191     FontEntry* pFontEntry;
192     if ( nFontsAvailable == nFontNameCount )
193     {
194         nFontsAvailable++;
195         pFontEntry = new FontEntry;
196         aFontEntryList.Insert( pFontEntry, LIST_APPEND );
197     }
198     else
199     {
200         pFontEntry = (FontEntry*)aFontEntryList.GetObject( nFontNameCount );
201     }
202     nFontNameCount++;
203     sal_Int8* pBuf = new sal_Int8[ nSize ];
204     memcpy( pBuf, pSource, nSize );
205     sal_Int8* pFound = ImplSearchEntry( pBuf, (sal_Int8*)"ITALIC", nSize, 6 );
206     if ( pFound )
207     {
208         pFontEntry->nFontType |= 1;
209         sal_uInt32 nPrev = ( pFound - pBuf );
210         sal_uInt32 nToCopyOfs = 6;
211         if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
212         {
213             nPrev--;
214             pFound--;
215             nToCopyOfs++;
216         }
217         sal_uInt32 nToCopy = nSize - nToCopyOfs - nPrev;
218         if ( nToCopy )
219         {
220             memcpy( pFound, pFound + nToCopyOfs, nToCopy );
221         }
222         nSize -= nToCopyOfs;
223     }
224     pFound = ImplSearchEntry( pBuf, (sal_Int8*)"BOLD", nSize, 4 );
225     if ( pFound )
226     {
227         pFontEntry->nFontType |= 2;
228 
229         sal_uInt32 nPrev = ( pFound - pBuf );
230         sal_uInt32 nToCopyOfs = 4;
231         if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
232         {
233             nPrev--;
234             pFound--;
235             nToCopyOfs++;
236         }
237         sal_uInt32 nToCopy = nSize - nToCopyOfs - nPrev;
238         if ( nToCopy )
239         {
240             memcpy( pFound, pFound + nToCopyOfs, nToCopy );
241         }
242         nSize -= nToCopyOfs;
243     }
244     pFontEntry->pFontName = new sal_Int8[ nSize + 1 ];
245     pFontEntry->pFontName[ nSize ] = 0;
246     memcpy( pFontEntry->pFontName, pBuf, nSize );
247     delete[] pBuf;
248 }
249 
250 //--------------------------------------------------------------------------
251 
InsertCharSet(CharSetType eCharSetType,sal_uInt8 * pSource,sal_uInt32 nSize)252 void CGMFList::InsertCharSet( CharSetType eCharSetType, sal_uInt8* pSource, sal_uInt32 nSize )
253 {
254     FontEntry* pFontEntry;
255     if ( nFontsAvailable == nCharSetCount )
256     {
257         nFontsAvailable++;
258         pFontEntry = new FontEntry;
259         aFontEntryList.Insert( pFontEntry, LIST_APPEND );
260     }
261     else
262     {
263         pFontEntry = (FontEntry*)aFontEntryList.GetObject( nCharSetCount );
264     }
265     nCharSetCount++;
266     pFontEntry->eCharSetType = eCharSetType;
267     pFontEntry->pCharSetValue = new sal_Int8[ nSize + 1 ];
268     pFontEntry->pCharSetValue[ nSize ] = 0;
269     memcpy( pFontEntry->pCharSetValue, pSource , nSize );
270 }
271 
272 // ---------------------------------------------------------------
273 
ImplDeleteList()274 void CGMFList::ImplDeleteList()
275 {
276     FontEntry* pFontEntry = (FontEntry*)aFontEntryList.First();
277     while( pFontEntry )
278     {
279         delete pFontEntry;
280         pFontEntry = (FontEntry*)aFontEntryList.Next();
281     }
282     aFontEntryList.Clear();
283 }
284 
285