FONTAINE  1.0
FontFace.h
Go to the documentation of this file.
00001 //
00002 // The Fontaine Font Analysis Project 
00003 // 
00004 // Copyright (c) 2009 by Edward H. Trager
00005 // All Rights Reserved
00006 // 
00007 // Released under the GNU GPL version 2.0 or later.
00008 //     
00009 
00010 
00011 #ifndef FONTFACE_INCLUDED
00012 #define FONTFACE_INCLUDED
00013 
00014 #include <string>
00015 #include <set>
00016 #include <vector>
00017 
00018 #include <ft2build.h>  
00019 #include FT_FREETYPE_H
00020 #include FT_SFNT_NAMES_H
00021 
00022 #include "Utf8String.h"
00023 #include "FontLibrary.h"
00024 #include "OrthographyResults.h"
00025 #include "LicenseData.h"
00026 
00027 //
00028 // Needed by the non-const fillReport() method:
00029 //
00030 #include "MLR.h"
00031 
00032 //
00033 // This class contains information
00034 // about a single font file:
00035 // 
00036 class FontFace{
00037         
00038 public:
00039         
00040         //
00041         // FontFaces are distinguished uniquely by 
00042         // using commonName + subFamily as the key:
00043         // 
00044         struct compare{
00045                 bool operator()(const FontFace *f1,const FontFace *f2) const{
00046                         std::string t1, t2;
00047                         t1 =  f1->_commonName;
00048                         t1 += f1->_subFamily ;
00049                         t2 =  f2->_commonName;
00050                         t2 += f2->_subFamily ;
00051                         return t1 < t2;
00052                 }
00053         };
00054         
00055         //
00056         // The following enums generally follow the W3C CSS Standard (http://www.w3.org/TR/REC-CSS1):
00057         //
00058         enum FAMILY  { SERIF, SANS, CURSIVE, FANTASY, MONOSPACE };
00059         enum STYLE   { NORMAL, ITALIC, OBLIQUE };
00060         enum VARIANT { NORMAL_VARIANT, SMALL_CAPS };
00061         // 
00062         enum WEIGHT  { NORMAL_WEIGHT, BOLD, W100, W200, W300, W400, W500, W600, W700, W800, W900 };
00063         //
00064         // As the common labels "serif" and "sans" are primarily applicable in typography in the
00065         // Western world, the following enum provides a generalization that is applicable across
00066         // all scripts:
00067         // 
00068         enum STROKE { UNMODULATED, SEMIMODULATED, MODULATED };
00069         
00070         enum NAMEID { 
00071                 NID_COPYRIGHT   =0, 
00072                 NID_FONT_FAMILY =1,
00073                 NID_FONT_SUBFAM =2,
00074                 NID_UNIQUE_ID   =3,
00075                 NID_FULL_NAME   =4,
00076                 NID_VERSION     =5,
00077                 NID_POSTSCRIPT  =6,
00078                 NID_TRADEMARK   =7,
00079                 NID_VENDOR      =8,
00080                 NID_DESIGNER    =9,
00081                 NID_DESCRIPTION =10,
00082                 NID_URL_VENDOR  =11,
00083                 NID_URL_DESIGNER=12,
00084                 NID_LICENSE     =13,
00085                 NID_URL_LICENSE =14,
00086                 NID_RESERVED    =15,
00087                 NID_PREF_NAME   =16,
00088                 NID_PREF_SUBFAM =17,
00089                 NID_MAC_FULLNAME=18,
00090                 NID_SAMPLETEXT  =19,
00091                 NID_FINDFONT_NM =20,
00092         };
00093         
00094 private:
00095         
00096         FT_Face _face;
00097         
00098         std::string _fileName;
00099         std::string _commonName; // The English or common Font Family name. e.g. "HanWangKaiMediumPoIn1"
00100         std::string _nativeName; // The native Font Family name, e.g. "漢宗中楷體破音一"
00101         std::string _subFamily;  // As given in the English or common subFamily record.
00102         
00103         std::string _copyright; 
00104         
00105         std::string _licenseURL; // 2009.07.16.ET addendum
00106         
00107         // 2011.04.18.ET addenda:
00108         std::string _version;
00109         std::string _vendor;
00110         std::string _designer;
00111         std::string _vendorURL;
00112         std::string _designerURL;
00113         
00114         unsigned _glyphCount;    // Number of glyphs
00115         
00116         FAMILY  _genericFamily;
00117         STYLE   _style;
00118         VARIANT _variant;
00119         WEIGHT  _weight;
00120         STROKE  _stroke;
00121         
00122         //
00123         // Supported Orthographies
00124         //
00125         std::vector< const OrthographyResults * > _supportedOrthographies;
00126         
00127         //
00128         // License:
00129         //
00130         const LicenseData *_licenseData;
00131         
00132         bool _hasVerticalMetrics;
00133         bool _isFixedWidth;
00134         bool _hasFixedSizes;
00135         
00136         std::set<UTF32> _unicodeValues;
00137         
00138         UTF8String _getPlatform3Encoding1String( unsigned length, const FT_Byte *string) const;
00139         UTF8String _getPlatform1Encoding0String( unsigned length, const FT_Byte *string) const;
00140         UTF8String _getStringFromTrueTypeFont(FT_SfntName &fontName) const;
00141         
00142         unsigned int _getUnicodeValues(void);
00143         
00144         //
00145         // Reporting option state flags:
00146         //
00147         bool _reportMissing;
00148         bool _reportFragmentary;
00149         bool _reportPartial;
00150         bool _reportFull;
00151         
00152 public:
00153         
00154         //
00155         // Constructor:
00156         //
00157         FontFace( FontLibrary &library, const std::string &fileName );
00158         
00159         //
00160         // Destructor:
00161         //
00162         ~FontFace();
00163         
00164         //
00165         // hasUnicodeValue()
00166         //
00167         bool hasUnicodeValue(UTF32) const;
00168         
00169         //
00170         // getters for reports:
00171         //
00172         std::string getBasicReport(void) const;
00173         std::string getOrthographyReport(void) const;
00174         
00175         //
00176         // Reporting options:
00177         //
00178         void setReportOnMissing(bool x);
00179         void setReportOnFragmentary(bool x);
00180         void setReportOnPartial(bool x);
00181         void setReportOnFull(bool x);
00182         
00183 private:
00184         
00185         bool _checkOrthography( const OrthographyData *pData );
00186         void _checkOrthographies(void);
00187         
00188         bool _checkLicense( const std::string &test, const LicenseData *pData);
00189         bool _checkAllKnownLicenses( const std::string &licenseString);
00190         void _storeCopyrightSummary(const std::string &copyrightString);
00191         void _checkLicenses(void);
00192         
00193 public:
00194         
00195         //
00196         // getters:
00197         //
00198         const std::string & getFileName(void) const;
00199         const std::string & getCommonName(void) const;
00200         const std::string & getNativeName(void) const;
00201         const std::string & getSubFamily(void) const;
00202         
00203         std::string getLicenseReport(void) const;
00204         const std::string & getCopyright(void) const;
00205         
00206         unsigned getGlyphCount(void) const;
00207         unsigned getCharacterCount(void) const;
00208         FAMILY  getFamily(void)  const;
00209         STYLE   getStyle(void)   const;
00210         VARIANT getVariant(void) const;
00211         WEIGHT  getWeight(void)  const;
00212         STROKE  getStroke(void)  const;
00213         bool    hasVerticalMetrics(void) const;
00214         bool    isFixedWidth(void) const;
00215         bool    hasFixedSizes(void) const;
00216         
00217         //
00218         // Pass in a report object, mlr, 
00219         // and fill in the report:
00220         //
00221         void fillReport(MLR *mlr);
00222         
00223 };
00224 
00225 #endif