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 <iosfwd>
21 
22 class UT_WorkBuffer;
23 struct FT_LibraryRec_;
24 typedef struct FT_LibraryRec_ *FT_Library;
25 
26 class FONT_Info
27 {
28 public:
29  inline bool isValid() const { return myIsValid; }
30 
31  /// The typeface (font family) of the font. E.g. 'Helvetica'
32  inline const char *typeface() const { return myTypeface; }
33 
34  /// The full name of the font, including style and weight.
35  /// E.g. 'Helvetica Bold Oblique'
36  inline const char *name() const { return myName; }
37 
38  /// A bitmap of the styles of the face. See FONT_Style for possible
39  /// bits.
40  FONT_Style style() const { return myStyle; }
41 
42  /// Returns \c true if the font has the specific style flag set.
43  bool hasStyle(FONT_Style style) const
44  { return (myStyle & style) == style; }
45 
46  /// Returns true if the font is italic or oblique.
47  bool isSlanted() const
48  { return hasStyle(FONT_STYLE_ITALIC) ||
50 
51  /// Returns true if the font is bolded in some way.
52  bool isBolded() const
53  { return int(myWeight) >= int(FONT_WEIGHT_DEMIBOLD); }
54 
55  /// The weight of the font.
56  FONT_Weight weight() const { return myWeight; }
57 
58  /// Returns the filename of the font. Can be either a TrueType,
59  /// OpenType, or Adobe Type-1 font.
60  inline const char *path() const { return myPath; }
61 
62  /// Returns the index of the face in the font file. This is used for
63  /// TrueType and OpenType font collection files to select the correct face
64  /// from within the file.
65  inline int faceIndex() const { return myFaceIndex; }
66 
67  /// Returns the font style name given an FONT_Style bitmap value.
69 
70  /// Attempts to parse a font's style name into the style bit field.
71  static bool parseStyleName(const char *name, FONT_Style &style);
72 
73  /// Returns the a weight name closest to the weight value given. The
74  /// value is clamped. See FONT_Weight for the known, named values.
75  static const char *weightName(FONT_Weight weight);
76 
77  /// Attempts to parse a font's weight name into the style bit field.
78  static bool parseWeightName(const char *name, FONT_Weight &weight);
79 
80  /// Less-than operator for comparison and sorting.
81  inline bool operator<(const FONT_Info &other) const
82  {
83  return myName < other.myName;
84  }
85 private:
86  friend class FONT_Registry;
87  FONT_Info()
88  : myStyle(FONT_STYLE_NORMAL), myWeight(FONT_WEIGHT_REGULAR),
89  myFaceIndex(-1), myIsValid(false)
90  {}
91  FONT_Info(
94  const UT_StringHolder &path, int face_index = 0)
95  : myTypeface(typeface), myName(name),
96  myStyle(style), myWeight(weight),
97  myPath(path), myFaceIndex(face_index)
98  { /**/ }
99 
100  UT_StringHolder myTypeface;
101  UT_StringHolder myName;
102  FONT_Style myStyle;
103  FONT_Weight myWeight;
104  bool myIsValid;
105 
106  UT_StringHolder myPath;
107  int myFaceIndex;
108 };
109 
110 FONT_API std::ostream &
111 operator<<(std::ostream &os, const FONT_Info &fi);
112 
113 
114 #endif // __FONT_Info__
int faceIndex() const
Definition: FONT_Info.h:65
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:24
#define FONT_API
Definition: FONT_API.h:10
FONT_Weight
Definition: FONT_Enums.h:49
const char * typeface() const
The typeface (font family) of the font. E.g. 'Helvetica'.
Definition: FONT_Info.h:32
bool isBolded() const
Returns true if the font is bolded in some way.
Definition: FONT_Info.h:52
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.
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:47
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:56
bool hasStyle(FONT_Style style) const
Returns true if the font has the specific style flag set.
Definition: FONT_Info.h:43
bool operator<(const FONT_Info &other) const
Less-than operator for comparison and sorting.
Definition: FONT_Info.h:81
FONT_Style style() const
Definition: FONT_Info.h:40
bool isValid() const
Definition: FONT_Info.h:29
const char * name() const
Definition: FONT_Info.h:36
const char * path() const
Definition: FONT_Info.h:60
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