1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
|
/*************************************************************************
*
* $RCSfile: fontcache.cxx,v $
*
* $Revision: 1.11 $
*
* last change: $Author: obo $ $Date: 2004-07-05 09:22:24 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include <cstdlib>
#include <cstring>
#include <psprint/fontcache.hxx>
#ifndef _OSL_THREAD_H
#include <osl/thread.h>
#endif
#ifndef _UTL_ATOM_HXX_
#include <unotools/atom.hxx>
#endif
#ifndef _STREAM_HXX
#include <tools/stream.hxx>
#endif
#include <unistd.h>
#include <sys/stat.h>
#if OSL_DEBUG_LEVEL >1
#include <cstdio>
#endif
#define FONTCACHEFILE "/user/psprint/pspfontcache"
using namespace std;
using namespace rtl;
using namespace psp;
using namespace utl;
/*
* static helpers
*/
/*
* FontCache constructor
*/
FontCache::FontCache()
{
m_bDoFlush = false;
m_aCacheFile = getOfficePath( UserPath );
if( m_aCacheFile.Len() )
{
m_aCacheFile.AppendAscii( FONTCACHEFILE );
read();
}
}
/*
* FontCache destructor
*/
FontCache::~FontCache()
{
clearCache();
}
/*
* FontCache::clearCache
*/
void FontCache::clearCache()
{
for( FontCacheData::iterator dir_it = m_aCache.begin(); dir_it != m_aCache.end(); ++dir_it )
{
for( FontDirMap::iterator entry_it = dir_it->second.m_aEntries.begin(); entry_it != dir_it->second.m_aEntries.end(); ++entry_it )
{
for( FontCacheEntry::iterator font_it = entry_it->second.m_aEntry.begin(); font_it != entry_it->second.m_aEntry.end(); ++font_it )
delete *font_it;
}
}
m_aCache.clear();
}
/*
* FontCache::Commit
*/
void FontCache::flush()
{
if( ! m_bDoFlush || ! m_aCacheFile.Len() )
return;
SvFileStream aStream;
aStream.Open( m_aCacheFile, STREAM_WRITE | STREAM_TRUNC );
if( ! (aStream.IsOpen() && aStream.IsWritable()) )
{
#if OSL_DEBUG_LEVEL > 1
fprintf( stderr, "FontCache::flush: opening cache file %s failed\n", ByteString( m_aCacheFile, osl_getThreadTextEncoding() ).GetBuffer() );
#endif
return;
}
aStream.SetLineDelimiter( LINEEND_LF );
PrintFontManager& rManager( PrintFontManager::get() );
MultiAtomProvider* pAtoms = rManager.m_pAtoms;
for( FontCacheData::const_iterator dir_it = m_aCache.begin(); dir_it != m_aCache.end(); ++ dir_it )
{
const FontDirMap& rDir( dir_it->second.m_aEntries );
ByteString aDirectory( rManager.getDirectory( dir_it->first ) );
ByteString aLine( "FontCacheDirectory:" );
aLine.Append( ByteString::CreateFromInt64( dir_it->second.m_nTimestamp ) );
aLine.Append( ':' );
aLine.Append( aDirectory );
if( rDir.empty() && dir_it->second.m_bNoFiles )
aLine.Insert( "Empty", 0 );
aStream.WriteLine( aLine );
for( FontDirMap::const_iterator entry_it = rDir.begin(); entry_it != rDir.end(); ++entry_it )
{
// insert cache entries
const FontCacheEntry& rEntry( entry_it->second.m_aEntry );
if( rEntry.begin() == rEntry.end() )
continue;
struct stat aStat;
ByteString aFileName( aDirectory );
aFileName.Append( '/' );
aFileName.Append( ByteString( entry_it->first ) );
if( stat( aFileName.GetBuffer(), &aStat ) )
continue;
aLine = "File:";
aLine.Append( ByteString( entry_it->first ) );
aStream.WriteLine( aLine );
int nEntrySize = entry_it->second.m_aEntry.size();
// write: type;mtime;nfonts
aLine = ByteString::CreateFromInt32( rEntry.front()->m_eType );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt64( aStat.st_mtime ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( nEntrySize ) );
aStream.WriteLine( aLine );
sal_Int32 nSubEntry = 0;
for( FontCacheEntry::const_iterator it = rEntry.begin(); it != rEntry.end(); ++it, nSubEntry++ )
{
/*
* for each font entry write:
* name[;name[;name]]
* fontnr;PSName;italic;weight;width;pitch;encoding;ascend;descend;leading;vsubst;gxw;gxh;gyw;gyh[;{metricfile,typeflags}]
*/
if( nEntrySize > 1 )
nSubEntry = static_cast<const PrintFontManager::TrueTypeFontFile*>(*it)->m_nCollectionEntry;
aLine = OUStringToOString( pAtoms->getString( ATOM_FAMILYNAME, (*it)->m_nFamilyName ), RTL_TEXTENCODING_UTF8 );
for( ::std::list< int >::const_iterator name_it = (*it)->m_aAliases.begin(); name_it != (*it)->m_aAliases.end(); ++name_it )
{
const OUString& rAdd( pAtoms->getString( ATOM_FAMILYNAME, *name_it ) );
if( rAdd.getLength() )
{
aLine.Append( ';' );
aLine.Append( ByteString( String( rAdd ), RTL_TEXTENCODING_UTF8 ) );
}
}
aStream.WriteLine( aLine );
const OUString& rPSName( pAtoms->getString( ATOM_PSNAME, (*it)->m_nPSName ) );
aLine = ByteString::CreateFromInt32( nSubEntry );
aLine.Append( ';' );
aLine.Append( ByteString( String( rPSName ), RTL_TEXTENCODING_UTF8 ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_eItalic ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_eWeight ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_eWidth ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_ePitch ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_aEncoding ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_nAscend ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_nDescend ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_nLeading ) );
aLine.Append( ';' );
aLine.Append( (*it)->m_bHaveVerticalSubstitutedGlyphs ? "1" : "0" );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_aGlobalMetricX.width ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_aGlobalMetricX.height ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_aGlobalMetricY.width ) );
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( (*it)->m_aGlobalMetricY.height ) );
switch( (*it)->m_eType )
{
case fonttype::Type1:
aLine.Append( ';' );
aLine.Append( ByteString( static_cast<const PrintFontManager::Type1FontFile*>(*it)->m_aMetricFile ) );
break;
case fonttype::TrueType:
aLine.Append( ';' );
aLine.Append( ByteString::CreateFromInt32( static_cast<const PrintFontManager::TrueTypeFontFile*>(*it)->m_nTypeFlags ) );
break;
default: break;
}
aStream.WriteLine( aLine );
}
aStream.WriteLine( ByteString() );
}
}
m_bDoFlush = false;
}
/*
* FontCache::read
*/
void FontCache::read()
{
PrintFontManager& rManager( PrintFontManager::get() );
MultiAtomProvider* pAtoms = rManager.m_pAtoms;
SvFileStream aStream( m_aCacheFile, STREAM_READ );
if( ! aStream.IsOpen() )
{
#if OSL_DEBUG_LEVEL > 1
fprintf( stderr, "FontCache::read: opening cache file %s failed\n", ByteString( m_aCacheFile, osl_getThreadTextEncoding() ).GetBuffer() );
#endif
return;
}
ByteString aLine;
int nDir = 0;
FontDirMap* pDir = NULL;
xub_StrLen nIndex;
do
{
aStream.ReadLine( aLine );
if( aLine.CompareTo( "FontCacheDirectory:", 19 ) == COMPARE_EQUAL ||
aLine.CompareTo( "EmptyFontCacheDirectory:", 24 ) == COMPARE_EQUAL )
{
bool bEmpty = (aLine.CompareTo( "Empty", 5 ) == COMPARE_EQUAL);
xub_StrLen nSearchIndex = bEmpty ? 24 : 19;
OString aDir;
sal_Int64 nTimestamp = 0;
xub_StrLen nTEnd = aLine.Search( ':', nSearchIndex );
if( nTEnd != STRING_NOTFOUND )
{
nTimestamp = aLine.Copy( nSearchIndex, nTEnd - nSearchIndex ).ToInt64();
aDir = aLine.Copy( nTEnd+1 );
}
else
{
// invalid format, remove
pDir = NULL;
nDir = 0;
m_bDoFlush = true;
continue;
}
// is the directory modified ?
struct stat aStat;
if( stat( aDir.getStr(), &aStat ) ||
(sal_Int64)aStat.st_mtime != nTimestamp ||
! S_ISDIR(aStat.st_mode) )
{
// remove outdated cache data
pDir = NULL;
nDir = 0;
m_bDoFlush = true;
continue;
}
else
{
nDir = rManager.getDirectoryAtom( aDir, true );
m_aCache[ nDir ].m_nTimestamp = nTimestamp;
m_aCache[ nDir ].m_bNoFiles = bEmpty;
pDir = bEmpty ? NULL : &m_aCache[ nDir ].m_aEntries;
}
}
else if( pDir && aLine.CompareTo( "File:", 5 ) == COMPARE_EQUAL )
{
OString aFile( aLine.Copy( 5 ) );
aStream.ReadLine( aLine );
nIndex = 0;
fonttype::type eType = (fonttype::type)aLine.GetToken( 0, ';', nIndex ).ToInt32();
if( eType != fonttype::TrueType &&
eType != fonttype::Type1 &&
eType != fonttype::Builtin
)
continue;
if( nIndex == STRING_NOTFOUND )
continue;
sal_Int64 nTime = aLine.GetToken( 0, ';', nIndex ).ToInt64();
if( nIndex == STRING_NOTFOUND )
continue;
sal_Int32 nFonts = aLine.GetToken( 0, ';', nIndex ).ToInt32();
(*pDir)[ aFile ].m_nTimestamp = nTime;
for( int n = 0; n < nFonts; n++ )
{
aStream.ReadLine( aLine );
PrintFontManager::PrintFont* pFont = NULL;
switch( eType )
{
case fonttype::TrueType:
pFont = new PrintFontManager::TrueTypeFontFile();
break;
case fonttype::Type1:
pFont = new PrintFontManager::Type1FontFile();
break;
case fonttype::Builtin:
pFont = new PrintFontManager::BuiltinFont();
break;
default: break;
}
nIndex = 0;
pFont->m_nFamilyName = pAtoms->getAtom( ATOM_FAMILYNAME,
String( aLine.GetToken( 0, ';', nIndex ), RTL_TEXTENCODING_UTF8 ),
sal_True );
while( nIndex != STRING_NOTFOUND )
{
String aAlias( aLine.GetToken( 0, ';', nIndex ), RTL_TEXTENCODING_UTF8 );
if( aAlias.Len() )
pFont->m_aAliases.push_back( pAtoms->getAtom( ATOM_FAMILYNAME, aAlias, sal_True ) );
}
#define CHECKINDEX() if( nIndex == STRING_NOTFOUND ) { delete pFont; continue; }
aStream.ReadLine( aLine );
nIndex = 0;
int nCollEntry = aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_nPSName = pAtoms->getAtom( ATOM_PSNAME, String( aLine.GetToken( 0, ';', nIndex ), RTL_TEXTENCODING_UTF8 ), sal_True );
CHECKINDEX();
pFont->m_eItalic = (italic::type)aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_eWeight = (weight::type)aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_eWidth = (width::type)aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_ePitch = (pitch::type)aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_aEncoding = (rtl_TextEncoding)aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_nAscend = aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_nDescend = aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_nLeading = aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_bHaveVerticalSubstitutedGlyphs = aLine.GetToken( 0, ';', nIndex ).CompareIgnoreCaseToAscii( "true" ) == COMPARE_EQUAL ? true : false;
CHECKINDEX();
pFont->m_aGlobalMetricX.width = aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_aGlobalMetricX.height = aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_aGlobalMetricY.width = aLine.GetToken( 0, ';', nIndex ).ToInt32();
CHECKINDEX();
pFont->m_aGlobalMetricY.height = aLine.GetToken( 0, ';', nIndex ).ToInt32();
switch( eType )
{
case fonttype::TrueType:
CHECKINDEX();
static_cast<PrintFontManager::TrueTypeFontFile*>(pFont)->m_nTypeFlags = aLine.GetToken( 0, ';', nIndex ).ToInt32();
static_cast<PrintFontManager::TrueTypeFontFile*>(pFont)->m_nCollectionEntry = nCollEntry;
static_cast<PrintFontManager::TrueTypeFontFile*>(pFont)->m_nDirectory = nDir;
static_cast<PrintFontManager::TrueTypeFontFile*>(pFont)->m_aFontFile = aFile;
break;
case fonttype::Type1:
{
CHECKINDEX();
ByteString aMetricFile( aLine.GetToken( 0, ';', nIndex ) );
static_cast<PrintFontManager::Type1FontFile*>(pFont)->m_aMetricFile = aMetricFile;
static_cast<PrintFontManager::Type1FontFile*>(pFont)->m_nDirectory = nDir;
static_cast<PrintFontManager::Type1FontFile*>(pFont)->m_aFontFile = aFile;
}
break;
case fonttype::Builtin:
static_cast<PrintFontManager::BuiltinFont*>(pFont)->m_nDirectory = nDir;
static_cast<PrintFontManager::BuiltinFont*>(pFont)->m_aMetricFile = aFile;
break;
default: break;
}
/*
* #i20287# duplicate lines could exist because of
* fontcache code prior to OOo 1.1.1, ignore them
*/
bool bDuplicate = false;
FontCacheEntry& rEntry = (*pDir)[aFile].m_aEntry;
for( FontCacheEntry::const_iterator entry = rEntry.begin();
entry != rEntry.end() && ! bDuplicate; ++entry )
{
const PrintFontManager::PrintFont* pOld = *entry;
if( pOld->m_eType == pFont->m_eType &&
pOld->m_nFamilyName == pFont->m_nFamilyName &&
pOld->m_nPSName == pFont->m_nPSName &&
pOld->m_eItalic == pFont->m_eItalic &&
pOld->m_eWidth == pFont->m_eWidth &&
pOld->m_ePitch == pFont->m_ePitch &&
pOld->m_aEncoding == pFont->m_aEncoding &&
pOld->m_bFontEncodingOnly == pFont->m_bFontEncodingOnly &&
pOld->m_nAscend == pFont->m_nAscend &&
pOld->m_nDescend == pFont->m_nDescend
)
bDuplicate = m_bDoFlush = true;
}
if( bDuplicate )
{
#if OSL_DEBUG_LEVEL > 1
fprintf( stderr, "removing duplicate font %s\n", aFile.getStr() );
#endif
delete pFont;
continue;
}
rEntry.push_back( pFont );
}
}
} while( ! aStream.IsEof() );
}
/*
* FontCache::updateDirTimestamp
*/
void FontCache::updateDirTimestamp( int nDirID )
{
PrintFontManager& rManager( PrintFontManager::get() );
const OString& rDir = rManager.getDirectory( nDirID );
struct stat aStat;
if( ! stat( rDir.getStr(), &aStat ) )
m_aCache[ nDirID ].m_nTimestamp = (sal_Int64)aStat.st_mtime;
}
/*
* FontCache::copyPrintFont
*/
void FontCache::copyPrintFont( const PrintFontManager::PrintFont* pFrom, PrintFontManager::PrintFont* pTo ) const
{
if( pFrom->m_eType != pTo->m_eType )
return;
switch( pFrom->m_eType )
{
case fonttype::TrueType:
static_cast<PrintFontManager::TrueTypeFontFile*>(pTo)->m_nDirectory = static_cast<const PrintFontManager::TrueTypeFontFile*>(pFrom)->m_nDirectory;
static_cast<PrintFontManager::TrueTypeFontFile*>(pTo)->m_aFontFile = static_cast<const PrintFontManager::TrueTypeFontFile*>(pFrom)->m_aFontFile;
static_cast<PrintFontManager::TrueTypeFontFile*>(pTo)->m_nCollectionEntry = static_cast<const PrintFontManager::TrueTypeFontFile*>(pFrom)->m_nCollectionEntry;
static_cast<PrintFontManager::TrueTypeFontFile*>(pTo)->m_nTypeFlags = static_cast<const PrintFontManager::TrueTypeFontFile*>(pFrom)->m_nTypeFlags;
break;
case fonttype::Type1:
static_cast<PrintFontManager::Type1FontFile*>(pTo)->m_nDirectory = static_cast<const PrintFontManager::Type1FontFile*>(pFrom)->m_nDirectory;
static_cast<PrintFontManager::Type1FontFile*>(pTo)->m_aFontFile = static_cast<const PrintFontManager::Type1FontFile*>(pFrom)->m_aFontFile;
static_cast<PrintFontManager::Type1FontFile*>(pTo)->m_aMetricFile = static_cast<const PrintFontManager::Type1FontFile*>(pFrom)->m_aMetricFile;
break;
case fonttype::Builtin:
static_cast<PrintFontManager::BuiltinFont*>(pTo)->m_nDirectory = static_cast<const PrintFontManager::BuiltinFont*>(pFrom)->m_nDirectory;
static_cast<PrintFontManager::BuiltinFont*>(pTo)->m_aMetricFile = static_cast<const PrintFontManager::BuiltinFont*>(pFrom)->m_aMetricFile;
break;
default: break;
}
pTo->m_nFamilyName = pFrom->m_nFamilyName;
pTo->m_aAliases = pFrom->m_aAliases;
pTo->m_nPSName = pFrom->m_nPSName;
pTo->m_eItalic = pFrom->m_eItalic;
pTo->m_eWeight = pFrom->m_eWeight;
pTo->m_eWidth = pFrom->m_eWidth;
pTo->m_ePitch = pFrom->m_ePitch;
pTo->m_aEncoding = pFrom->m_aEncoding;
pTo->m_aGlobalMetricX = pFrom->m_aGlobalMetricX;
pTo->m_aGlobalMetricY = pFrom->m_aGlobalMetricY;
pTo->m_nAscend = pFrom->m_nAscend;
pTo->m_nDescend = pFrom->m_nDescend;
pTo->m_nLeading = pFrom->m_nLeading;
pTo->m_nXMin = pFrom->m_nXMin;
pTo->m_nYMin = pFrom->m_nYMin;
pTo->m_nXMax = pFrom->m_nXMax;
pTo->m_nYMax = pFrom->m_nYMax;
pTo->m_bHaveVerticalSubstitutedGlyphs = pFrom->m_bHaveVerticalSubstitutedGlyphs;
}
/*
* FontCache::equalsPrintFont
*/
bool FontCache::equalsPrintFont( const PrintFontManager::PrintFont* pLeft, PrintFontManager::PrintFont* pRight ) const
{
if( pLeft->m_eType != pRight->m_eType )
return false;
switch( pLeft->m_eType )
{
case fonttype::TrueType:
{
const PrintFontManager::TrueTypeFontFile* pLT = static_cast<const PrintFontManager::TrueTypeFontFile*>(pLeft);
const PrintFontManager::TrueTypeFontFile* pRT = static_cast<const PrintFontManager::TrueTypeFontFile*>(pRight);
if( pRT->m_nDirectory != pLT->m_nDirectory ||
pRT->m_aFontFile != pLT->m_aFontFile ||
pRT->m_nCollectionEntry != pLT->m_nCollectionEntry ||
pRT->m_nTypeFlags != pLT->m_nTypeFlags )
return false;
}
break;
case fonttype::Type1:
{
const PrintFontManager::Type1FontFile* pLT = static_cast<const PrintFontManager::Type1FontFile*>(pLeft);
const PrintFontManager::Type1FontFile* pRT = static_cast<const PrintFontManager::Type1FontFile*>(pRight);
if( pRT->m_nDirectory != pLT->m_nDirectory ||
pRT->m_aFontFile != pLT->m_aFontFile ||
pRT->m_aMetricFile != pLT->m_aMetricFile )
return false;
}
break;
case fonttype::Builtin:
{
const PrintFontManager::BuiltinFont* pLT = static_cast<const PrintFontManager::BuiltinFont*>(pLeft);
const PrintFontManager::BuiltinFont* pRT = static_cast<const PrintFontManager::BuiltinFont*>(pRight);
if( pRT->m_nDirectory != pLT->m_nDirectory ||
pRT->m_aMetricFile != pLT->m_aMetricFile )
return false;
}
break;
default: break;
}
if( pRight->m_nFamilyName != pLeft->m_nFamilyName ||
pRight->m_nPSName != pLeft->m_nPSName ||
pRight->m_eItalic != pLeft->m_eItalic ||
pRight->m_eWeight != pLeft->m_eWeight ||
pRight->m_eWidth != pLeft->m_eWidth ||
pRight->m_ePitch != pLeft->m_ePitch ||
pRight->m_aEncoding != pLeft->m_aEncoding ||
pRight->m_aGlobalMetricX != pLeft->m_aGlobalMetricX ||
pRight->m_aGlobalMetricY != pLeft->m_aGlobalMetricY ||
pRight->m_nAscend != pLeft->m_nAscend ||
pRight->m_nDescend != pLeft->m_nDescend ||
pRight->m_nLeading != pLeft->m_nLeading ||
pRight->m_nXMin != pLeft->m_nXMin ||
pRight->m_nYMin != pLeft->m_nYMin ||
pRight->m_nXMax != pLeft->m_nXMax ||
pRight->m_nYMax != pLeft->m_nYMax ||
pRight->m_bHaveVerticalSubstitutedGlyphs != pLeft->m_bHaveVerticalSubstitutedGlyphs )
return false;
std::list< int >::const_iterator lit, rit;
for( lit = pLeft->m_aAliases.begin(), rit = pRight->m_aAliases.begin();
lit != pLeft->m_aAliases.end() && rit != pRight->m_aAliases.end() && (*lit) == (*rit);
++lit, ++rit )
;
return lit == pLeft->m_aAliases.end() && rit == pRight->m_aAliases.end();
}
/*
* FontCache::clonePrintFont
*/
PrintFontManager::PrintFont* FontCache::clonePrintFont( const PrintFontManager::PrintFont* pOldFont ) const
{
PrintFontManager::PrintFont* pFont = NULL;
switch( pOldFont->m_eType )
{
case fonttype::TrueType:
pFont = new PrintFontManager::TrueTypeFontFile();
break;
case fonttype::Type1:
pFont = new PrintFontManager::Type1FontFile();
break;
case fonttype::Builtin:
pFont = new PrintFontManager::BuiltinFont();
break;
default: break;
}
if( pFont )
{
copyPrintFont( pOldFont, pFont );
}
return pFont;
}
/*
* FontCache::getFontCacheFile
*/
bool FontCache::getFontCacheFile( int nDirID, const OString& rDir, const OString& rFile, list< PrintFontManager::PrintFont* >& rNewFonts ) const
{
bool bSuccess = false;
FontCacheData::const_iterator dir = m_aCache.find( nDirID );
if( dir != m_aCache.end() )
{
FontDirMap::const_iterator entry = dir->second.m_aEntries.find( rFile );
if( entry != dir->second.m_aEntries.end() )
{
bSuccess = true;
for( FontCacheEntry::const_iterator font = entry->second.m_aEntry.begin(); font != entry->second.m_aEntry.end(); ++font )
{
PrintFontManager::PrintFont* pFont = clonePrintFont( *font );
rNewFonts.push_back( pFont );
}
}
}
return bSuccess;
}
/*
* FontCache::updateFontCacheEntry
*/
void FontCache::updateFontCacheEntry( const PrintFontManager::PrintFont* pFont, bool bFlush )
{
PrintFontManager& rManager( PrintFontManager::get() );
OString aFile;
int nDirID = 0;
switch( pFont->m_eType )
{
case fonttype::TrueType:
nDirID = static_cast<const PrintFontManager::TrueTypeFontFile*>(pFont)->m_nDirectory;
aFile = static_cast<const PrintFontManager::TrueTypeFontFile*>(pFont)->m_aFontFile;
break;
case fonttype::Type1:
nDirID = static_cast<const PrintFontManager::Type1FontFile*>(pFont)->m_nDirectory;
aFile = static_cast<const PrintFontManager::Type1FontFile*>(pFont)->m_aFontFile;
break;
case fonttype::Builtin:
nDirID = static_cast<const PrintFontManager::BuiltinFont*>(pFont)->m_nDirectory;
aFile = static_cast<const PrintFontManager::BuiltinFont*>(pFont)->m_aMetricFile;
break;
default:
return;
}
FontCacheData::const_iterator dir = m_aCache.find( nDirID );
FontDirMap::const_iterator entry;
FontCacheEntry::const_iterator font;
PrintFontManager::PrintFont* pCacheFont = NULL;
if( dir != m_aCache.end() )
{
entry = dir->second.m_aEntries.find( aFile );
if( entry != dir->second.m_aEntries.end() )
{
for( font = entry->second.m_aEntry.begin(); font != entry->second.m_aEntry.end(); ++font )
{
if( (*font)->m_eType == pFont->m_eType &&
( (*font)->m_eType != fonttype::TrueType ||
static_cast<const PrintFontManager::TrueTypeFontFile*>(*font)->m_nCollectionEntry == static_cast<const PrintFontManager::TrueTypeFontFile*>(pFont)->m_nCollectionEntry
) )
break;
}
if( font != entry->second.m_aEntry.end() )
pCacheFont = *font;
}
}
else
createCacheDir( nDirID );
if( pCacheFont )
{
if( ! equalsPrintFont( pFont, pCacheFont ) )
{
copyPrintFont( pFont, pCacheFont );
m_bDoFlush = true;
}
}
else
{
pCacheFont = clonePrintFont( pFont );
m_aCache[nDirID].m_aEntries[aFile].m_aEntry.push_back( pCacheFont );
ByteString aPath = rManager.getDirectory( nDirID );
aPath.Append( '/' );
aPath.Append( ByteString( aFile ) );
struct stat aStat;
if( ! stat( aPath.GetBuffer(), &aStat ) )
m_aCache[nDirID].m_aEntries[aFile].m_nTimestamp = (sal_Int64)aStat.st_mtime;
m_bDoFlush = true;
}
if( bFlush )
flush();
}
/*
* FontCache::listDirectory
*/
bool FontCache::listDirectory( const OString& rDir, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const
{
PrintFontManager& rManager( PrintFontManager::get() );
int nDirID = rManager.getDirectoryAtom( rDir );
FontCacheData::const_iterator dir = m_aCache.find( nDirID );
bool bFound = (dir != m_aCache.end());
if( bFound && !dir->second.m_bNoFiles )
{
for( FontDirMap::const_iterator file = dir->second.m_aEntries.begin(); file != dir->second.m_aEntries.end(); ++file )
{
for( FontCacheEntry::const_iterator font = file->second.m_aEntry.begin(); font != file->second.m_aEntry.end(); ++font )
{
PrintFontManager::PrintFont* pFont = clonePrintFont( *font );
rNewFonts.push_back( pFont );
}
}
}
return bFound;
}
/*
* FontCache::createCacheDir
*/
void FontCache::createCacheDir( int nDirID )
{
PrintFontManager& rManager( PrintFontManager::get() );
const OString& rDir = rManager.getDirectory( nDirID );
struct stat aStat;
if( ! stat( rDir.getStr(), &aStat ) )
m_aCache[nDirID].m_nTimestamp = (sal_Int64)aStat.st_mtime;
}
/*
* FontCache::markEmptyDir
*/
void FontCache::markEmptyDir( int nDirID, bool bNoFiles )
{
createCacheDir( nDirID );
m_aCache[nDirID].m_bNoFiles = bNoFiles;
m_bDoFlush = true;
}
|