This file is indexed.

/usr/include/podofo/doc/PdfFontCache.h is in libpodofo-dev 0.9.0-1.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
/***************************************************************************
 *   Copyright (C) 2007 by Dominik Seichter                                *
 *   domseichter@web.de                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef _PDF_FONT_CACHE_H_
#define _PDF_FONT_CACHE_H_

#include "podofo/base/PdfDefines.h"
#include "podofo/base/Pdf3rdPtyForwardDecl.h"
#include "podofo/base/PdfEncoding.h"
#include "podofo/base/PdfEncodingFactory.h"
#include "podofo/base/util/PdfMutex.h"
#include "PdfFont.h"

namespace PoDoFo {

class PdfFontMetrics;
class PdfVecObjects;

/** A private structure,
 *  which represents a font in the cache.
 */
struct TFontCacheElement {
    TFontCacheElement() 
        : m_pFont( NULL ),
	  m_pEncoding( NULL ),
	  m_bBold( false ),
	  m_bItalic( false )
    {
    }

    TFontCacheElement( const char* pszFontName, bool bBold, bool bItalic, 
		               const PdfEncoding * const pEncoding )
        : m_pFont(NULL), m_pEncoding( pEncoding ), m_bBold( bBold ), 
          m_bItalic( bItalic ), m_sFontName( reinterpret_cast<const pdf_utf8*>(pszFontName) )
    {
    }

#ifdef _WIN32
    TFontCacheElement( const wchar_t* pszFontName, bool bBold, bool bItalic, 
		       const PdfEncoding * const pEncoding )
        : m_pFont(NULL), m_pEncoding( pEncoding ), m_bBold( bBold ), 
          m_bItalic( bItalic ), m_sFontName( pszFontName )
    {
    }
#endif // _WIN32

    TFontCacheElement( const TFontCacheElement & rhs ) 
    {
        this->operator=(rhs);
    }
    
    const TFontCacheElement & operator=( const TFontCacheElement & rhs ) 
    {
        m_pFont     = rhs.m_pFont;
        m_pEncoding = rhs.m_pEncoding;
        m_bBold     = rhs.m_bBold;
        m_bItalic   = rhs.m_bItalic;
        m_sFontName = rhs.m_sFontName;
        
        return *this;
    }
    
    bool operator<( const TFontCacheElement & rhs ) const
    {
        if( m_sFontName == rhs.m_sFontName ) 
        {
            if( m_pEncoding == NULL  ||  rhs.m_pEncoding == NULL  ||  *m_pEncoding == *rhs.m_pEncoding ) 
            {
                if( m_bBold == rhs.m_bBold) 
                    return m_bItalic < rhs.m_bItalic;
                else
                    return m_bBold < rhs.m_bBold;
            }
            else
                return *m_pEncoding < *rhs.m_pEncoding;
        }
        else
            return (m_sFontName < rhs.m_sFontName);
    }
    
    inline bool operator()( const TFontCacheElement& r1, 
			    const TFontCacheElement& r2 ) const 
    { 
        return r1 < r2;
    }

    PdfFont*           m_pFont;
    const PdfEncoding* m_pEncoding;
    bool               m_bBold;
    bool               m_bItalic;
    PdfString          m_sFontName; ///< We use PdfString here as it can easily handle unicode on windows
};

/**
 * This class assists PdfDocument
 * with caching font information.
 *
 * Additional to font caching, this class is also
 * responsible for font matching.
 *
 * PdfFont is an actual font that can be used in
 * a PDF file (i.e. it does also font embedding)
 * and PdfFontMetrics provides only metrics informations.
 *
 * This class is an internal class of PoDoFo
 * and should not be used in user applications
 *
 * \see PdfDocument
 */
class PODOFO_DOC_API PdfFontCache {
    typedef std::vector<TFontCacheElement>  TSortedFontList;
    typedef TSortedFontList::iterator       TISortedFontList;
    typedef TSortedFontList::const_iterator TCISortedFontList;

#if defined(PODOFO_HAVE_FONTCONFIG)
    static Util::PdfMutex m_FcMutex;
#endif

 public:

    /**
     * Flags to control font creation.
     */
    enum EFontCreationFlags {
        eFontCreationFlags_None = 0,				///< No special settings
        eFontCreationFlags_AutoSelectBase14 = 1,	///< Create automatically a base14 font if the fontname matches one of them
        eFontCreationFlags_Type1Subsetting = 2		///< Create subsetted type1-font, which includes only used characters
    };

    /** Create an empty font cache 
     *
     *  \param pParent a PdfVecObjects which is required
     *                 to create new font objects
     */
    PdfFontCache( PdfVecObjects* pParent );

    /** Destroy and empty the font cache
     */
    ~PdfFontCache();

    /** 
     * Empty the internal font cache.
     * This should be done when ever a new document
     * is created or openened.
     */
    void EmptyCache();

    /** Get a font from the cache. If the font does not yet
     *  exist, add it to the cache. This font is created
     *  from an existing object.
     *
     *  \param pObject a PdfObject that is a font
     *
     *  \returns a PdfFont object or NULL if the font could
     *           not be created or found.
     */
    PdfFont* GetFont( PdfObject* pObject );

    /** Get a font from the cache. If the font does not yet
     *  exist, add it to the cache.
     *
     *  \param pszFontName a valid fontname
     *  \param bBold if true search for a bold font
     *  \param bItalic if true search for an italic font
     *  \param bEmbedd if true a font for embedding into 
     *                 PDF will be created
     *  \param eFontCreationFlags special flag to specify how fonts should be created
     *  \param pEncoding the encoding of the font. The font will not take ownership of this object.     
     *  \param pszFileName optional path to a valid font file
     *
     *  \returns a PdfFont object or NULL if the font could
     *           not be created or found.
     */
    PdfFont* GetFont( const char* pszFontName, bool bBold, bool bItalic, 
                      bool bEmbedd, EFontCreationFlags eFontCreationFlags = eFontCreationFlags_AutoSelectBase14,
                      const PdfEncoding * const = PdfEncodingFactory::GlobalWinAnsiEncodingInstance(), 
                      const char* pszFileName = NULL );

#ifdef _WIN32
    /** Get a font from the cache. If the font does not yet
     *  exist, add it to the cache.
     *
     *  \param pszFontName a valid fontname
     *  \param bBold if true search for a bold font
     *  \param bItalic if true search for an italic font
     *  \param bEmbedd if true a font for embedding into 
     *                 PDF will be created
     *  \param pEncoding the encoding of the font. The font will not take ownership of this object.     
     *
     *  \returns a PdfFont object or NULL if the font could
     *           not be created or found.
 	 *
     *  This is an overloaded member function to allow working
     *  with unicode characters. On Unix systes you can also path
     *  UTF-8 to the const char* overload.
     */
    PdfFont* GetFont( const wchar_t* pszFontName, bool bBold, bool bItalic, 
                      bool bEmbedd, const PdfEncoding * const = PdfEncodingFactory::GlobalWinAnsiEncodingInstance() );
#endif // _WIN32

    /** Get a font from the cache. If the font does not yet
     *  exist, add it to the cache.
     *
     *  \param face a valid freetype font face (will be free'd by PoDoFo)
     *  \param bEmbedd if true a font for embedding into 
     *                 PDF will be created
     *  \param pEncoding the encoding of the font. The font will not take ownership of this object.     
     *
     *  \returns a PdfFont object or NULL if the font could
     *           not be created or found.
     */
    PdfFont* GetFont( FT_Face face, bool bEmbedd, const PdfEncoding * const = PdfEncodingFactory::GlobalWinAnsiEncodingInstance() );

    /** Get a font with specific id from the cache. If the font does not yet
     *  exist, copy from existing type1-font and set id.
     *
     *  \param pFont an existing font
     *  \param pszSuffix Suffix to add to font-id 
     *
     *  \returns a PdfFont object or NULL if the font could
     *           not be created or found.
     */
	PdfFont* GetDuplicateFontType1( PdfFont* pFont, const char* pszSuffix );

    /** Get a fontsubset from the cache. If the font does not yet
     *  exist, add it to the cache.
     *
     *  \param pszFontName a valid fontname
     *  \param bBold if true search for a bold font
     *  \param bItalic if true search for an italic font
     *  \param pEncoding the encoding of the font. All characters
     *                   of the encoding will be included in this subset.
     *                   The font will not take ownership of this object.     
     *  \param pszFileName optional path to a valid font file
     *
     *  \returns a PdfFont object or NULL if the font could
     *           not be created or found.
     */
    PdfFont* GetFontSubset( const char* pszFontName, bool bBold, bool bItalic, 
			    const PdfEncoding * const = PdfEncodingFactory::GlobalWinAnsiEncodingInstance(),
			    const char* pszFileName = NULL);

    /** Embeds all pending subset-fonts
     *
     */
	void EmbedSubsetFonts();

#if defined(PODOFO_HAVE_FONTCONFIG)
    /** Get the path of a font file on a Unix system using fontconfig
     *
     *  This method is only available if PoDoFo was compiled with
     *  fontconfig support.
     *
     *  \param pConfig a handle to an initialized fontconfig library
     *  \param pszFontName name of the requested font
     *  \param bBold if true find a bold font
     *  \param bItalic if true find an italic font
     *  \returns the path to the fontfile or an empty string
     */
    static std::string GetFontConfigFontPath( FcConfig* pConfig, const char* pszFontName, bool bBold, bool bItalic );
#endif // defined(PODOFO_HAVE_FONTCONFIG)

    // Peter Petrov: 26 April 2008
    /** Returns the font library from font cache
     *
     *  \returns the internal handle to the freetype library
     */
    inline FT_Library GetFontLibrary() const;

 private:
    /**
     * Get the path to a font file for a certain fontname
     *
     * \param pszFontName a valid fontname
     * \param bBold if true search for a bold font
     * \param bItalic if true search for an italic font
     *
     * \returns the path to the fonts file if it was found.
     */
    std::string GetFontPath( const char* pszFontName, bool bBold, bool bItalic );

    /** Create a font and put it into the fontcache
     *
     *  \param itSorted iterator pointing to a location in vecContainer
     *                  where a sorted insert can be made
     *  \param vecContainer container where the font object should be added
     *  \param pMetrics a font metrics
     *  \param bEmbedd if true the font will be embedded in the pdf file
     *  \param bBold if true this font will be treated as bold font
     *  \param bItalic if true this font will be treated as italic font
     *  \param pszFontName a font name for debug output
     *  \param pEncoding the encoding of the font. The font will not take ownership of this object.     
     *  \param bSubsetting if true the font will be subsetted in the pdf file
     *
     *  \returns a font handle or NULL in case of error
     */
    PdfFont* CreateFontObject( TISortedFontList itSorted, TSortedFontList & vecContainer,
                               PdfFontMetrics* pMetrics, bool bEmbedd, bool bBold, 
                               bool bItalic, const char* pszFontName, const PdfEncoding * const pEncoding,
							   bool bSubsetting = false );

    /** Create a font subset.
     *  \param pMetrics a font metrics
     *  \param pszFontName a font name for debug output
     *  \param bBold if true this font will be treated as bold font
     *  \param bItalic if true this font will be treated as italic font
     *  \param vecCharacters a list of Unicode character indeces that should be embedded in the subset
     *
     *  \returns a font handle or NULL in case of error
     */
    /*
    PdfFont* CreateFontSubset( PdfFontMetrics* pMetrics, const char* pszFontName, bool bBold, 
                               bool bItalic, const std::vector<int> & vecCharacters );
    */
#ifdef _WIN32
    /** Load and create a font with windows API calls
     *
     *  This method is only available on Windows systems.
     * 
     *  \param itSorted iterator pointing to a location in vecContainer
     *                  where a sorted insert can be made
     *  \param vecContainer container where the font object should be added
     *  \param pszFontName a fontname
     *  \param bBold if true search for a bold font
     *  \param bItalic if true search for an italic font
     *  \param bEmbedd if true embedd the font
     *  \param pEncoding the encoding of the font. The font will not take ownership of this object.     
     *
     *  \returns a font handle or NULL in case of error
     */
    PdfFont* GetWin32Font( TISortedFontList itSorted, TSortedFontList & vecContainer, const char* pszFontName, 
			               bool bBold, bool bItalic, bool bEmbedd, const PdfEncoding * const pEncoding );

    PdfFont* GetWin32Font( TISortedFontList itSorted, TSortedFontList & vecContainer, const wchar_t* pszFontName, 
			               bool bBold, bool bItalic, bool bEmbedd, const PdfEncoding * const pEncoding );
#endif // _WIN32

 private:
    TSortedFontList m_vecFonts;              ///< Sorted list of all fonts, currently in the cache
    TSortedFontList m_vecFontSubsets;
    FT_Library      m_ftLibrary;             ///< Handle to the freetype library

    void*           m_pFcConfig;             ///< Handle to fontconfig on unix systems

    PdfVecObjects*  m_pParent;               ///< Handle to parent for creating new fonts and objects
};

// Peter Petrov: 26 April 2008
// -----------------------------------------------------
// 
// -----------------------------------------------------
FT_Library PdfFontCache::GetFontLibrary() const
{
    return this->m_ftLibrary;
}

};

#endif /* _PDF_FONT_CACHE_H_ */