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