Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #define CTRLTOOL_CXX
31 : :
32 : : #include <string.h>
33 : :
34 : : #include <comphelper/string.hxx>
35 : : #include <tools/debug.hxx>
36 : : #include <i18npool/mslangid.hxx>
37 : : #include <vcl/window.hxx>
38 : : #include <vcl/svapp.hxx>
39 : : #include <vcl/wrkwin.hxx>
40 : : #include <sal/macros.h>
41 : : #include <svtools/svtools.hrc>
42 : : #include <svtools/svtresid.hxx>
43 : : #include <svtools/ctrltool.hxx>
44 : :
45 : : // =======================================================================
46 : :
47 : : // Standard Fontgroessen fuer scalierbare Fonts
48 : : static const long aStdSizeAry[] =
49 : : {
50 : : 60,
51 : : 70,
52 : : 80,
53 : : 90,
54 : : 100,
55 : : 105,
56 : : 110,
57 : : 120,
58 : : 130,
59 : : 140,
60 : : 150,
61 : : 160,
62 : : 180,
63 : : 200,
64 : : 220,
65 : : 240,
66 : : 260,
67 : : 280,
68 : : 320,
69 : : 360,
70 : : 400,
71 : : 440,
72 : : 480,
73 : : 540,
74 : : 600,
75 : : 660,
76 : : 720,
77 : : 800,
78 : : 880,
79 : : 960,
80 : : 0
81 : : };
82 : :
83 : : // =======================================================================
84 : :
85 : : // -----------------------------
86 : : // - class ImplFontListFonInfo -
87 : : // -----------------------------
88 : :
89 : 504256 : class ImplFontListFontInfo : public FontInfo
90 : : {
91 : : friend class FontList;
92 : :
93 : : private:
94 : : OutputDevice* mpDevice;
95 : : ImplFontListFontInfo* mpNext;
96 : :
97 : : public:
98 : 518754 : ImplFontListFontInfo( const FontInfo& rInfo,
99 : : OutputDevice* pDev ) :
100 : 518754 : FontInfo( rInfo )
101 : : {
102 : 518754 : mpDevice = pDev;
103 : 518754 : }
104 : :
105 : 1464 : OutputDevice* GetDevice() const { return mpDevice; }
106 : : };
107 : :
108 : : // ------------------------------
109 : : // - class ImplFontListNameInfo -
110 : : // ------------------------------
111 : :
112 : 225218 : class ImplFontListNameInfo
113 : : {
114 : : friend class FontList;
115 : :
116 : : private:
117 : : XubString maSearchName;
118 : : ImplFontListFontInfo* mpFirst;
119 : : sal_uInt16 mnType;
120 : :
121 : 232054 : ImplFontListNameInfo( const XubString& rSearchName ) :
122 : 232054 : maSearchName( rSearchName )
123 : 232054 : {}
124 : : };
125 : :
126 : : //sort normal to the start
127 : 406922 : static int sortWeightValue(FontWeight eWeight)
128 : : {
129 [ + + ]: 406922 : if (eWeight < WEIGHT_NORMAL)
130 : 8458 : return eWeight + 1;
131 [ + + ]: 398464 : if (eWeight > WEIGHT_NORMAL)
132 : 222246 : return eWeight - 1;
133 : 406922 : return 0; // eWeight == WEIGHT_NORMAL
134 : : }
135 : :
136 : 565747 : static StringCompare ImplCompareFontInfo( ImplFontListFontInfo* pInfo1,
137 : : ImplFontListFontInfo* pInfo2 )
138 : : {
139 : : //Sort non italic before italics
140 [ + + ]: 565747 : if ( pInfo1->GetItalic() < pInfo2->GetItalic() )
141 : 100264 : return COMPARE_LESS;
142 [ + + ]: 465483 : else if ( pInfo1->GetItalic() > pInfo2->GetItalic() )
143 : 262022 : return COMPARE_GREATER;
144 : :
145 : : //Sort normal weight to the start, followed by lightest to heaviest weights
146 : 203461 : int nWeight1 = sortWeightValue(pInfo1->GetWeight());
147 : 203461 : int nWeight2 = sortWeightValue(pInfo2->GetWeight());
148 : :
149 [ - + ]: 203461 : if ( nWeight1 < nWeight2 )
150 : 0 : return COMPARE_LESS;
151 [ + - ]: 203461 : else if ( nWeight1 > nWeight2 )
152 : 203461 : return COMPARE_GREATER;
153 : :
154 : 565747 : return pInfo1->GetStyleName().CompareTo( pInfo2->GetStyleName() );
155 : : }
156 : :
157 : : // =======================================================================
158 : :
159 : 528110 : static void ImplMakeSearchString( XubString& rStr )
160 : : {
161 : 528110 : rStr.ToLowerAscii();
162 : 528110 : }
163 : :
164 : : // -----------------------------------------------------------------------
165 : :
166 : 1700 : static void ImplMakeSearchStringFromName( XubString& rStr )
167 : : {
168 : : // check for features before alternate font separator
169 [ - + ]: 1700 : if (rStr.Search(':') < rStr.Search(';'))
170 [ # # ]: 0 : rStr = rStr.GetToken( 0, ':' );
171 : : else
172 [ + - ]: 1700 : rStr = rStr.GetToken( 0, ';' );
173 : 1700 : ImplMakeSearchString( rStr );
174 : 1700 : }
175 : :
176 : : // -----------------------------------------------------------------------
177 : :
178 : 528110 : ImplFontListNameInfo* FontList::ImplFind( const XubString& rSearchName, sal_uLong* pIndex ) const
179 : : {
180 : : // Wenn kein Eintrag in der Liste oder der Eintrag groesser ist als
181 : : // der Letzte, dann hinten dranhaengen. Wir vergleichen erst mit dem
182 : : // letzten Eintrag, da die Liste von VCL auch sortiert zurueckkommt
183 : : // und somit die Wahrscheinlichkeit das hinten angehaengt werden muss
184 : : // sehr gross ist.
185 : : StringCompare eComp;
186 : 528110 : sal_uLong nCnt = maEntries.size();
187 [ + + ]: 528110 : if ( !nCnt )
188 : : {
189 [ + - ]: 4113 : if ( pIndex )
190 : 4113 : *pIndex = ULONG_MAX;
191 : 4113 : return NULL;
192 : : }
193 : : else
194 : : {
195 : 523997 : const ImplFontListNameInfo* pCmpData = &maEntries[nCnt-1];
196 : 523997 : eComp = rSearchName.CompareTo( pCmpData->maSearchName );
197 [ + + ]: 523997 : if ( eComp == COMPARE_GREATER )
198 : : {
199 [ + + ]: 20111 : if ( pIndex )
200 : 20045 : *pIndex = ULONG_MAX;
201 : 20111 : return NULL;
202 : : }
203 [ + + ]: 503886 : else if ( eComp == COMPARE_EQUAL )
204 : 11330 : return const_cast<ImplFontListNameInfo*>(pCmpData);
205 : : }
206 : :
207 : : // Fonts in der Liste suchen
208 : : const ImplFontListNameInfo* pCompareData;
209 : 492556 : const ImplFontListNameInfo* pFoundData = NULL;
210 : 492556 : sal_uLong nLow = 0;
211 : 492556 : sal_uLong nHigh = nCnt-1;
212 : : sal_uLong nMid;
213 : :
214 [ + + ]: 1779363 : do
215 : : {
216 : 2082776 : nMid = (nLow + nHigh) / 2;
217 : 2082776 : pCompareData = &maEntries[nMid];
218 : 2082776 : eComp = rSearchName.CompareTo( pCompareData->maSearchName );
219 [ + + ]: 2082776 : if ( eComp == COMPARE_LESS )
220 : : {
221 [ + + ]: 822083 : if ( !nMid )
222 : 18923 : break;
223 : 803160 : nHigh = nMid-1;
224 : : }
225 : : else
226 : : {
227 [ + + ]: 1260693 : if ( eComp == COMPARE_GREATER )
228 : 976203 : nLow = nMid + 1;
229 : : else
230 : : {
231 : 284490 : pFoundData = pCompareData;
232 : 284490 : break;
233 : : }
234 : : }
235 : : }
236 : : while ( nLow <= nHigh );
237 : :
238 [ + + ]: 492556 : if ( pIndex )
239 : : {
240 : 490922 : eComp = rSearchName.CompareTo( pCompareData->maSearchName );
241 [ + + ]: 490922 : if ( eComp == COMPARE_GREATER )
242 : 78690 : *pIndex = (nMid+1);
243 : : else
244 : 412232 : *pIndex = nMid;
245 : : }
246 : :
247 : 528110 : return const_cast<ImplFontListNameInfo*>(pFoundData);
248 : : }
249 : :
250 : : // -----------------------------------------------------------------------
251 : :
252 : 1700 : ImplFontListNameInfo* FontList::ImplFindByName( const XubString& rStr ) const
253 : : {
254 [ + - ]: 1700 : XubString aSearchName = rStr;
255 [ + - ]: 1700 : ImplMakeSearchStringFromName( aSearchName );
256 [ + - ][ + - ]: 1700 : return ImplFind( aSearchName, NULL );
257 : : }
258 : :
259 : : // -----------------------------------------------------------------------
260 : :
261 : 4225 : void FontList::ImplInsertFonts( OutputDevice* pDevice, sal_Bool bAll,
262 : : sal_Bool bInsertData )
263 : : {
264 : 4225 : rtl_TextEncoding eSystemEncoding = osl_getThreadTextEncoding();
265 : :
266 : : sal_uInt16 nType;
267 [ + + ]: 4225 : if ( pDevice->GetOutDevType() != OUTDEV_PRINTER )
268 : 4167 : nType = FONTLIST_FONTNAMETYPE_SCREEN;
269 : : else
270 : 58 : nType = FONTLIST_FONTNAMETYPE_PRINTER;
271 : :
272 : : // Alle Fonts vom Device abfragen
273 : 4225 : int n = pDevice->GetDevFontCount();
274 : : sal_uInt16 i;
275 [ + + ]: 530635 : for( i = 0; i < n; i++ )
276 : : {
277 [ + - ]: 526410 : FontInfo aFontInfo = pDevice->GetDevFont( i );
278 : :
279 : : // Wenn keine Raster-Schriften angezeigt werden sollen,
280 : : // dann diese ignorieren
281 [ + + ][ + - ]: 526410 : if ( !bAll && (aFontInfo.GetType() == TYPE_RASTER) )
[ - + ][ - + ]
282 : 0 : continue;
283 : :
284 [ + - ][ + - ]: 526410 : XubString aSearchName = aFontInfo.GetName();
285 : : ImplFontListNameInfo* pData;
286 : : sal_uLong nIndex;
287 [ + - ]: 526410 : ImplMakeSearchString( aSearchName );
288 [ + - ]: 526410 : pData = ImplFind( aSearchName, &nIndex );
289 : :
290 [ + + ]: 526410 : if ( !pData )
291 : : {
292 [ + - ]: 232054 : if ( bInsertData )
293 : : {
294 [ + - ][ + - ]: 232054 : ImplFontListFontInfo* pNewInfo = new ImplFontListFontInfo( aFontInfo, pDevice );
295 [ + - ][ + - ]: 232054 : pData = new ImplFontListNameInfo( aSearchName );
296 : 232054 : pData->mpFirst = pNewInfo;
297 : 232054 : pNewInfo->mpNext = NULL;
298 : 232054 : pData->mnType = 0;
299 : :
300 [ + + ]: 232054 : if (nIndex < maEntries.size())
301 [ + - ][ + - ]: 207896 : maEntries.insert(maEntries.begin()+nIndex,pData);
[ + - ]
302 : : else
303 [ + - ]: 24158 : maEntries.push_back(pData);
304 : : }
305 : : }
306 : : else
307 : : {
308 [ + + ]: 294356 : if ( bInsertData )
309 : : {
310 : 286700 : sal_Bool bInsert = sal_True;
311 : 286700 : ImplFontListFontInfo* pPrev = NULL;
312 : 286700 : ImplFontListFontInfo* pTemp = pData->mpFirst;
313 [ + - ][ + - ]: 286700 : ImplFontListFontInfo* pNewInfo = new ImplFontListFontInfo( aFontInfo, pDevice );
314 [ + + ]: 752183 : while ( pTemp )
315 : : {
316 [ + - ]: 565747 : StringCompare eComp = ImplCompareFontInfo( pNewInfo, pTemp );
317 [ + + ][ - + ]: 565747 : if ( (eComp == COMPARE_LESS) || (eComp == COMPARE_EQUAL) )
318 : : {
319 [ - + ]: 100264 : if ( eComp == COMPARE_EQUAL )
320 : : {
321 : : // Overwrite charset, because charset should match
322 : : // with the system charset
323 [ # # ][ # # ]: 0 : if ( (pTemp->GetCharSet() != eSystemEncoding) &&
[ # # ][ # # ]
324 [ # # ]: 0 : (pNewInfo->GetCharSet() == eSystemEncoding) )
325 : : {
326 : 0 : ImplFontListFontInfo* pTemp2 = pTemp->mpNext;
327 [ # # ]: 0 : *((FontInfo*)pTemp) = *((FontInfo*)pNewInfo);
328 : 0 : pTemp->mpNext = pTemp2;
329 : : }
330 [ # # ][ # # ]: 0 : delete pNewInfo;
331 : 0 : bInsert = sal_False;
332 : : }
333 : :
334 : 100264 : break;
335 : : }
336 : :
337 : 465483 : pPrev = pTemp;
338 : 465483 : pTemp = pTemp->mpNext;
339 : : }
340 : :
341 [ + - ]: 286700 : if ( bInsert )
342 : : {
343 : 286700 : pNewInfo->mpNext = pTemp;
344 [ + + ]: 286700 : if ( pPrev )
345 : 278474 : pPrev->mpNext = pNewInfo;
346 : : else
347 : 8226 : pData->mpFirst = pNewInfo;
348 : : }
349 : : }
350 : : }
351 : :
352 [ + - ]: 526410 : if ( pData )
353 : : {
354 : 526410 : pData->mnType |= nType;
355 [ + - ][ + - ]: 526410 : if ( aFontInfo.GetType() != TYPE_RASTER )
356 : 526410 : pData->mnType |= FONTLIST_FONTNAMETYPE_SCALABLE;
357 : : }
358 [ + - ][ + - ]: 526410 : }
[ + - ]
359 : 4225 : }
360 : :
361 : : // =======================================================================
362 : :
363 [ + - ][ + - ]: 4167 : FontList::FontList( OutputDevice* pDevice, OutputDevice* pDevice2, sal_Bool bAll )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
364 : : {
365 : : // Variablen initialisieren
366 : 4167 : mpDev = pDevice;
367 : 4167 : mpDev2 = pDevice2;
368 : 4167 : mpSizeAry = NULL;
369 : :
370 : : // Stylenamen festlegen
371 [ + - ][ + - ]: 4167 : maLight = SVT_RESSTR(STR_SVT_STYLE_LIGHT);
[ + - ]
372 [ + - ][ + - ]: 4167 : maLightItalic = SVT_RESSTR(STR_SVT_STYLE_LIGHT_ITALIC);
[ + - ]
373 [ + - ][ + - ]: 4167 : maNormal = SVT_RESSTR(STR_SVT_STYLE_NORMAL);
[ + - ]
374 [ + - ][ + - ]: 4167 : maNormalItalic = SVT_RESSTR(STR_SVT_STYLE_NORMAL_ITALIC);
[ + - ]
375 [ + - ][ + - ]: 4167 : maBold = SVT_RESSTR(STR_SVT_STYLE_BOLD);
[ + - ]
376 [ + - ][ + - ]: 4167 : maBoldItalic = SVT_RESSTR(STR_SVT_STYLE_BOLD_ITALIC);
[ + - ]
377 [ + - ][ + - ]: 4167 : maBlack = SVT_RESSTR(STR_SVT_STYLE_BLACK);
[ + - ]
378 [ + - ][ + - ]: 4167 : maBlackItalic = SVT_RESSTR(STR_SVT_STYLE_BLACK_ITALIC);
[ + - ]
379 : :
380 [ + - ]: 4167 : ImplInsertFonts( pDevice, bAll, sal_True );
381 : :
382 : : // Gegebenenfalls muessen wir mit den Bildschirmfonts vergleichen,
383 : : // damit dort die eigentlich doppelten auf Equal mappen koennen
384 : 4167 : sal_Bool bCompareWindow = sal_False;
385 [ + - ][ + + ]: 4167 : if ( !pDevice2 && (pDevice->GetOutDevType() == OUTDEV_PRINTER) )
[ + + ]
386 : : {
387 : 58 : bCompareWindow = sal_True;
388 [ + - ]: 58 : pDevice2 = Application::GetDefaultDevice();
389 : : }
390 : :
391 [ + + + - ]: 4225 : if ( pDevice2 &&
[ + + ]
392 : 58 : (pDevice2->GetOutDevType() != pDevice->GetOutDevType()) )
393 [ + - ]: 58 : ImplInsertFonts( pDevice2, bAll, !bCompareWindow );
394 : 4167 : }
395 : :
396 : : // -----------------------------------------------------------------------
397 : :
398 [ + - ][ + - ]: 4030 : FontList::~FontList()
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
399 : : {
400 : : // Gegebenenfalls SizeArray loeschen
401 [ - + ]: 4030 : if ( mpSizeAry )
402 [ # # ]: 0 : delete[] mpSizeAry;
403 : :
404 : : // FontInfos loeschen
405 : : ImplFontListFontInfo *pTemp, *pInfo;
406 [ + - ]: 4030 : boost::ptr_vector<ImplFontListNameInfo>::iterator it;
407 [ + - ][ + - ]: 229248 : for (it = maEntries.begin(); it != maEntries.end(); ++it)
[ + - ][ + - ]
[ + + ]
408 : : {
409 [ + - ]: 225218 : pInfo = it->mpFirst;
410 [ + + ]: 729474 : while ( pInfo )
411 : : {
412 : 504256 : pTemp = pInfo->mpNext;
413 [ + - ][ + - ]: 504256 : delete pInfo;
414 : 504256 : pInfo = pTemp;
415 : : }
416 : : }
417 : 4030 : }
418 : : // -----------------------------------------------------------------------
419 : 0 : FontList* FontList::Clone() const
420 : : {
421 : : FontList* pReturn = new FontList(
422 [ # # ]: 0 : mpDev, mpDev2, GetFontNameCount() == mpDev->GetDevFontCount());
423 : 0 : return pReturn;
424 : : }
425 : :
426 : : // -----------------------------------------------------------------------
427 : :
428 : 0 : const XubString& FontList::GetStyleName( FontWeight eWeight, FontItalic eItalic ) const
429 : : {
430 [ # # ]: 0 : if ( eWeight > WEIGHT_BOLD )
431 : : {
432 [ # # ]: 0 : if ( eItalic > ITALIC_NONE )
433 : 0 : return maBlackItalic;
434 : : else
435 : 0 : return maBlack;
436 : : }
437 [ # # ]: 0 : else if ( eWeight > WEIGHT_MEDIUM )
438 : : {
439 [ # # ]: 0 : if ( eItalic > ITALIC_NONE )
440 : 0 : return maBoldItalic;
441 : : else
442 : 0 : return maBold;
443 : : }
444 [ # # ]: 0 : else if ( eWeight > WEIGHT_LIGHT )
445 : : {
446 [ # # ]: 0 : if ( eItalic > ITALIC_NONE )
447 : 0 : return maNormalItalic;
448 : : else
449 : 0 : return maNormal;
450 : : }
451 [ # # ]: 0 : else if ( eWeight != WEIGHT_DONTKNOW )
452 : : {
453 [ # # ]: 0 : if ( eItalic > ITALIC_NONE )
454 : 0 : return maLightItalic;
455 : : else
456 : 0 : return maLight;
457 : : }
458 : : else
459 : : {
460 [ # # ]: 0 : if ( eItalic > ITALIC_NONE )
461 : 0 : return maNormalItalic;
462 : : else
463 : 0 : return maNormal;
464 : : }
465 : : }
466 : :
467 : : // -----------------------------------------------------------------------
468 : :
469 : 0 : XubString FontList::GetStyleName( const FontInfo& rInfo ) const
470 : : {
471 : 0 : XubString aStyleName = rInfo.GetStyleName();
472 [ # # ]: 0 : FontWeight eWeight = rInfo.GetWeight();
473 [ # # ]: 0 : FontItalic eItalic = rInfo.GetItalic();
474 : :
475 : : // Nur wenn kein StyleName gesetzt ist, geben wir einen syntetischen
476 : : // Namen zurueck
477 [ # # ]: 0 : if ( !aStyleName.Len() )
478 [ # # ][ # # ]: 0 : aStyleName = GetStyleName( eWeight, eItalic );
479 : : else
480 : : {
481 : : // Translate StyleName to localized name
482 [ # # ]: 0 : XubString aCompareStyleName = aStyleName;
483 [ # # ]: 0 : aCompareStyleName.ToLowerAscii();
484 [ # # ][ # # ]: 0 : aCompareStyleName = comphelper::string::remove(aCompareStyleName, ' ');
485 [ # # ][ # # ]: 0 : if ( aCompareStyleName.EqualsAscii( "bold" ) )
486 [ # # ]: 0 : aStyleName = maBold;
487 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "bolditalic" ) )
488 [ # # ]: 0 : aStyleName = maBoldItalic;
489 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "italic" ) )
490 [ # # ]: 0 : aStyleName = maNormalItalic;
491 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "standard" ) )
492 [ # # ]: 0 : aStyleName = maNormal;
493 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "regular" ) )
494 [ # # ]: 0 : aStyleName = maNormal;
495 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "medium" ) )
496 [ # # ]: 0 : aStyleName = maNormal;
497 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "light" ) )
498 [ # # ]: 0 : aStyleName = maLight;
499 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "lightitalic" ) )
500 [ # # ]: 0 : aStyleName = maLightItalic;
501 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "black" ) )
502 [ # # ]: 0 : aStyleName = maBlack;
503 [ # # ][ # # ]: 0 : else if ( aCompareStyleName.EqualsAscii( "blackitalic" ) )
504 [ # # ]: 0 : aStyleName = maBlackItalic;
505 : :
506 : : // fix up StyleName, because the PS Printer driver from
507 : : // W2000 returns wrong StyleNames (e.g. Bold instead of Bold Italic
508 : : // for Helvetica)
509 [ # # ]: 0 : if ( eItalic > ITALIC_NONE )
510 : : {
511 [ # # ][ # # ]: 0 : if ( (aStyleName == maNormal) ||
[ # # ][ # # ]
[ # # ][ # # ]
512 [ # # ]: 0 : (aStyleName == maBold) ||
513 [ # # ]: 0 : (aStyleName == maLight) ||
514 [ # # ]: 0 : (aStyleName == maBlack) )
515 [ # # ][ # # ]: 0 : aStyleName = GetStyleName( eWeight, eItalic );
516 [ # # ]: 0 : }
517 : : }
518 : :
519 : 0 : return aStyleName;
520 : : }
521 : :
522 : : // -----------------------------------------------------------------------
523 : :
524 : 0 : XubString FontList::GetFontMapText( const FontInfo& rInfo ) const
525 : : {
526 [ # # ]: 0 : if ( !rInfo.GetName().Len() )
527 : : {
528 [ # # ]: 0 : XubString aEmptryStr;
529 [ # # ][ # # ]: 0 : return aEmptryStr;
530 : : }
531 : :
532 : : // Search Fontname
533 : 0 : ImplFontListNameInfo* pData = ImplFindByName( rInfo.GetName() );
534 [ # # ]: 0 : if ( !pData )
535 : : {
536 [ # # ]: 0 : if ( !maMapNotAvailable.Len() )
537 [ # # ][ # # ]: 0 : ((FontList*)this)->maMapNotAvailable = SVT_RESSTR(STR_SVT_FONTMAP_NOTAVAILABLE);
538 : 0 : return maMapNotAvailable;
539 : : }
540 : :
541 : : // search for synthetic style
542 : 0 : sal_uInt16 nType = pData->mnType;
543 : 0 : const XubString& rStyleName = rInfo.GetStyleName();
544 [ # # ]: 0 : if ( rStyleName.Len() )
545 : : {
546 : 0 : sal_Bool bNotSynthetic = sal_False;
547 : 0 : sal_Bool bNoneAvailable = sal_False;
548 : 0 : FontWeight eWeight = rInfo.GetWeight();
549 : 0 : FontItalic eItalic = rInfo.GetItalic();
550 : 0 : ImplFontListFontInfo* pFontInfo = pData->mpFirst;
551 [ # # ]: 0 : while ( pFontInfo )
552 : : {
553 [ # # # # ]: 0 : if ( (eWeight == pFontInfo->GetWeight()) &&
[ # # ]
554 : 0 : (eItalic == pFontInfo->GetItalic()) )
555 : : {
556 : 0 : bNotSynthetic = sal_True;
557 : 0 : break;
558 : : }
559 : :
560 : 0 : pFontInfo = pFontInfo->mpNext;
561 : : }
562 : :
563 [ # # ]: 0 : if ( bNoneAvailable )
564 : : {
565 [ # # ]: 0 : XubString aEmptryStr;
566 [ # # ][ # # ]: 0 : return aEmptryStr;
567 : : }
568 [ # # ]: 0 : else if ( !bNotSynthetic )
569 : : {
570 [ # # ]: 0 : if ( !maMapStyleNotAvailable.Len() )
571 [ # # ][ # # ]: 0 : ((FontList*)this)->maMapStyleNotAvailable = SVT_RESSTR(STR_SVT_FONTMAP_STYLENOTAVAILABLE);
572 : 0 : return maMapStyleNotAvailable;
573 : : }
574 : : }
575 : :
576 : : // Only Printer-Font?
577 [ # # ]: 0 : if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_PRINTER )
578 : : {
579 [ # # ]: 0 : if ( !maMapPrinterOnly.Len() )
580 [ # # ][ # # ]: 0 : ((FontList*)this)->maMapPrinterOnly = SVT_RESSTR(STR_SVT_FONTMAP_PRINTERONLY);
581 : 0 : return maMapPrinterOnly;
582 : : }
583 : : // Only Screen-Font?
584 [ # # # # ]: 0 : else if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_SCREEN
[ # # ]
585 : 0 : && rInfo.GetType() == TYPE_RASTER )
586 : : {
587 [ # # ]: 0 : if ( !maMapScreenOnly.Len() )
588 [ # # ][ # # ]: 0 : ((FontList*)this)->maMapScreenOnly = SVT_RESSTR(STR_SVT_FONTMAP_SCREENONLY);
589 : 0 : return maMapScreenOnly;
590 : : }
591 : : else
592 : : {
593 [ # # ]: 0 : if ( !maMapBoth.Len() )
594 [ # # ][ # # ]: 0 : ((FontList*)this)->maMapBoth = SVT_RESSTR(STR_SVT_FONTMAP_BOTH);
595 : 0 : return maMapBoth;
596 : : }
597 : : }
598 : :
599 : : namespace
600 : : {
601 : 219 : FontInfo makeMissing(ImplFontListFontInfo* pFontNameInfo, const rtl::OUString &rName,
602 : : FontWeight eWeight, FontItalic eItalic)
603 : : {
604 : 219 : FontInfo aInfo;
605 : : // Falls der Fontname stimmt, uebernehmen wir soviel wie moeglich
606 [ - + ]: 219 : if (pFontNameInfo)
607 : : {
608 [ # # ]: 0 : aInfo = *pFontNameInfo;
609 [ # # ][ # # ]: 0 : aInfo.SetStyleName(rtl::OUString());
[ # # ]
610 : : }
611 : :
612 [ + - ]: 219 : aInfo.SetWeight(eWeight);
613 [ + - ]: 219 : aInfo.SetItalic(eItalic);
614 : :
615 : : //If this is a known but uninstalled symbol font which we can remap to
616 : : //OpenSymbol then toggle its charset to be a symbol font
617 [ + - ][ + - ]: 219 : if (ConvertChar::GetRecodeData(rName, rtl::OUString("OpenSymbol")))
[ + - ][ + - ]
[ + - ][ + + ]
618 [ + - ]: 138 : aInfo.SetCharSet(RTL_TEXTENCODING_SYMBOL);
619 : :
620 : 219 : return aInfo;
621 : : }
622 : : }
623 : :
624 : 6 : FontInfo FontList::Get( const XubString& rName, const XubString& rStyleName ) const
625 : : {
626 : 6 : ImplFontListNameInfo* pData = ImplFindByName( rName );
627 : 6 : ImplFontListFontInfo* pFontInfo = NULL;
628 : 6 : ImplFontListFontInfo* pFontNameInfo = NULL;
629 [ - + ]: 6 : if ( pData )
630 : : {
631 : 0 : ImplFontListFontInfo* pSearchInfo = pData->mpFirst;
632 : 0 : pFontNameInfo = pSearchInfo;
633 : 0 : pSearchInfo = pData->mpFirst;
634 [ # # ]: 0 : while ( pSearchInfo )
635 : : {
636 [ # # ][ # # ]: 0 : if ( rStyleName.EqualsIgnoreCaseAscii( GetStyleName( *pSearchInfo ) ) )
637 : : {
638 : 0 : pFontInfo = pSearchInfo;
639 : 0 : break;
640 : : }
641 : :
642 : 0 : pSearchInfo = pSearchInfo->mpNext;
643 : : }
644 : : }
645 : :
646 : : // Konnten die Daten nicht gefunden werden, dann muessen bestimmte
647 : : // Attribute nachgebildet werden
648 : 6 : FontInfo aInfo;
649 [ + - ]: 6 : if ( !pFontInfo )
650 : : {
651 : 6 : FontWeight eWeight = WEIGHT_DONTKNOW;
652 : 6 : FontItalic eItalic = ITALIC_NONE;
653 : :
654 [ + - ][ + - ]: 6 : if ( rStyleName == maNormal )
655 : : {
656 : 6 : eItalic = ITALIC_NONE;
657 : 6 : eWeight = WEIGHT_NORMAL;
658 : : }
659 [ # # ][ # # ]: 0 : else if ( rStyleName == maNormalItalic )
660 : : {
661 : 0 : eItalic = ITALIC_NORMAL;
662 : 0 : eWeight = WEIGHT_NORMAL;
663 : : }
664 [ # # ][ # # ]: 0 : else if ( rStyleName == maBold )
665 : : {
666 : 0 : eItalic = ITALIC_NONE;
667 : 0 : eWeight = WEIGHT_BOLD;
668 : : }
669 [ # # ][ # # ]: 0 : else if ( rStyleName == maBoldItalic )
670 : : {
671 : 0 : eItalic = ITALIC_NORMAL;
672 : 0 : eWeight = WEIGHT_BOLD;
673 : : }
674 [ # # ][ # # ]: 0 : else if ( rStyleName == maLight )
675 : : {
676 : 0 : eItalic = ITALIC_NONE;
677 : 0 : eWeight = WEIGHT_LIGHT;
678 : : }
679 [ # # ][ # # ]: 0 : else if ( rStyleName == maLightItalic )
680 : : {
681 : 0 : eItalic = ITALIC_NORMAL;
682 : 0 : eWeight = WEIGHT_LIGHT;
683 : : }
684 [ # # ][ # # ]: 0 : else if ( rStyleName == maBlack )
685 : : {
686 : 0 : eItalic = ITALIC_NONE;
687 : 0 : eWeight = WEIGHT_BLACK;
688 : : }
689 [ # # ][ # # ]: 0 : else if ( rStyleName == maBlackItalic )
690 : : {
691 : 0 : eItalic = ITALIC_NORMAL;
692 : 0 : eWeight = WEIGHT_BLACK;
693 : : }
694 [ + - ][ + - ]: 6 : aInfo = makeMissing(pFontNameInfo, rName, eWeight, eItalic);
[ + - ][ + - ]
695 : : }
696 : : else
697 [ # # ]: 0 : aInfo = *pFontInfo;
698 : :
699 : : // set Fontname to keep FontAlias
700 [ + - ][ + - ]: 6 : aInfo.SetName( rName );
701 [ + - ]: 6 : aInfo.SetStyleName( rStyleName );
702 : :
703 : 6 : return aInfo;
704 : : }
705 : :
706 : : // -----------------------------------------------------------------------
707 : :
708 : 213 : FontInfo FontList::Get( const XubString& rName,
709 : : FontWeight eWeight, FontItalic eItalic ) const
710 : : {
711 : 213 : ImplFontListNameInfo* pData = ImplFindByName( rName );
712 : 213 : ImplFontListFontInfo* pFontInfo = NULL;
713 : 213 : ImplFontListFontInfo* pFontNameInfo = NULL;
714 [ - + ]: 213 : if ( pData )
715 : : {
716 : 0 : ImplFontListFontInfo* pSearchInfo = pData->mpFirst;
717 : 0 : pFontNameInfo = pSearchInfo;
718 [ # # ]: 0 : while ( pSearchInfo )
719 : : {
720 [ # # # # ]: 0 : if ( (eWeight == pSearchInfo->GetWeight()) &&
[ # # ]
721 : 0 : (eItalic == pSearchInfo->GetItalic()) )
722 : : {
723 : 0 : pFontInfo = pSearchInfo;
724 : 0 : break;
725 : : }
726 : :
727 : 0 : pSearchInfo = pSearchInfo->mpNext;
728 : : }
729 : : }
730 : :
731 : : // Konnten die Daten nicht gefunden werden, dann muessen bestimmte
732 : : // Attribute nachgebildet werden
733 : 213 : FontInfo aInfo;
734 [ + - ]: 213 : if ( !pFontInfo )
735 [ + - ][ + - ]: 213 : aInfo = makeMissing(pFontNameInfo, rName, eWeight, eItalic);
[ + - ][ + - ]
736 : : else
737 [ # # ]: 0 : aInfo = *pFontInfo;
738 : :
739 : : // set Fontname to keep FontAlias
740 [ + - ][ + - ]: 213 : aInfo.SetName( rName );
741 : :
742 : 213 : return aInfo;
743 : : }
744 : :
745 : : // -----------------------------------------------------------------------
746 : :
747 : 0 : sal_Bool FontList::IsAvailable( const XubString& rName ) const
748 : : {
749 : 0 : return (ImplFindByName( rName ) != 0);
750 : : }
751 : :
752 : : // -----------------------------------------------------------------------
753 : :
754 : 146272 : const FontInfo& FontList::GetFontName( sal_uInt16 nFont ) const
755 : : {
756 : : DBG_ASSERT( nFont < GetFontNameCount(), "FontList::GetFontName(): nFont >= Count" );
757 : :
758 : 146272 : return *(maEntries[nFont].mpFirst);
759 : : }
760 : :
761 : : // -----------------------------------------------------------------------
762 : :
763 : 116 : sal_uInt16 FontList::GetFontNameType( sal_uInt16 nFont ) const
764 : : {
765 : : DBG_ASSERT( nFont < GetFontNameCount(), "FontList::GetFontNameType(): nFont >= Count" );
766 : :
767 : 116 : return maEntries[nFont].mnType;
768 : : }
769 : :
770 : : // -----------------------------------------------------------------------
771 : :
772 : 0 : sal_Handle FontList::GetFirstFontInfo( const XubString& rName ) const
773 : : {
774 : 0 : ImplFontListNameInfo* pData = ImplFindByName( rName );
775 [ # # ]: 0 : if ( !pData )
776 : 0 : return (sal_Handle)NULL;
777 : : else
778 : 0 : return (sal_Handle)pData->mpFirst;
779 : : }
780 : :
781 : : // -----------------------------------------------------------------------
782 : :
783 : 0 : sal_Handle FontList::GetNextFontInfo( sal_Handle hFontInfo ) const
784 : : {
785 : 0 : ImplFontListFontInfo* pInfo = (ImplFontListFontInfo*)(void*)hFontInfo;
786 : 0 : return (sal_Handle)(pInfo->mpNext);
787 : : }
788 : :
789 : : // -----------------------------------------------------------------------
790 : :
791 : 0 : const FontInfo& FontList::GetFontInfo( sal_Handle hFontInfo ) const
792 : : {
793 : 0 : ImplFontListFontInfo* pInfo = (ImplFontListFontInfo*)(void*)hFontInfo;
794 : 0 : return *pInfo;
795 : : }
796 : :
797 : : // -----------------------------------------------------------------------
798 : :
799 : 1481 : const long* FontList::GetSizeAry( const FontInfo& rInfo ) const
800 : : {
801 : : // Size-Array vorher loeschen
802 [ - + ]: 1481 : if ( mpSizeAry )
803 : : {
804 [ # # ]: 0 : delete[] ((FontList*)this)->mpSizeAry;
805 : 0 : ((FontList*)this)->mpSizeAry = NULL;
806 : : }
807 : :
808 : : // Falls kein Name, dann Standardgroessen
809 [ + - ][ - + ]: 1481 : if ( !rInfo.GetName().Len() )
810 : 0 : return aStdSizeAry;
811 : :
812 : : // Zuerst nach dem Fontnamen suchen um das Device dann von dem
813 : : // entsprechenden Font zu nehmen
814 : 1481 : OutputDevice* pDevice = mpDev;
815 [ + - ][ + - ]: 1481 : ImplFontListNameInfo* pData = ImplFindByName( rInfo.GetName() );
816 [ + + ]: 1481 : if ( pData )
817 : 1464 : pDevice = pData->mpFirst->GetDevice();
818 : :
819 [ + - ]: 1481 : int nDevSizeCount = pDevice->GetDevFontSizeCount( rInfo );
820 [ - + # # ]: 2962 : if ( !nDevSizeCount ||
[ + - ]
821 [ # # ][ - + ]: 1481 : (pDevice->GetDevFontSize( rInfo, 0 ).Height() == 0) )
[ # # ]
822 : 1481 : return aStdSizeAry;
823 : :
824 [ # # ]: 0 : MapMode aOldMapMode = pDevice->GetMapMode();
825 [ # # ][ # # ]: 0 : MapMode aMap( MAP_10TH_INCH, Point(), Fraction( 1, 72 ), Fraction( 1, 72 ) );
[ # # ]
826 [ # # ]: 0 : pDevice->SetMapMode( aMap );
827 : :
828 : : sal_uInt16 i;
829 : 0 : sal_uInt16 nRealCount = 0;
830 : 0 : long nOldHeight = 0;
831 [ # # ]: 0 : ((FontList*)this)->mpSizeAry = new long[nDevSizeCount+1];
832 [ # # ]: 0 : for ( i = 0; i < nDevSizeCount; i++ )
833 : : {
834 [ # # ]: 0 : Size aSize = pDevice->GetDevFontSize( rInfo, i );
835 [ # # ]: 0 : if ( aSize.Height() != nOldHeight )
836 : : {
837 : 0 : nOldHeight = aSize.Height();
838 : 0 : ((FontList*)this)->mpSizeAry[nRealCount] = nOldHeight;
839 : 0 : nRealCount++;
840 : : }
841 : : }
842 : 0 : ((FontList*)this)->mpSizeAry[nRealCount] = 0;
843 : :
844 [ # # ]: 0 : pDevice->SetMapMode( aOldMapMode );
845 [ # # ][ # # ]: 1481 : return mpSizeAry;
846 : : }
847 : :
848 : : // -----------------------------------------------------------------------
849 : :
850 : 1481 : const long* FontList::GetStdSizeAry()
851 : : {
852 : 1481 : return aStdSizeAry;
853 : : }
854 : :
855 : : // =======================================================================
856 : :
857 : : // ---------------------------------
858 : : // - FontSizeNames & FsizeNameItem -
859 : : // ---------------------------------
860 : :
861 : : struct ImplFSNameItem
862 : : {
863 : : long mnSize;
864 : : const char* mszUtf8Name;
865 : : };
866 : :
867 : : //------------------------------------------------------------------------
868 : :
869 : : static const ImplFSNameItem aImplSimplifiedChinese[] =
870 : : {
871 : : { 50, "\xe5\x85\xab\xe5\x8f\xb7" },
872 : : { 55, "\xe4\xb8\x83\xe5\x8f\xb7" },
873 : : { 65, "\xe5\xb0\x8f\xe5\x85\xad" },
874 : : { 75, "\xe5\x85\xad\xe5\x8f\xb7" },
875 : : { 90, "\xe5\xb0\x8f\xe4\xba\x94" },
876 : : { 105, "\xe4\xba\x94\xe5\x8f\xb7" },
877 : : { 120, "\xe5\xb0\x8f\xe5\x9b\x9b" },
878 : : { 140, "\xe5\x9b\x9b\xe5\x8f\xb7" },
879 : : { 150, "\xe5\xb0\x8f\xe4\xb8\x89" },
880 : : { 160, "\xe4\xb8\x89\xe5\x8f\xb7" },
881 : : { 180, "\xe5\xb0\x8f\xe4\xba\x8c" },
882 : : { 220, "\xe4\xba\x8c\xe5\x8f\xb7" },
883 : : { 240, "\xe5\xb0\x8f\xe4\xb8\x80" },
884 : : { 260, "\xe4\xb8\x80\xe5\x8f\xb7" },
885 : : { 360, "\xe5\xb0\x8f\xe5\x88\x9d" },
886 : : { 420, "\xe5\x88\x9d\xe5\x8f\xb7" }
887 : : };
888 : :
889 : : //------------------------------------------------------------------------
890 : :
891 : 7831 : FontSizeNames::FontSizeNames( LanguageType eLanguage )
892 : : {
893 [ - + ]: 7831 : if ( eLanguage == LANGUAGE_DONTKNOW )
894 : 0 : eLanguage = Application::GetSettings().GetUILanguage();
895 [ - + ]: 7831 : if ( eLanguage == LANGUAGE_SYSTEM )
896 : 0 : eLanguage = MsLangId::getSystemUILanguage();
897 : :
898 [ - + ]: 7831 : if (MsLangId::isSimplifiedChinese(eLanguage))
899 : : {
900 : : // equivalent for traditional chinese disabled by popular request, #i89077#
901 : 0 : mpArray = aImplSimplifiedChinese;
902 : 0 : mnElem = SAL_N_ELEMENTS(aImplSimplifiedChinese);
903 : : }
904 : : else
905 : : {
906 : 7831 : mpArray = NULL;
907 : 7831 : mnElem = 0;
908 : : }
909 : 7831 : }
910 : :
911 : : //------------------------------------------------------------------------
912 : :
913 : 2963 : long FontSizeNames::Name2Size( const String& rName ) const
914 : : {
915 [ - + ]: 2963 : if ( mnElem )
916 : : {
917 : : rtl::OString aName(rtl::OUStringToOString(rName,
918 [ # # ][ # # ]: 0 : RTL_TEXTENCODING_UTF8));
919 : :
920 : : // linear search is sufficient for this rare case
921 [ # # ]: 0 : for( long i = mnElem; --i >= 0; )
922 [ # # ]: 0 : if ( aName.equals(mpArray[i].mszUtf8Name) )
923 [ # # ]: 0 : return mpArray[i].mnSize;
924 : : }
925 : :
926 : 2963 : return 0;
927 : : }
928 : :
929 : : //------------------------------------------------------------------------
930 : :
931 : 3387 : String FontSizeNames::Size2Name( long nValue ) const
932 : : {
933 : 3387 : String aStr;
934 : :
935 : : // binary search
936 [ - + ]: 3387 : for( long lower = 0, upper = mnElem - 1; lower <= upper; )
937 : : {
938 : 0 : long mid = (upper + lower) >> 1;
939 [ # # ]: 0 : if ( nValue == mpArray[mid].mnSize )
940 : : {
941 [ # # ][ # # ]: 0 : aStr = String( mpArray[mid].mszUtf8Name, RTL_TEXTENCODING_UTF8 );
[ # # ]
942 : 0 : break;
943 : : }
944 [ # # ]: 0 : else if ( nValue < mpArray[mid].mnSize )
945 : 0 : upper = mid - 1;
946 : : else /* ( nValue > mpArray[mid].mnSize ) */
947 : 0 : lower = mid + 1;
948 : : }
949 : :
950 : 3387 : return aStr;
951 : : }
952 : :
953 : : //------------------------------------------------------------------------
954 : :
955 : 0 : String FontSizeNames::GetIndexName( sal_uLong nIndex ) const
956 : : {
957 : 0 : String aStr;
958 : :
959 [ # # ]: 0 : if ( nIndex < mnElem )
960 [ # # ][ # # ]: 0 : aStr = String( mpArray[nIndex].mszUtf8Name, RTL_TEXTENCODING_UTF8 );
[ # # ]
961 : :
962 : 0 : return aStr;
963 : : }
964 : :
965 : : //------------------------------------------------------------------------
966 : :
967 : 0 : long FontSizeNames::GetIndexSize( sal_uLong nIndex ) const
968 : : {
969 [ # # ]: 0 : if ( nIndex >= mnElem )
970 : 0 : return 0;
971 : 0 : return mpArray[nIndex].mnSize;
972 : : }
973 : :
974 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|