1
///////////////////////////////////////////////////////////////////////////////
2
// Name: pdffontdatatype1.h
3
// Purpose: Definition of font data for Type1 fonts
4
// Author: Ulrich Telle
7
// Copyright: (c) Ulrich Telle
8
// Licence: wxWindows licence
9
///////////////////////////////////////////////////////////////////////////////
11
/// \file pdffontdatatype1.h Definition of font data for Type1 fonts
13
#ifndef _PDF_FONT_DATA_TYPE1_H_
14
#define _PDF_FONT_DATA_TYPE1_H_
17
#include <wx/strconv.h>
18
#include <wx/stream.h>
19
#include <wx/string.h>
20
#include <wx/xml/xml.h>
22
// wxPdfDocument headers
23
#include "wx/pdfdocdef.h"
24
#include "wx/pdfarraytypes.h"
25
#include "wx/pdffontdata.h"
27
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxUint16, wxPdfFontType1GlyphWidthMap, class WXDLLIMPEXP_PDFDOC);
29
/// Class representing Type 1 fonts. (For internal use only)
30
class WXDLLIMPEXP_PDFDOC wxPdfFontDataType1 : public wxPdfFontData
33
///< Default constructor
34
wxPdfFontDataType1(wxMemoryInputStream* pfbStream = NULL);
36
/// Default destructor
37
virtual ~wxPdfFontDataType1();
39
/// Get the width of a string
41
* \param s the string for which the width should be calculated
42
* \param encoding the character to glyph mapping
43
* \param withKerning flag indicating whether kerning should be taken into account
44
* \return the width of the string
46
virtual double GetStringWidth(const wxString& s, const wxPdfEncoding* encoding = NULL, bool withKerning = false) const;
48
/// Check whether the font oan show all characters of a given string
50
* \param s the string to be checked
51
* \param encoding the character to glyph mapping
52
* \return TRUE if the font can show all characters of the string, FALSE otherwise
54
virtual bool CanShow(const wxString& s, const wxPdfEncoding* encoding = NULL) const;
56
/// Convert character codes to glyph numbers
58
* \param s the string to be converted
59
* \param encoding the character to glyph mapping
60
* \param usedGlyphs the list of used glyphs
61
* \param subsetGlyphs the mapping of glyphs to subset glyphs
62
* \return the converted string
64
virtual wxString ConvertCID2GID(const wxString& s, const wxPdfEncoding* encoding,
65
wxPdfSortedArrayInt* usedGlyphs = NULL,
66
wxPdfChar2GlyphMap* subsetGlyphs = NULL) const;
68
/// Load the font metrics XML file
70
* \param root the root node of the XML font metric file
71
* \return TRUE if the metric file could be processed successfully, FALSE otherwise
73
virtual bool LoadFontMetrics(wxXmlNode* root);
75
/// Initialize font data
77
* \return TRUE if the font data has been initialized successfully, FALSE otherwise
79
virtual bool Initialize();
81
/// Get the character width array as string
83
* \param subset flag whether subsetting is enabled
84
* \param usedGlyphs the list of used glyphs
85
* \param subsetGlyphs the mapping of glyphs to subset glyphs
86
* \return the string representation of the character widths
88
virtual wxString GetWidthsAsString(bool subset = false, wxPdfSortedArrayInt* usedGlyphs = NULL, wxPdfChar2GlyphMap* subsetGlyphs = NULL) const;
91
/// Get the character width array as string
93
* \param glyphNames the list of glyph names available in the font
94
* \param subset flag whether subsetting is enabled
95
* \param usedGlyphs the list of used glyphs
96
* \param subsetGlyphs the mapping of glyphs to subset glyphs
97
* \return the string representation of the character widths
99
virtual wxString GetWidthsAsString(const wxArrayString& glyphNames, bool subset = false, wxPdfSortedArrayInt* usedGlyphs = NULL, wxPdfChar2GlyphMap* subsetGlyphs = NULL) const;
101
/// Get a list of glyph names available in the font
103
* \param[out] glyphNames the list of glyph names
104
* \return TRUE if the glyph names are available, FALSE otherwise
106
virtual bool GetGlyphNames(wxArrayString& glyphNames) const;
111
* \param fontData the output stream
112
* \param usedGlyphs the list of used glyphs
113
* \param subsetGlyphs the mapping of glyphs to subset glyphs
114
* \return the size of the written font data
116
virtual size_t WriteFontData(wxOutputStream* fontData,
117
wxPdfSortedArrayInt* usedGlyphs = NULL,
118
wxPdfChar2GlyphMap* subsetGlyphs = NULL);
120
/// Write character/glyph to unicode mapping
122
* \param mapData the output stream
123
* \param encoding the character to glyph mapping
124
* \param usedGlyphs the list of used glyphs
125
* \param subsetGlyphs the mapping of glyphs to subset glyphs
126
* \return the size of the written data
128
virtual size_t WriteUnicodeMap(wxOutputStream* mapData,
129
const wxPdfEncoding* encoding = NULL,
130
wxPdfSortedArrayInt* usedGlyphs = NULL,
131
wxPdfChar2GlyphMap* subsetGlyphs = NULL);
134
/// Set the encoding type
136
* \param encodingType the encoding type
138
void SetEncodingType(const wxString& encodingType) { m_encodingType = encodingType; }
140
/// Get the encoding type
142
* \return the encoding type
144
wxString GetEncodingType() const { return m_encodingType; }
148
* \param encodingMap the encoding map
150
void SetEncodingMap(const wxArrayString& encodingMap) { m_encodingMap = encodingMap; }
154
* \return the encoding map
156
wxArrayString GetEncodingMap() const { return m_encodingMap; }
158
/// Set glyph width map
160
* \param glyphWidthMap the map of glyph widths
162
void SetType1GlyphWidthMap(wxPdfFontType1GlyphWidthMap* glyphWidthMap) { m_glyphWidthMap = glyphWidthMap; }
164
/// Get the associated encoding converter
166
* \return the encoding converter associated with this font
168
virtual wxMBConv* GetEncodingConv() const { return m_conv; }
170
/// Create the associated default encoding converter
171
virtual void CreateDefaultEncodingConv();
175
/// Compress the font data
176
bool CompressFontData(wxOutputStream* fontData, wxInputStream* pfbFile);
179
wxString m_encodingType; ///< encoding type
180
wxArrayString m_encodingMap; ///< encoding map
181
wxArrayString m_glyphNames; ///< list of glyph names
182
wxPdfFontType1GlyphWidthMap* m_glyphWidthMap; ///< mapping of glyph widths
185
wxMemoryInputStream* m_pfbStream; ///< Font stream in PFB format
186
wxMBConv* m_conv; ///< Associated encoding converter