xref: /trunk/main/vcl/inc/vcl/fontmanager.hxx (revision 74cbd1f1)
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 #ifndef _PSPRINT_FONTMANAGER_HXX_
25 #define _PSPRINT_FONTMANAGER_HXX_
26 
27 #include <hash_map>
28 #include <map>
29 #include <list>
30 #include <set>
31 #include <vector>
32 
33 #include "vcl/dllapi.h"
34 #include "vcl/helper.hxx"
35 #include "salglyphid.hxx"
36 
37 #include "com/sun/star/lang/Locale.hpp"
38 
39 #define ATOM_FAMILYNAME                     2
40 #define ATOM_PSNAME                         3
41 
42 /*
43  *  some words on metrics: every length returned by PrintFontManager and
44  *  friends are PostScript afm style, that is they are 1/1000 font height
45  */
46 
47 // forward declarations
48 namespace utl { class MultiAtomProvider; } // see unotools/atom.hxx
49 class FontSubsetInfo;
50 class ImplFontOptions;
51 
52 namespace psp {
53 class PPDParser; // see ppdparser.hxx
54 
55 namespace italic
56 {
57 enum type {
58     Upright = 0,
59     Oblique = 1,
60     Italic = 2,
61     Unknown = 3
62 };
63 }
64 
65 namespace width
66 {
67 enum type {
68     Unknown = 0,
69     UltraCondensed = 1,
70     ExtraCondensed = 2,
71     Condensed = 3,
72     SemiCondensed = 4,
73     Normal = 5,
74     SemiExpanded = 6,
75     Expanded = 7,
76     ExtraExpanded = 8,
77     UltraExpanded = 9
78 };
79 }
80 
81 namespace pitch
82 {
83 enum type {
84     Unknown = 0,
85     Fixed = 1,
86     Variable = 2
87 };
88 }
89 
90 namespace weight
91 {
92 enum type {
93     Unknown = 0,
94     Thin = 1,
95     UltraLight = 2,
96     Light = 3,
97     SemiLight = 4,
98     Normal = 5,
99     Medium = 6,
100     SemiBold = 7,
101     Bold = 8,
102     UltraBold = 9,
103     Black = 10
104 };
105 }
106 
107 namespace family
108 {
109 enum type {
110     Unknown = 0,
111     Decorative = 1,
112     Modern = 2,
113     Roman = 3,
114     Script = 4,
115     Swiss = 5,
116     System = 6
117 };
118 }
119 
120 namespace fonttype
121 {
122 enum type {
123     Unknown = 0,
124     Type1 = 1,
125     TrueType = 2,
126     Builtin = 3
127 };
128 }
129 
130 namespace fcstatus
131 {
132 enum type {
133     istrue,
134     isunset,
135     isfalse
136 };
137 }
138 
139 /*
140  *  the difference between FastPrintFontInfo and PrintFontInfo
141  *  is that the information in FastPrintFontInfo can usually
142  *  be gathered without openening either the font file or
143  *  an afm metric file. they are gathered from fonts.dir alone.
144  *  if only FastPrintFontInfo is gathered and PrintFontInfo
145  *  on demand and for less fonts, then performance in startup
146  *  increases considerably
147  */
148 
149 struct FastPrintFontInfo
150 {
151     fontID                  			m_nID; // FontID
152     fonttype::type          			m_eType;
153 
154     // font attributes
155     rtl::OUString         				m_aFamilyName;
156     rtl::OUString                       m_aStyleName;
157     std::list< rtl::OUString >			m_aAliases;
158     family::type            			m_eFamilyStyle;
159     italic::type            			m_eItalic;
160     width::type             			m_eWidth;
161     weight::type            			m_eWeight;
162     pitch::type             			m_ePitch;
163     rtl_TextEncoding        			m_aEncoding;
164     bool                                m_bSubsettable;
165     bool                                m_bEmbeddable;
166 
FastPrintFontInfopsp::FastPrintFontInfo167     FastPrintFontInfo() :
168             m_nID( 0 ),
169             m_eType( fonttype::Unknown ),
170             m_eFamilyStyle( family::Unknown ),
171             m_eItalic( italic::Unknown ),
172             m_eWidth( width::Unknown ),
173             m_eWeight( weight::Unknown ),
174             m_ePitch( pitch::Unknown ),
175             m_aEncoding( RTL_TEXTENCODING_DONTKNOW )
176     {}
177 };
178 
179 struct PrintFontInfo : public FastPrintFontInfo
180 {
181     int                     				m_nAscend;
182     int                     				m_nDescend;
183     int                     				m_nLeading;
184     int                     				m_nWidth;
185 
PrintFontInfopsp::PrintFontInfo186     PrintFontInfo() :
187             FastPrintFontInfo(),
188             m_nAscend( 0 ),
189             m_nDescend( 0 ),
190             m_nLeading( 0 ),
191             m_nWidth( 0 )
192     {}
193 };
194 
195 // the values are per thousand of the font size
196 // note: width, height contain advances, not bounding box
197 struct CharacterMetric
198 {
199     short int width, height;
200 
CharacterMetricpsp::CharacterMetric201     CharacterMetric() : width( 0 ), height( 0 ) {}
operator ==psp::CharacterMetric202     bool operator==( const CharacterMetric& rOther ) const
203     { return rOther.width == width && rOther.height == height; }
operator !=psp::CharacterMetric204     bool operator!=( const CharacterMetric& rOther ) const
205     { return rOther.width != width || rOther.height != height; }
206 };
207 
208 struct KernPair
209 {
210     sal_Unicode first, second;
211     short int kern_x, kern_y;
212 
KernPairpsp::KernPair213     KernPair() : first( 0 ), second( 0 ), kern_x( 0 ), kern_y( 0 ) {}
214 };
215 
216 class FontCache;
217 
218 // a class to manage printable fonts
219 // aims are type1 and truetype fonts
220 
221 class FontCache;
222 
223 class VCL_PLUGIN_PUBLIC PrintFontManager
224 {
225     struct PrintFont;
226     struct TrueTypeFontFile;
227     struct Type1FontFile;
228     struct BuiltinFont;
229     friend struct PrintFont;
230     friend struct TrueTypeFontFile;
231     friend struct Type1FontFile;
232     friend struct BuiltinFont;
233     friend class FontCache;
234 
235     struct PrintFontMetrics
236     {
237         // character metrics are stored by the following keys:
238         // lower two bytes contain a sal_Unicode (a UCS2 character)
239         // upper byte contains: 0 for horizontal metric
240         //                      1 for vertical metric
241         // highest byte: 0 for now
242         std::hash_map< int, CharacterMetric >     m_aMetrics;
243         // contains the unicode blocks for which metrics were queried
244         // this implies that metrics should be queried in terms of
245         // unicode blocks. here a unicode block is identified
246         // by the upper byte of the UCS2 encoding.
247         // note that the corresponding bit should be set even
248         // if the font does not support a single character of that page
249         // this map shows, which pages were queried already
250         // if (like in AFM metrics) all metrics are queried in
251         // a single pass, then all bits should be set
252         char                                        m_aPages[32];
253 
254         bool                                        m_bKernPairsQueried;
255         std::list< KernPair >                     m_aXKernPairs;
256         std::list< KernPair >                     m_aYKernPairs;
257         std::hash_map< sal_Unicode, bool >		m_bVerticalSubstitutions;
258 
PrintFontMetricspsp::PrintFontManager::PrintFontMetrics259         PrintFontMetrics() : m_bKernPairsQueried( false ) {}
260 
isEmptypsp::PrintFontManager::PrintFontMetrics261         bool isEmpty() const { return m_aMetrics.empty(); }
262     };
263 
264     struct PrintFont
265     {
266         fonttype::type                              m_eType;
267 
268         // font attributes
269         int                                         m_nFamilyName;  // atom
270         std::list< int >							m_aAliases;
271         int                                         m_nPSName;      // atom
272         rtl::OUString                               m_aStyleName;
273         italic::type                                m_eItalic;
274         width::type                                 m_eWidth;
275         weight::type                                m_eWeight;
276         pitch::type                                 m_ePitch;
277         rtl_TextEncoding                            m_aEncoding;
278         bool										m_bFontEncodingOnly; // set if font should be only accessed by builtin encoding
279         CharacterMetric                             m_aGlobalMetricX;
280         CharacterMetric                             m_aGlobalMetricY;
281         PrintFontMetrics*                           m_pMetrics;
282         int                                         m_nAscend;
283         int                                         m_nDescend;
284         int                                         m_nLeading;
285         int											m_nXMin; // font bounding box
286         int											m_nYMin;
287         int											m_nXMax;
288         int											m_nYMax;
289         bool										m_bHaveVerticalSubstitutedGlyphs;
290         bool                                        m_bUserOverride;
291 
292         std::map< sal_Unicode, sal_Int32 >			m_aEncodingVector;
293         std::map< sal_Unicode, rtl::OString >		m_aNonEncoded;
294 
295         explicit PrintFont( fonttype::type eType );
296         virtual ~PrintFont();
297         virtual bool queryMetricPage( int nPage, utl::MultiAtomProvider* pProvider ) = 0;
298 
299         bool readAfmMetrics( const rtl::OString& rFileName, utl::MultiAtomProvider* pProvider, bool bFillEncodingvector, bool bOnlyGlobalAttributes );
300     };
301 
302     struct Type1FontFile : public PrintFont
303     {
304         int                 m_nDirectory;       // atom containing system dependent path
305         rtl::OString      m_aFontFile;        // relative to directory
306         rtl::OString      m_aMetricFile;      // dito
307         rtl::OString      m_aXLFD;            // mainly for administration, contains the XLFD from fonts.dir
308 
309         /* note: m_aFontFile and Metric file are not atoms
310            because they should be fairly unique */
311 
Type1FontFilepsp::PrintFontManager::Type1FontFile312         Type1FontFile() : PrintFont( fonttype::Type1 ), m_nDirectory( 0 ) {}
313         virtual ~Type1FontFile();
314         virtual bool queryMetricPage( int nPage, utl::MultiAtomProvider* pProvider );
315     };
316 
317     struct TrueTypeFontFile : public PrintFont
318     {
319         int					    m_nDirectory;       // atom containing system dependent path
320         rtl::OString          m_aFontFile;        // relative to directory
321         rtl::OString          m_aXLFD;            // mainly for administration, contains the XLFD from fonts.dir
322         int                     m_nCollectionEntry; // -1 for regular fonts, 0 to ... for fonts stemming from collections
323         unsigned int           m_nTypeFlags;		// copyright bits and PS-OpenType flag
324 
325         TrueTypeFontFile();
326         virtual ~TrueTypeFontFile();
327         virtual bool queryMetricPage( int nPage, utl::MultiAtomProvider* pProvider );
328     };
329 
330     struct BuiltinFont : public PrintFont
331     {
332         int                 m_nDirectory;       // atom containing system dependent path
333         rtl::OString      m_aMetricFile;
334 
BuiltinFontpsp::PrintFontManager::BuiltinFont335         BuiltinFont() : PrintFont( fonttype::Builtin ) {}
336         virtual ~BuiltinFont();
337         virtual bool queryMetricPage( int nPage, utl::MultiAtomProvider* pProvider );
338     };
339 
340     struct XLFDEntry
341     {
342         static const int MaskFoundry	= 1;
343         static const int MaskFamily		= 2;
344         static const int MaskAddStyle	= 4;
345         static const int MaskItalic		= 8;
346         static const int MaskWeight		= 16;
347         static const int MaskWidth		= 32;
348         static const int MaskPitch		= 64;
349         static const int MaskEncoding	= 128;
350 
351         int					nMask; // contains a bit set for every valid member
352 
353         rtl::OString		aFoundry;
354         rtl::OString		aFamily;
355         rtl::OString		aAddStyle;
356         italic::type		eItalic;
357         weight::type		eWeight;
358         width::type			eWidth;
359         pitch::type			ePitch;
360         rtl_TextEncoding	aEncoding;
361 
XLFDEntrypsp::PrintFontManager::XLFDEntry362         XLFDEntry() { nMask = 0; }
363 
364         bool operator<(const XLFDEntry& rRight) const;
365         bool operator==(const XLFDEntry& rRight) const;
366     };
367 
368     static rtl::OString s_aEmptyOString;
369 
370     fontID                                      m_nNextFontID;
371     std::hash_map< fontID, PrintFont* >       m_aFonts;
372     std::hash_map< int, family::type >        m_aFamilyTypes;
373     std::list< rtl::OUString >              m_aPrinterDrivers;
374     std::list< rtl::OString >               m_aFontDirectories;
375     std::list< int >							m_aPrivateFontDirectories;
376     std::map< struct XLFDEntry, std::list< struct XLFDEntry > >
377     m_aXLFD_Aliases;
378     utl::MultiAtomProvider*                   m_pAtoms;
379     // for speeding up findFontFileID
380     std::hash_map< rtl::OString, std::set< fontID >, rtl::OStringHash >
381     											m_aFontFileToFontID;
382 
383     std::hash_map< rtl::OString, int, rtl::OStringHash >
384     m_aDirToAtom;
385     std::hash_map< int, rtl::OString >     m_aAtomToDir;
386     int                                        m_nNextDirAtom;
387 
388     std::hash_multimap< rtl::OString, sal_Unicode, rtl::OStringHash >
389     	m_aAdobenameToUnicode;
390     std::hash_multimap< sal_Unicode, rtl::OString >
391     	m_aUnicodeToAdobename;
392     std::hash_multimap< sal_Unicode, sal_uInt8 >	m_aUnicodeToAdobecode;
393     std::hash_multimap< sal_uInt8, sal_Unicode >	m_aAdobecodeToUnicode;
394 
395     mutable FontCache*                                                        m_pFontCache;
396     bool m_bFontconfigSuccess;
397 
398     mutable std::vector< fontID >               m_aOverrideFonts;
399 
400     rtl::OString getAfmFile( PrintFont* pFont ) const;
401     rtl::OString getFontFile( PrintFont* pFont ) const;
402 
403     void getFontAttributesFromXLFD( PrintFont* pFont, const std::list< rtl::OString >& rXLFDs ) const;
404 
405     bool analyzeFontFile( int nDirID, const rtl::OString& rFileName, const std::list< rtl::OString >& rXLFDs, std::list< PrintFont* >& rNewFonts ) const;
406     rtl::OUString convertTrueTypeName( void* pNameRecord ) const; // actually a NameRecord* formt font subsetting code
407     void analyzeTrueTypeFamilyName( void* pTTFont, std::list< rtl::OUString >& rnames ) const; // actually a TrueTypeFont* from font subsetting code
408     bool analyzeTrueTypeFile( PrintFont* pFont ) const;
409     // finds the FIRST id for this font file; there may be more
410     // for TrueType collections
411     fontID findFontFileID( int nDirID, const rtl::OString& rFile ) const;
412     fontID findFontBuiltinID( int nPSNameAtom ) const;
413 
414     family::type matchFamilyName( const rtl::OUString& rFamily ) const;
415 
getFont(fontID nID) const416     PrintFont* getFont( fontID nID ) const
417     {
418         std::hash_map< fontID, PrintFont* >::const_iterator it;
419         it = m_aFonts.find( nID );
420         return it == m_aFonts.end() ? NULL : it->second;
421     }
422     rtl::OString getXLFD( PrintFont* pFont ) const;
423     void fillPrintFontInfo( PrintFont* pFont, FastPrintFontInfo& rInfo ) const;
424     void fillPrintFontInfo( PrintFont* pFont, PrintFontInfo& rInfo ) const;
425 
426     const rtl::OString& getDirectory( int nAtom ) const;
427     int getDirectoryAtom( const rtl::OString& rDirectory, bool bCreate = false );
428 
429     /* try to initialize fonts from libfontconfig
430 
431     called from <code>initialize()</code>
432 
433     @returns
434     true if at least one font was added by libfontconfig
435     false else (e.g. no libfontconfig found)
436     */
437     bool initFontconfig();
438     int  countFontconfigFonts( std::hash_map<rtl::OString, int, rtl::OStringHash>& o_rVisitedPaths );
439     /* deinitialize fontconfig
440      */
441     void deinitFontconfig();
442 
443     /* register an application specific font directory for libfontconfig
444 
445     since fontconfig is asked for font substitutes before OOo will check for font availability
446     and fontconfig will happily substitute fonts it doesn't know (e.g. "Arial Narrow" -> "DejaVu Sans Book"!)
447     it becomes necessary to tell the library about all the hidden font treasures
448 
449     @returns
450     true if libfontconfig accepted the directory
451     false else (e.g. no libfontconfig found)
452     */
453     bool addFontconfigDir(const rtl::OString& rDirectory);
454 
455     static bool parseXLFD( const rtl::OString& rXLFD, XLFDEntry& rEntry );
456     void parseXLFD_appendAliases( const std::list< rtl::OString >& rXLFDs, std::list< XLFDEntry >& rEntries ) const;
457     void initFontsAlias();
458 
459     bool readOverrideMetrics();
460 
461     PrintFontManager();
462     ~PrintFontManager();
463 public:
464     static PrintFontManager& get(); // one instance only
465 
466     int addFontFile( const rtl::OString& rFileName, int nFaceNum );
467 
468     void initialize();
469 
470     // returns the number of managed fonts
getFontCount() const471     int getFontCount() const { return m_aFonts.size(); }
472 
473     // caution: the getFontList* methods can change the font list on demand
474     // depending on the pParser argument. That is getFontCount() may
475     // return a larger value after getFontList()
476 
477     // returns the ids of all managed fonts. on pParser != NULL
478     // all fonttype::Builtin type fonts are not listed
479     // which do not occur in the PPD of pParser
480     void getFontList( std::list< fontID >& rFontIDs, const PPDParser* pParser = NULL, bool bUseOverrideMetrics = false );
481     // get the font list and detailed font info. see getFontList for pParser
482     void getFontListWithInfo( std::list< PrintFontInfo >& rFonts, const PPDParser* pParser = NULL, bool bUseOverrideMetrics = false );
483     // get the font list and fast font info. see getFontList for pParser
484     void getFontListWithFastInfo( std::list< FastPrintFontInfo >& rFonts, const PPDParser* pParser = NULL, bool bUseOverrideMetrics = false );
485 
486     // get font info for a specific font
487     bool getFontInfo( fontID nFontID, PrintFontInfo& rInfo ) const;
488     // get fast font info for a specific font
489     bool getFontFastInfo( fontID nFontID, FastPrintFontInfo& rInfo ) const;
490 
491     // routines to get font info in small pieces
492 
493     // get a specific fonts family name
494     const rtl::OUString& getFontFamily( fontID nFontID ) const;
495     // get a specific fonts PSName name
496     const rtl::OUString& getPSName( fontID nFontID ) const;
497 
498     // get a specific fonts style family
499     family::type getFontFamilyType( fontID nFontID ) const;
500 
501     // get a specific fonts family name aliases
502     void getFontFamilyAliases( fontID nFontID ) const;
503 
504     // get a specific fonts type
getFontType(fontID nFontID) const505     fonttype::type getFontType( fontID nFontID ) const
506     {
507         PrintFont* pFont = getFont( nFontID );
508         return pFont ? pFont->m_eType : fonttype::Unknown;
509     }
510 
511     // get a specific fonts italic type
getFontItalic(fontID nFontID) const512     italic::type getFontItalic( fontID nFontID ) const
513     {
514         PrintFont* pFont = getFont( nFontID );
515         return pFont ? pFont->m_eItalic : italic::Unknown;
516     }
517 
518     // get a specific fonts width type
getFontWidth(fontID nFontID) const519     width::type getFontWidth( fontID nFontID ) const
520     {
521         PrintFont* pFont = getFont( nFontID );
522         return pFont ? pFont->m_eWidth : width::Unknown;
523     }
524 
525     // get a specific fonts weight type
getFontWeight(fontID nFontID) const526     weight::type getFontWeight( fontID nFontID ) const
527     {
528         PrintFont* pFont = getFont( nFontID );
529         return pFont ? pFont->m_eWeight : weight::Unknown;
530     }
531 
532     // get a specific fonts pitch type
getFontPitch(fontID nFontID) const533     pitch::type getFontPitch( fontID nFontID ) const
534     {
535         PrintFont* pFont = getFont( nFontID );
536         return pFont ? pFont->m_ePitch : pitch::Unknown;
537     }
538 
539     // get a specific fonts encoding
getFontEncoding(fontID nFontID) const540     rtl_TextEncoding getFontEncoding( fontID nFontID ) const
541     {
542         PrintFont* pFont = getFont( nFontID );
543         return pFont ? pFont->m_aEncoding : RTL_TEXTENCODING_DONTKNOW;
544     }
545 
546     // should i only use font's builtin encoding ?
getUseOnlyFontEncoding(fontID nFontID) const547     bool getUseOnlyFontEncoding( fontID nFontID ) const
548     {
549         PrintFont* pFont = getFont( nFontID );
550         return pFont ? pFont->m_bFontEncodingOnly : false;
551     }
552 
553     // get a specific fonts system dependent filename
getFontFileSysPath(fontID nFontID) const554     rtl::OString getFontFileSysPath( fontID nFontID ) const
555     {
556         return getFontFile( getFont( nFontID ) );
557     }
558 
559     // get the ttc face number
560     int getFontFaceNumber( fontID nFontID ) const;
561 
562     // get a specific fonts global metrics
563     const CharacterMetric& getGlobalFontMetric( fontID nFontID, bool bHorizontal ) const;
564 
565     // get a specific fonts ascend
566     int getFontAscend( fontID nFontID ) const;
567 
568     // get a specific fonts descent
569     int getFontDescend( fontID nFontID ) const;
570 
571     // get a specific fonts leading
572     int getFontLeading( fontID nFontID ) const;
573 
574     // get a fonts glyph bounding box
575     bool getFontBoundingBox( fontID nFont, int& xMin, int& yMin, int& xMax, int& yMax );
576 
577     // info whether there are vertical substitutions
578     bool hasVerticalSubstitutions( fontID nFontID ) const;
579 
580     // info whether an array of glyphs has vertical substitutions
581     void hasVerticalSubstitutions( fontID nFontID, const sal_Unicode* pCharacters,
582         int nCharacters, bool* pHasSubst ) const;
583 
584     // get the XLFD for a font that originated from the X fontpath
585     // note: this may not be the original line that was in the fonts.dir
586     // returns a string for every font, but only TrueType and Type1
587     // fonts originated from the X font path, so check for the font type
588     rtl::OUString getFontXLFD( fontID nFontID ) const;
589 
590     // get a specific fonts metrics
591 
592     // get metrics for a sal_Unicode range
593     // the user is responsible to allocate pArray large enough
594     bool getMetrics( fontID nFontID, sal_Unicode minCharacter, sal_Unicode maxCharacter, CharacterMetric* pArray, bool bVertical = false ) const;
595     // get metrics for an array of sal_Unicode characters
596     // the user is responsible to allocate pArray large enough
597     bool getMetrics( fontID nFontID, const sal_Unicode* pString, int nLen, CharacterMetric* pArray, bool bVertical = false ) const;
598 
599     // get encoding vector of font, currently only for Type1 and Builtin fonts
600     // returns NULL if encoding vector is empty or font is neither type1 or
601     // builtin; if ppNonEncoded is set and non encoded type1 glyphs exist
602     // then *ppNonEncoded is set to the mapping for nonencoded glyphs.
603     // the encoding vector contains -1 for non encoded glyphs
604     const std::map< sal_Unicode, sal_Int32 >* getEncodingMap( fontID nFontID, const std::map< sal_Unicode, rtl::OString >** ppNonEncoded ) const;
605 
606     // to get font substitution transparently use the
607     // getKernPairs method of PrinterGfx
608     const std::list< KernPair >& getKernPairs( fontID nFontID, bool bVertical = false ) const;
609 
610     // evaluates copyright flags for TrueType fonts
611     // type1 fonts do not have such a feature, so return for them is true
612     // returns true for builtin fonts (surprise!)
613     bool isFontDownloadingAllowed( fontID nFont ) const;
614 
615     // helper for type 1 fonts
616     std::list< rtl::OString > getAdobeNameFromUnicode( sal_Unicode aChar ) const;
617 
618     std::pair< std::hash_multimap< sal_Unicode, sal_uInt8 >::const_iterator,
619                std::hash_multimap< sal_Unicode, sal_uInt8 >::const_iterator >
getAdobeCodeFromUnicode(sal_Unicode aChar) const620     getAdobeCodeFromUnicode( sal_Unicode aChar ) const
621     {
622         return m_aUnicodeToAdobecode.equal_range( aChar );
623     }
624     std::list< sal_Unicode >  getUnicodeFromAdobeName( const rtl::OString& rName ) const;
625     std::pair< std::hash_multimap< sal_uInt8, sal_Unicode >::const_iterator,
626                  std::hash_multimap< sal_uInt8, sal_Unicode >::const_iterator >
getUnicodeFromAdobeCode(sal_uInt8 aChar) const627     getUnicodeFromAdobeCode( sal_uInt8 aChar ) const
628     {
629         return m_aAdobecodeToUnicode.equal_range( aChar );
630     }
631 
632     // creates a new font subset of an existing TrueType font
633     // returns true in case of success, else false
634     // nFont: the font to be subsetted
635     // rOutFile: the file to put the new subset into;
636     //           must be a valid osl file URL
637     // pGlyphIDs: input array of glyph ids for new font
638     // pNewEncoding: the corresponding encoding in the new font
639     // pWidths: output array of widths of requested glyphs
640     // nGlyphs: number of glyphs in arrays
641     // pCapHeight:: capital height of the produced font
642     // pXMin, pYMin, pXMax, pYMax: outgoing font bounding box
643     // TODO: callers of this method should use its FontSubsetInfo counterpart directly
644     bool createFontSubset( FontSubsetInfo&,
645                            fontID nFont,
646                            const rtl::OUString& rOutFile,
647                            sal_GlyphId* pGlyphIds,
648                            sal_uInt8* pNewEncoding,
649                            sal_Int32* pWidths,
650                            int nGlyphs,
651                            bool bVertical = false
652                            );
653     void getGlyphWidths( fontID nFont,
654                          bool bVertical,
655                          std::vector< sal_Int32 >& rWidths,
656                          std::map< sal_Unicode, sal_uInt32 >& rUnicodeEnc );
657 
658 
659     // font administration functions
660 
661     // for importFonts to provide the user feedback
662     class ImportFontCallback
663     {
664     public:
665         enum FailCondition { NoWritableDirectory, NoAfmMetric, AfmCopyFailed, FontCopyFailed };
666         virtual void importFontsFailed( FailCondition eReason ) = 0;
667         virtual void progress( const rtl::OUString& rFile ) = 0;
668         virtual bool queryOverwriteFile( const rtl::OUString& rFile ) = 0;
669         virtual void importFontFailed( const rtl::OUString& rFile, FailCondition ) = 0;
670         virtual bool isCanceled() = 0;
671     };
672 
673     // checks whether font import would fail due to no writeable directory
674     bool checkImportPossible() const;
675     // expects system paths not UNC paths
676     // returns the number of fonts successfully imported
677     int importFonts( const std::list< rtl::OString >& rFiles, bool bLinkOnly = false, ImportFontCallback* pCallback = NULL );
678 
679     // check whether changeFontProperties would fail due to not writable fonts.dir
680     bool checkChangeFontPropertiesPossible( fontID nFont ) const;
681     // change fonts.dir entry for font
682     bool changeFontProperties( fontID nFont, const rtl::OUString& rXLFD );
683 
684     // get properties of a not imported font file
685     bool getImportableFontProperties( const rtl::OString& rFile, std::list< FastPrintFontInfo >& rFontProps );
686 
687     // get fonts that come from the same font file
688     bool getFileDuplicates( fontID nFont, std::list< fontID >& rFonts ) const;
689     // remove font files
690     bool removeFonts( const std::list< fontID >& rFonts );
691 
692     bool isPrivateFontFile( fontID ) const;
693 
694     // returns false if there were not any
695     bool getAlternativeFamilyNames( fontID nFont, std::list< rtl::OUString >& rNames ) const;
696 
697     /*  system dependendent font matching
698 
699     <p>
700     <code>matchFont</code> matches a pattern of font characteristics
701     and returns the closest match if possibe. If a match was found
702     the <code>FastPrintFontInfo</code> passed in as parameter
703     will be update to the found matching font.
704     </p>
705     <p>
706     implementation note: currently the function is only implemented
707     for fontconfig.
708     </p>
709 
710     @param rInfo
711     out of the FastPrintFontInfo structure the following
712     fields will be used for the match:
713     <ul>
714     <li>family name</li>
715     <li>italic</li>
716     <li>width</li>
717     <li>weight</li>
718     <li>pitch</li>
719     </ul>
720 
721     @param rLocale
722     if <code>rLocal</code> contains non empty strings the corresponding
723     locale will be used for font matching also; e.g. "Sans" can result
724     in different fonts in e.g. english and japanese
725 
726     @returns
727     true if a match was found
728     false else
729      */
730     bool matchFont( FastPrintFontInfo& rInfo, const com::sun::star::lang::Locale& rLocale );
731     bool getFontOptions( const FastPrintFontInfo&, int nSize, void (*subcallback)(void*), ImplFontOptions& rResult ) const;
732 
733     rtl::OUString Substitute( const rtl::OUString& rFontName, rtl::OUString& rMissingCodes,
734         const rtl::OString& rLangAttrib, italic::type& rItalic, weight::type& rWeight,
735         width::type& rWidth, pitch::type& rPitch) const;
hasFontconfig() const736     bool hasFontconfig() const { return m_bFontconfigSuccess; }
737 
738     int FreeTypeCharIndex( void *pFace, sal_uInt32 aChar );
739 };
740 
741 } // namespace
742 
743 #endif // _PSPRINT_FONTMANAGER_HXX_
744