FONTAINE  1.0
FontFace.h
Go to the documentation of this file.
1 //
2 // The Fontaine Font Analysis Project
3 //
4 // Copyright (c) 2009 by Edward H. Trager
5 // All Rights Reserved
6 //
7 // Released under the GNU GPL version 2.0 or later.
8 //
9 
10 
11 #ifndef FONTFACE_INCLUDED
12 #define FONTFACE_INCLUDED
13 
14 #include <string>
15 #include <set>
16 #include <vector>
17 
18 #include <ft2build.h>
19 #include FT_FREETYPE_H
20 #include FT_SFNT_NAMES_H
21 
22 #include "Utf8String.h"
23 #include "FontLibrary.h"
24 #include "OrthographyResults.h"
25 #include "LicenseData.h"
26 
27 //
28 // Needed by the non-const fillReport() method:
29 //
30 #include "MLR.h"
31 
32 //
33 // This class contains information
34 // about a single font file:
35 //
36 class FontFace{
37 
38 public:
39 
40  //
41  // FontFaces are distinguished uniquely by
42  // using commonName + subFamily as the key:
43  //
44  struct compare{
45  bool operator()(const FontFace *f1,const FontFace *f2) const{
46  std::string t1, t2;
47  t1 = f1->_commonName;
48  t1 += f1->_subFamily ;
49  t2 = f2->_commonName;
50  t2 += f2->_subFamily ;
51  return t1 < t2;
52  }
53  };
54 
55  //
56  // The following enums generally follow the W3C CSS Standard (http://www.w3.org/TR/REC-CSS1):
57  //
59  enum STYLE { NORMAL, ITALIC, OBLIQUE };
61  //
63  //
64  // As the common labels "serif" and "sans" are primarily applicable in typography in the
65  // Western world, the following enum provides a generalization that is applicable across
66  // all scripts:
67  //
69 
70  enum NAMEID {
92  };
93 
94 private:
95 
96  FT_Face _face;
97 
98  std::string _fileName;
99  std::string _commonName; // The English or common Font Family name. e.g. "HanWangKaiMediumPoIn1"
100  std::string _nativeName; // The native Font Family name, e.g. "漢宗中楷體破音一"
101  std::string _subFamily; // As given in the English or common subFamily record.
102 
103  std::string _copyright;
104 
105  std::string _licenseURL; // 2009.07.16.ET addendum
106 
107  // 2011.04.18.ET addenda:
108  std::string _version;
109  std::string _vendor;
110  std::string _designer;
111  std::string _vendorURL;
112  std::string _designerURL;
113 
114  unsigned _glyphCount; // Number of glyphs
115 
121 
122  //
123  // Supported Orthographies
124  //
125  std::vector< const OrthographyResults * > _supportedOrthographies;
126 
127  //
128  // License:
129  //
131 
135 
136  std::set<UTF32> _unicodeValues;
137 
138  UTF8String _getPlatform3Encoding1String( unsigned length, const FT_Byte *string) const;
139  UTF8String _getPlatform1Encoding0String( unsigned length, const FT_Byte *string) const;
140  UTF8String _getStringFromTrueTypeFont(FT_SfntName &fontName) const;
141 
142  unsigned int _getUnicodeValues(void);
143 
144  //
145  // Reporting option state flags:
146  //
151 
152 public:
153 
154  //
155  // Constructor:
156  //
157  FontFace( FontLibrary &library, const std::string &fileName );
158 
159  //
160  // Destructor:
161  //
162  ~FontFace();
163 
164  //
165  // hasUnicodeValue()
166  //
167  bool hasUnicodeValue(UTF32) const;
168 
169  //
170  // getters for reports:
171  //
172  std::string getBasicReport(void) const;
173  std::string getOrthographyReport(void) const;
174 
175  //
176  // Reporting options:
177  //
178  void setReportOnMissing(bool x);
179  void setReportOnFragmentary(bool x);
180  void setReportOnPartial(bool x);
181  void setReportOnFull(bool x);
182 
183 private:
184 
185  bool _checkOrthography( const OrthographyData *pData );
186  void _checkOrthographies(void);
187 
188  bool _checkLicense( const std::string &test, const LicenseData *pData);
189  bool _checkAllKnownLicenses( const std::string &licenseString);
190  void _storeCopyrightSummary(const std::string &copyrightString);
191  void _checkLicenses(void);
192 
193 public:
194 
195  //
196  // getters:
197  //
198  const std::string & getFileName(void) const;
199  const std::string & getCommonName(void) const;
200  const std::string & getNativeName(void) const;
201  const std::string & getSubFamily(void) const;
202 
203  std::string getLicenseReport(void) const;
204  const std::string & getCopyright(void) const;
205 
206  unsigned getGlyphCount(void) const;
207  unsigned getCharacterCount(void) const;
208  FAMILY getFamily(void) const;
209  STYLE getStyle(void) const;
210  VARIANT getVariant(void) const;
211  WEIGHT getWeight(void) const;
212  STROKE getStroke(void) const;
213  bool hasVerticalMetrics(void) const;
214  bool isFixedWidth(void) const;
215  bool hasFixedSizes(void) const;
216 
217  //
218  // Pass in a report object, mlr,
219  // and fill in the report:
220  //
221  void fillReport(MLR *mlr);
222 
223 };
224 
225 #endif