1/*
2 * Copyright 2001-2008, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
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_
11
12
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 <Referenceable.h>
20#include <String.h>
21
22#include <ft2build.h>
23#include FT_FREETYPE_H
24
25
26struct node_ref;
27class FontFamily;
28class ServerFont;
29
30
31/*!
32 \class FontStyle FontStyle.h
33 \brief Object used to represent a font style
34
35 FontStyle objects help abstract a lot of the font engine details while
36 still offering plenty of information the style in question.
37*/
38class FontStyle : public BReferenceable {
39 public:
40 FontStyle(node_ref& nodeRef, const char* path,
41 FT_Face face);
42 virtual ~FontStyle();
43
44 const node_ref& NodeRef() const { return fNodeRef; }
45
46 bool Lock();
47 void Unlock();
48
49/*!
50 \fn bool FontStyle::IsFixedWidth(void)
51 \brief Determines whether the font's character width is fixed
52 \return true if fixed, false if not
53*/
54 bool IsFixedWidth() const
55 { return FT_IS_FIXED_WIDTH(fFreeTypeFace); }
56
57
58/* \fn bool FontStyle::IsFullAndHalfFixed()
59 \brief Determines whether the font has 2 different, fixed, widths.
60 \return false (for now)
61*/
62 bool IsFullAndHalfFixed() const
63 { return fFullAndHalfFixed; };
64
65/*!
66 \fn bool FontStyle::IsScalable(void)
67 \brief Determines whether the font can be scaled to any size
68 \return true if scalable, false if not
69*/
70 bool IsScalable() const
71 { return FT_IS_SCALABLE(fFreeTypeFace); }
72/*!
73 \fn bool FontStyle::HasKerning(void)
74 \brief Determines whether the font has kerning information
75 \return true if kerning info is available, false if not
76*/
77 bool HasKerning() const
78 { return FT_HAS_KERNING(fFreeTypeFace); }
79/*!
80 \fn bool FontStyle::HasTuned(void)
81 \brief Determines whether the font contains strikes
82 \return true if it has strikes included, false if not
83*/
84 bool HasTuned() const
85 { return FT_HAS_FIXED_SIZES(fFreeTypeFace); }
86/*!
87 \fn bool FontStyle::TunedCount(void)
88 \brief Returns the number of strikes the style contains
89 \return The number of strikes the style contains
90*/
91 int32 TunedCount() const
92 { return fFreeTypeFace->num_fixed_sizes; }
93/*!
94 \fn bool FontStyle::GlyphCount(void)
95 \brief Returns the number of glyphs in the style
96 \return The number of glyphs the style contains
97*/
98 uint16 GlyphCount() const
99 { return fFreeTypeFace->num_glyphs; }
100/*!
101 \fn bool FontStyle::CharMapCount(void)
102 \brief Returns the number of character maps the style contains
103 \return The number of character maps the style contains
104*/
105 uint16 CharMapCount() const
106 { return fFreeTypeFace->num_charmaps; }
107
108 const char* Name() const
109 { return fName.String(); }
110 FontFamily* Family() const
111 { return fFamily; }
112 uint16 ID() const
113 { return fID; }
114 uint32 Flags() const;
115
116 uint16 Face() const
117 { return fFace; }
118 uint16 PreservedFace(uint16) const;
119
120 const char* Path() const;
121 void UpdatePath(const node_ref& parentNodeRef);
122
123 void GetHeight(float size, font_height &heigth) const;
124 font_direction Direction() const
125 { return B_FONT_LEFT_TO_RIGHT; }
126 font_file_format FileFormat() const
127 { return B_TRUETYPE_WINDOWS; }
128
129 FT_Face FreeTypeFace() const
130 { return fFreeTypeFace; }
131
132 status_t UpdateFace(FT_Face face);
133
134 private:
135 friend class FontFamily;
136 uint16 _TranslateStyleToFace(const char *name) const;
137 void _SetFontFamily(FontFamily* family, uint16 id);
138
139 private:
140 FT_Face fFreeTypeFace;
141 BString fName;
142 BPath fPath;
143 node_ref fNodeRef;
144
145 FontFamily* fFamily;
146 uint16 fID;
147
148 BRect fBounds;
149
150 font_height fHeight;
151 uint16 fFace;
152 bool fFullAndHalfFixed;
153};
154
155#endif // FONT_STYLE_H_