vfs: check userland buffers before reading them.
[haiku.git] / src / servers / app / font / FontStyle.h
blobb64542b8240de4beb4886bd156a27554dec9e7bc
1 /*
2 * Copyright 2001-2008, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * DarkWyrm <bpmagic@columbus.rr.com>
7 * Axel Dörfler, axeld@pinc-software.de
8 */
9 #ifndef FONT_STYLE_H_
10 #define FONT_STYLE_H_
13 #include <Font.h>
14 #include <Locker.h>
15 #include <Node.h>
16 #include <ObjectList.h>
17 #include <Path.h>
18 #include <Rect.h>
19 #include <String.h>
21 #include <ft2build.h>
22 #include FT_FREETYPE_H
23 #include "ReferenceCounting.h"
24 #include "HashTable.h"
27 struct node_ref;
28 class FontFamily;
29 class ServerFont;
32 class FontKey : public Hashable {
33 public:
34 FontKey(uint16 familyID, uint16 styleID)
35 : fHash(familyID | (styleID << 16UL))
38 virtual ~FontKey() {};
40 virtual uint32 Hash() const
41 { return fHash; }
42 virtual bool CompareTo(Hashable& other) const
43 { return fHash == other.Hash(); }
45 private:
46 uint32 fHash;
50 /*!
51 \class FontStyle FontStyle.h
52 \brief Object used to represent a font style
54 FontStyle objects help abstract a lot of the font engine details while
55 still offering plenty of information the style in question.
57 class FontStyle : public ReferenceCounting, public Hashable {
58 public:
59 FontStyle(node_ref& nodeRef, const char* path,
60 FT_Face face);
61 virtual ~FontStyle();
63 virtual uint32 Hash() const;
64 virtual bool CompareTo(Hashable& other) const;
66 const node_ref& NodeRef() const { return fNodeRef; }
68 bool Lock();
69 void Unlock();
71 /*!
72 \fn bool FontStyle::IsFixedWidth(void)
73 \brief Determines whether the font's character width is fixed
74 \return true if fixed, false if not
76 bool IsFixedWidth() const
77 { return FT_IS_FIXED_WIDTH(fFreeTypeFace); }
80 /* \fn bool FontStyle::IsFullAndHalfFixed()
81 \brief Determines whether the font has 2 different, fixed, widths.
82 \return false (for now)
84 bool IsFullAndHalfFixed() const
85 { return false; };
87 /*!
88 \fn bool FontStyle::IsScalable(void)
89 \brief Determines whether the font can be scaled to any size
90 \return true if scalable, false if not
92 bool IsScalable() const
93 { return FT_IS_SCALABLE(fFreeTypeFace); }
94 /*!
95 \fn bool FontStyle::HasKerning(void)
96 \brief Determines whether the font has kerning information
97 \return true if kerning info is available, false if not
99 bool HasKerning() const
100 { return FT_HAS_KERNING(fFreeTypeFace); }
102 \fn bool FontStyle::HasTuned(void)
103 \brief Determines whether the font contains strikes
104 \return true if it has strikes included, false if not
106 bool HasTuned() const
107 { return FT_HAS_FIXED_SIZES(fFreeTypeFace); }
109 \fn bool FontStyle::TunedCount(void)
110 \brief Returns the number of strikes the style contains
111 \return The number of strikes the style contains
113 int32 TunedCount() const
114 { return fFreeTypeFace->num_fixed_sizes; }
116 \fn bool FontStyle::GlyphCount(void)
117 \brief Returns the number of glyphs in the style
118 \return The number of glyphs the style contains
120 uint16 GlyphCount() const
121 { return fFreeTypeFace->num_glyphs; }
123 \fn bool FontStyle::CharMapCount(void)
124 \brief Returns the number of character maps the style contains
125 \return The number of character maps the style contains
127 uint16 CharMapCount() const
128 { return fFreeTypeFace->num_charmaps; }
130 const char* Name() const
131 { return fName.String(); }
132 FontFamily* Family() const
133 { return fFamily; }
134 uint16 ID() const
135 { return fID; }
136 uint32 Flags() const;
138 uint16 Face() const
139 { return fFace; }
140 uint16 PreservedFace(uint16) const;
142 const char* Path() const;
143 void UpdatePath(const node_ref& parentNodeRef);
145 void GetHeight(float size, font_height &heigth) const;
146 font_direction Direction() const
147 { return B_FONT_LEFT_TO_RIGHT; }
148 font_file_format FileFormat() const
149 { return B_TRUETYPE_WINDOWS; }
151 FT_Face FreeTypeFace() const
152 { return fFreeTypeFace; }
154 status_t UpdateFace(FT_Face face);
156 private:
157 friend class FontFamily;
158 uint16 _TranslateStyleToFace(const char *name) const;
159 void _SetFontFamily(FontFamily* family, uint16 id);
161 private:
162 FT_Face fFreeTypeFace;
163 BString fName;
164 BPath fPath;
165 node_ref fNodeRef;
167 FontFamily* fFamily;
168 uint16 fID;
170 BRect fBounds;
172 font_height fHeight;
173 uint16 fFace;
176 #endif // FONT_STYLE_H_