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_NonCopyable.h>
22 #include <UT/UT_Set.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_StringMap.h>
25 #include <UT/UT_UniquePtr.h>
26 #include <UT/UT_ValArray.h>
27 
28 class UT_JSONParser;
29 class UT_JSONWriter;
30 class UT_JSONValueMap;
31 
32 struct font_CacheInfo;
34 
36 typedef struct FT_FaceRec_* FT_Face;
37 
38 
40 {
41 public:
42  ~FONT_Registry();
44 
45  /// Returns the FONT_Registry singleton.
46  static FONT_Registry &instance();
47 
48  /// Return a alphabetic list of all available typefaces.
49  UT_StringList typefaces() const;
50 
51  /// Returns all fonts from the given typeface.
52  const FONT_InfoPtrList &typefaceFonts(const char *typeface) const;
53 
54  /// Return a list of all font files that have been loaded.
55  /// If `include_system_font_files` is true then the returned list includes
56  /// font files that were loaded from system directories. Otherwise,
57  /// the returned list includes only font files found in the Houdini
58  /// search path.
59  UT_StringArray fontFilePaths(
60  bool include_system_font_files=true) const;
61 
62  /// Returns the closest variant on the given font with the additional
63  /// constraints.
64  /// \param font The font to base the variant on.
65  /// \param variant Specifies the variation upon the base font to return.
66  const FONT_Info &getVariant(
67  const FONT_Info &font_info,
68  FONT_Variant variant) const;
69 
70  /// Return a font face given an name. The name can be any of the possible
71  /// alternative names for a font. For example font names used in older
72  /// version of Houdini (e.g. "DejaVuSansMono-BoldOblique" would be the
73  /// "DejaVu Sans Mono" family, bold weight, oblique style), for factory
74  /// fonts. For system fonts, the path name would have been given.
75  /// If the font is not found, an invalid FONT_Info object is returned,
76  /// containing just the font name.
77  const FONT_Info &get(const char *name) const;
78 
79  /// Rebind the font.map aliases that have entries for the given lower case
80  /// language (e.g. "Proportional-CJK:ja" for "ja") to those entries.
81  ///
82  /// This changes what get() returns for those aliases, so call it during
83  /// application startup, before any fonts are looked up.
84  void setLanguage(const char *language);
85 
86  /// Returns a comma separated list of file globs that match the supported
87  /// extensions.
88  static const char *fileExtensionFilterString();
89 
90 private:
91  FONT_Registry();
92 
93  bool getInfoFromFontFile(const UT_StringHolder &font_path,
94  FONT_InfoPtrList &font_infos);
95 
96  void saveFontCache(UT_JSONWriter &j);
97  bool loadFontCache(UT_JSONParser &p,
98  font_CacheMap &cached_fonts);
99  static const FONT_Info *parseFontInfo(const UT_JSONValueMap *m,
100  const UT_StringHolder &font_path);
101  static bool parseFontsAndPath(UT_JSONParser &p,
102  font_CacheMap &cache);
103  void writeFontsForPath(UT_JSONWriter &j, const char *path,
104  const FONT_InfoPtrList &fl);
105  void init();
106  bool createFontInfosFromPath(
107  const UT_StringHolder &font_path);
108  void initTypefacesAndFontAliases();
109  void loadFontMap();
110 
111  void getCacheFilename(UT_String &filename) const;
112 
113  static bool parseType1Data(const FT_Face font_face,
114  FONT_Info &fi);
115  static bool parseTrueTypeData(const FT_Face font_face,
116  FONT_Info &fi);
117 
118  struct FontInfoPtrLess
119  {
120  bool operator()(const FONT_Info * const &a, const FONT_Info * const &b) const
121  {
122  return *a < *b;
123  }
124  };
125 
131 
132  FontSet myFonts;
133  FontAliasMap myFontAliases;
134  // Language (lower case) -> font.map alias -> font, for the "Alias:lang"
135  // entries.
136  UT_ArrayStringMap<FontAliasMap> myLanguageAliases;
137  TypefaceMap myTypefaceMap;
138  FontOverrides myFontOverrides;
139  UT_ArrayStringSet myBrokenFonts;
140  FT_Library myFTLib;
141 };
142 
143 #endif // __FONT_Registry__
UT_ArrayStringMap< font_CacheInfo > font_CacheMap
Definition: FONT_Registry.h:32
GT_API const UT_StringHolder filename
UT_JSONValueMap stores a map/dictionary of UT_JSONValue objects.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
struct FT_LibraryRec_ * FT_Library
Definition: FONT_Info.h:25
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define FONT_API
Definition: FONT_API.h:10
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:39
UT_Array< const FONT_Info * > FONT_InfoPtrList
Definition: FONT_Registry.h:35
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLuint const GLchar * name
Definition: glcorearb.h:786
FONT_Variant
Definition: FONT_Enums.h:19
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint j
Definition: glad.h:2733
struct FT_FaceRec_ * FT_Face
Definition: FONT_Registry.h:36