HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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_ArrayStringMap.h>
20 #include <UT/UT_ArrayStringSet.h>
21 #include <UT/UT_Set.h>
22 #include <UT/UT_StringHolder.h>
23 #include <UT/UT_StringMap.h>
24 #include <UT/UT_UniquePtr.h>
25 #include <UT/UT_ValArray.h>
26 
27 class UT_JSONParser;
28 class UT_JSONWriter;
29 class UT_JSONValueMap;
30 
31 struct font_CacheInfo;
33 
35 typedef struct FT_FaceRec_* FT_Face;
36 
37 
39 {
40 public:
41  ~FONT_Registry();
42 
43  /// Returns the FONT_Registry singleton.
44  static FONT_Registry &instance();
45 
46  /// Return a alphabetic list of all available typefaces.
47  UT_StringList typefaces() const;
48 
49  /// Returns all fonts from the given typeface.
50  const FONT_InfoPtrList &typefaceFonts(const char *typeface) const;
51 
52  /// Return a list of all font files that have been loaded.
53  /// If `include_system_font_files` is true then the returned list includes
54  /// font files that were loaded from system directories. Otherwise,
55  /// the returned list includes only font files found in the Houdini
56  /// search path.
57  UT_StringArray fontFilePaths(
58  bool include_system_font_files=true) const;
59 
60  /// Returns the closest variant on the given font with the additional
61  /// constraints.
62  /// \param font The font to base the variant on.
63  /// \param variant Specifies the variation upon the base font to return.
64  const FONT_Info &getVariant(
65  const FONT_Info &font_info,
66  FONT_Variant variant) const;
67 
68  /// Return a font face given an name. The name can be any of the possible
69  /// alternative names for a font. For example font names used in older
70  /// version of Houdini (e.g. "DejaVuSansMono-BoldOblique" would be the
71  /// "DejaVu Sans Mono" family, bold weight, oblique style), for factory
72  /// fonts. For system fonts, the path name would have been given.
73  /// If the font is not found, an invalid FONT_Info object is returned,
74  /// containing just the font name.
75  const FONT_Info &get(const char *name) const;
76 
77  /// Returns a comma separated list of file globs that match the supported
78  /// extensions.
79  static const char *fileExtensionFilterString();
80 
81 private:
82  FONT_Registry();
83 
84  bool getInfoFromFontFile(const UT_StringHolder &font_path,
85  FONT_InfoPtrList &font_infos);
86 
87  void saveFontCache(UT_JSONWriter &j);
88  bool loadFontCache(UT_JSONParser &p,
89  font_CacheMap &cached_fonts);
90  static const FONT_Info *parseFontInfo(const UT_JSONValueMap *m,
91  const UT_StringHolder &font_path);
92  static bool parseFontsAndPath(UT_JSONParser &p,
93  font_CacheMap &cache);
94  void writeFontsForPath(UT_JSONWriter &j, const char *path,
95  const FONT_InfoPtrList &fl);
96  void init();
97  bool createFontInfosFromPath(
98  const UT_StringHolder &font_path);
99  void initTypefacesAndFontAliases();
100 
101  void getCacheFilename(UT_String &filename) const;
102 
103  static bool parseType1Data(const FT_Face font_face,
104  FONT_Info &fi);
105  static bool parseTrueTypeData(const FT_Face font_face,
106  FONT_Info &fi);
107 
108  struct FontInfoPtrLess
109  {
110  bool operator()(const FONT_Info * const &a, const FONT_Info * const &b) const
111  {
112  return *a < *b;
113  }
114  };
115 
121 
122  FontSet myFonts;
123  FontAliasMap myFontAliases;
124  TypefaceMap myTypefaceMap;
125  FontOverrides myFontOverrides;
126  UT_ArrayStringSet myBrokenFonts;
127  FT_Library myFTLib;
128 };
129 
130 #endif // __FONT_Registry__
UT_ArrayStringMap< font_CacheInfo > font_CacheMap
Definition: FONT_Registry.h:31
GT_API const UT_StringHolder filename
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:75
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
UT_Array< const FONT_Info * > FONT_InfoPtrList
Definition: FONT_Registry.h:34
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:35
WARNING: This class DOES NOT ALLOW EMPTY STRING as a key!