HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FONT_Info.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_Info.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __FONT_Info__
12 #define __FONT_Info__
13 
14 #include "FONT_API.h"
15 
16 #include "FONT_Enums.h"
17 
18 #include <UT/UT_Array.h>
19 #include <UT/UT_StringHolder.h>
20 #include <SYS/SYS_Inline.h>
21 #include <iosfwd>
22 
23 class UT_WorkBuffer;
24 struct FT_LibraryRec_;
25 typedef struct FT_LibraryRec_ *FT_Library;
26 
27 class FONT_Info
28 {
29 public:
30  inline bool isValid() const { return myIsValid; }
31 
32  /// The typeface (font family) of the font. E.g. 'Helvetica'
34  const UT_StringHolder &typeface() const { return myTypeface; }
35 
36  /// The full name of the font, including style and weight.
37  /// E.g. 'Helvetica Bold Oblique'
39  const UT_StringHolder &name() const { return myName; }
40 
41  /// A bitmap of the styles of the face. See FONT_Style for possible
42  /// bits.
43  FONT_Style style() const { return myStyle; }
44 
45  /// Returns \c true if the font has the specific style flag set.
46  bool hasStyle(FONT_Style style) const
47  { return (myStyle & style) == style; }
48 
49  /// Returns true if the font is italic or oblique.
50  bool isSlanted() const
51  { return hasStyle(FONT_STYLE_ITALIC) ||
53 
54  /// Returns true if the font is bolded in some way.
55  bool isBolded() const
56  { return int(myWeight) >= int(FONT_WEIGHT_DEMIBOLD); }
57 
58  /// The weight of the font.
59  FONT_Weight weight() const { return myWeight; }
60 
61  /// Returns the filename of the font. Can be either a TrueType,
62  /// OpenType, or Adobe Type-1 font.
63  inline const char *path() const { return myPath; }
64 
65  /// Returns the index of the face in the font file. This is used for
66  /// TrueType and OpenType font collection files to select the correct face
67  /// from within the file.
68  inline int faceIndex() const { return myFaceIndex; }
69 
70  /// Returns the font style name given an FONT_Style bitmap value.
72 
73  /// Attempts to parse a font's style name into the style bit field.
74  static bool parseStyleName(const char *name, FONT_Style &style);
75 
76  /// Returns the a weight name closest to the weight value given. The
77  /// value is clamped. See FONT_Weight for the known, named values.
78  static const char *weightName(FONT_Weight weight);
79 
80  /// Attempts to parse a font's weight name into the style bit field.
81  static bool parseWeightName(const char *name, FONT_Weight &weight);
82 
83  /// Less-than operator for comparison and sorting.
84  inline bool operator<(const FONT_Info &other) const
85  {
86  return myName < other.myName;
87  }
88 private:
89  friend class FONT_Registry;
90  FONT_Info()
91  : myStyle(FONT_STYLE_NORMAL), myWeight(FONT_WEIGHT_REGULAR),
92  myFaceIndex(-1), myIsValid(false)
93  {}
94  FONT_Info(
97  const UT_StringHolder &path, int face_index = 0)
98  : myTypeface(typeface), myName(name),
99  myStyle(style), myWeight(weight),
100  myPath(path), myFaceIndex(face_index)
101  { /**/ }
102 
103  UT_StringHolder myTypeface;
104  UT_StringHolder myName;
105  FONT_Style myStyle;
106  FONT_Weight myWeight;
107  bool myIsValid;
108 
109  UT_StringHolder myPath;
110  int myFaceIndex;
111 };
112 
113 FONT_API std::ostream &
114 operator<<(std::ostream &os, const FONT_Info &fi);
115 
116 
117 #endif // __FONT_Info__
int faceIndex() const
Definition: FONT_Info.h:68
SYS_FORCE_INLINE const UT_StringHolder & name() const
Definition: FONT_Info.h:39
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
static bool parseWeightName(const char *name, FONT_Weight &weight)
Attempts to parse a font's weight name into the style bit field.
Font is slanted.
Definition: FONT_Enums.h:33
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
struct FT_LibraryRec_ * FT_Library
Definition: FONT_Info.h:25
#define FONT_API
Definition: FONT_API.h:10
FONT_Weight
Definition: FONT_Enums.h:49
bool isBolded() const
Returns true if the font is bolded in some way.
Definition: FONT_Info.h:55
static const char * weightName(FONT_Weight weight)
static bool parseStyleName(const char *name, FONT_Style &style)
Attempts to parse a font's style name into the style bit field.
SYS_FORCE_INLINE const UT_StringHolder & typeface() const
The typeface (font family) of the font. E.g. 'Helvetica'.
Definition: FONT_Info.h:34
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
static bool styleName(FONT_Style style, UT_WorkBuffer &name)
Returns the font style name given an FONT_Style bitmap value.
bool isSlanted() const
Returns true if the font is italic or oblique.
Definition: FONT_Info.h:50
GLuint const GLchar * name
Definition: glcorearb.h:786
No extra visual styles apply.
Definition: FONT_Enums.h:31
FONT_Weight weight() const
The weight of the font.
Definition: FONT_Info.h:59
bool hasStyle(FONT_Style style) const
Returns true if the font has the specific style flag set.
Definition: FONT_Info.h:46
bool operator<(const FONT_Info &other) const
Less-than operator for comparison and sorting.
Definition: FONT_Info.h:84
FONT_Style style() const
Definition: FONT_Info.h:43
bool isValid() const
Definition: FONT_Info.h:30
const char * path() const
Definition: FONT_Info.h:63
Font is italic (calligraphic)
Definition: FONT_Enums.h:32
FONT_API std::ostream & operator<<(std::ostream &os, const FONT_Info &fi)
FONT_Style
The font's style describes its visual appearance.
Definition: FONT_Enums.h:29