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  /// Returns a comma separated list of file globs that match the supported
80  /// extensions.
81  static const char *fileExtensionFilterString();
82 
83 private:
84  FONT_Registry();
85 
86  bool getInfoFromFontFile(const UT_StringHolder &font_path,
87  FONT_InfoPtrList &font_infos);
88 
89  void saveFontCache(UT_JSONWriter &j);
90  bool loadFontCache(UT_JSONParser &p,
91  font_CacheMap &cached_fonts);
92  static const FONT_Info *parseFontInfo(const UT_JSONValueMap *m,
93  const UT_StringHolder &font_path);
94  static bool parseFontsAndPath(UT_JSONParser &p,
95  font_CacheMap &cache);
96  void writeFontsForPath(UT_JSONWriter &j, const char *path,
97  const FONT_InfoPtrList &fl);
98  void init();
99  bool createFontInfosFromPath(
100  const UT_StringHolder &font_path);
101  void initTypefacesAndFontAliases();
102 
103  void getCacheFilename(UT_String &filename) const;
104 
105  static bool parseType1Data(const FT_Face font_face,
106  FONT_Info &fi);
107  static bool parseTrueTypeData(const FT_Face font_face,
108  FONT_Info &fi);
109 
110  struct FontInfoPtrLess
111  {
112  bool operator()(const FONT_Info * const &a, const FONT_Info * const &b) const
113  {
114  return *a < *b;
115  }
116  };
117 
123 
124  FontSet myFonts;
125  FontAliasMap myFontAliases;
126  TypefaceMap myTypefaceMap;
127  FontOverrides myFontOverrides;
128  UT_ArrayStringSet myBrokenFonts;
129  FT_Library myFTLib;
130 };
131 
132 #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:24
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:37
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.
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