HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FONT_Registry.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: FONT_Registry.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __FONT_Registry__
12 #define __FONT_Registry__
13 
14 #include "FONT_API.h"
15 
16 #include "FONT_Enums.h"
17 #include "FONT_Info.h"
18 
19 #include <UT/UT_UniquePtr.h>
20 #include <UT/UT_Set.h>
21 #include <UT/UT_StringHolder.h>
22 #include <UT/UT_StringMap.h>
23 #include <UT/UT_StringSet.h>
24 #include <UT/UT_ValArray.h>
25 
26 class UT_JSONParser;
27 class UT_JSONWriter;
29 
31 typedef struct FT_FaceRec_* FT_Face;
32 
33 
35 {
36 public:
37  ~FONT_Registry();
38 
39  /// Returns the FONT_Registry singleton.
40  static FONT_Registry &instance();
41 
42  /// Return a alphabetic list of all available typefaces.
43  UT_StringList typefaces() const;
44 
45  /// Returns all fonts from the given typeface.
46  const FONT_InfoPtrList &typefaceFonts(const char *typeface) const;
47 
48  /// Return a list of all font files that have been loaded.
49  UT_StringArray fontFilePaths() const;
50 
51  /// Returns the closest variant on the given font with the additional
52  /// constraints.
53  /// \param font The font to base the variant on.
54  /// \param variant Specifies the variation upon the base font to return.
55  const FONT_Info &getVariant(
56  const FONT_Info &font_info,
57  FONT_Variant variant) const;
58 
59  /// Return a font face given an name. The name can be any of the possible
60  /// alternative names for a font. For example font names used in older
61  /// version of Houdini (e.g. "DejaVuSansMono-BoldOblique" would be the
62  /// "DejaVu Sans Mono" family, bold weight, oblique style), for factory
63  /// fonts. For system fonts, the path name would have been given.
64  /// If the font is not found, an invalid FONT_Info object is returned,
65  /// containing just the font name.
66  const FONT_Info &get(const char *name) const;
67 
68  /// Returns a comma separated list of file globs that match the supported
69  /// extensions.
70  static const char *fileExtensionFilterString();
71 
72 private:
73  FONT_Registry();
74 
75  struct font_CacheInfo
76  {
77  font_CacheInfo() : mtime(-1) {}
78  time_t mtime;
79  UT_StringSet overrides;
81  };
83 
84  bool getInfoFromFontFile(const char *font_path,
85  FONT_InfoPtrList &font_infos);
86 
87  void saveFontCache(UT_JSONWriter &j);
88  bool loadFontCache(UT_JSONParser &p,
89  FontCacheMap &cached_fonts);
90  static const FONT_Info *parseFontInfo(const UT_JSONValueMap *m,
91  const char *font_path);
92  static bool parseFontsAndPath(UT_JSONParser &p,
93  FontCacheMap &cache);
94  void writeFontsForPath(UT_JSONWriter &j, const char *path,
95  const FONT_InfoPtrList &fl);
96  void init();
97  bool createFontInfosFromPath(const char *font_path);
98  void initTypefacesAndFontAliases();
99 
100  void getCacheFilename(UT_String &filename) const;
101 
102  static bool parseType1Data(const FT_Face font_face,
103  FONT_Info &fi);
104  static bool parseTrueTypeData(const FT_Face font_face,
105  FONT_Info &fi);
106 
107  struct FontInfoPtrLess
108  {
109  bool operator()(const FONT_Info * const &a, const FONT_Info * const &b) const
110  {
111  return *a < *b;
112  }
113  };
114 
120 
121  FontSet myFonts;
122  FontAliasMap myFontAliases;
123  TypefaceMap myTypefaceMap;
124  FontOverrides myFontOverrides;
125  UT_StringSet myBrokenFonts;
126  FT_Library myFTLib;
127 };
128 
129 #endif // __FONT_Registry__
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
struct FT_LibraryRec_ * FT_Library
Definition: FONT_Info.h:24
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define FONT_API
Definition: FONT_API.h:10
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
UT_Array< const FONT_Info * > FONT_InfoPtrList
Definition: FONT_Registry.h:28
GLuint const GLchar * name
Definition: glcorearb.h:785
FONT_Variant
Definition: FONT_Enums.h:19
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
struct FT_FaceRec_ * FT_Face
Definition: FONT_Registry.h:31