1FontServer class
2################
3
4The FontServer provides the base functionality for providing font
5support for the rest of the system and insulates the rest of the server
6from having to deal too much with FreeType.
7
8Member Functions
9================
10
11+-----------------------------------+-----------------------------------+
12| FontServer(void)                  | ~FontServer(void)                 |
13+-----------------------------------+-----------------------------------+
14| void Lock(void)                   | void Unlock(void)                 |
15+-----------------------------------+-----------------------------------+
16| void SaveList(void)               | status_t ScanDirectory(const char |
17|                                   | \*path)                           |
18+-----------------------------------+-----------------------------------+
19| FontStyle \*GetFont(font_family   | FontInstance                      |
20| family, font_style face)          | \*GetInstance(font_family family, |
21|                                   | font_style face, int16 size,      |
22|                                   | int16 rotation, int16 shear)      |
23+-----------------------------------+-----------------------------------+
24| int32 CountFamiles(void)          | status_t IsInitialized(void)      |
25+-----------------------------------+-----------------------------------+
26| int32 CountStyles(font_family     | FontStyle \*GetStyle(font_family  |
27| family)                           | family, font_style style)         |
28+-----------------------------------+-----------------------------------+
29| void RemoveFamily(const char      | FontFamily \*_FindFamily(const    |
30| \*family)                         | char \*name)                      |
31+-----------------------------------+-----------------------------------+
32| ServerFont \*GetSystemPlain(void) | ServerFont \*GetSystemBold(void)  |
33+-----------------------------------+-----------------------------------+
34| ServerFont \*GetSystemFixed(void) | bool SetSystemPlain(const char    |
35|                                   | \*family, const char \*style,     |
36|                                   | float size)                       |
37+-----------------------------------+-----------------------------------+
38| void RemoveUnusedFamilies(void)   | bool FontsNeedUpdated(void)       |
39+-----------------------------------+-----------------------------------+
40
41FontServer(void)
42----------------
43
441. Create access semaphore
452. Call FT_Init_FreeType()
463. If no error initializing the FreeType library, set init flag to true
47
48~FontServer(void)
49-----------------
50
511. Call FT_Done_FreeType()
52
53void Lock(void), void Unlock(void)
54----------------------------------
55
56These functions simply acquire and release the internal access
57semaphore.
58
59void SaveList(void)
60-------------------
61
62Saves the list of all scanned and valid font families and styles to
63disk
64
65
661. create a BMessage for storing font family data (hereafter, the font message)
672. create a BMessage for storing a list of font family messages (hereafter, the list message)
683. create a boolean tuned flag and a boolean fixed flag
694. Iterate through all families
70
71   A. for each family, get its name and add its name to the font message as "name"
72   B. iterate through the families styles
73
74      a. get the style's name, and if valid, add it to the font message as "styles"
75      b. if IsTuned and IsScalable, set the tuned flag to true
76      c. if IsFixedWidth, set the fixed flag to true
77
78   C. if the tuned flag is set, add a boolean true to the font message as "tuned"
79   D. if the fixed flag is set, add a boolean true to the font message as "fixed"
80   E. add the font message to the list message as "family"
81   F. empty the font message
82
835. Create a BFile from the path definition SERVER_FONT_LIST for Read/Write, creating the file if nonexistent and erasing any existing one
846. Flatten the list message to the created BFile object
857. Set the needs_update flag to false
86
87
88status_t ScanDirectory(const char \*path)
89-----------------------------------------
90
91ScanDirectory is where the brunt of the work of the FontServer is done: scan the directory of all fonts which can be loaded.
92
931. Make a BDirectory object pointer at the path parameter. If the init code is not B_OK, return it.
942. Enter a while() loop, iterating through each entry in the given directory, executing as follows:
95
96   a. Ensure that the entry is not '.' or '..'
97   b. Call FT_New_Face on the entry's full path
98   c. If a valid FT_Face is returned, iterate through to see if there are any supported character mappings in the current entry.
99   d. If there are no supported character mappings, dump the supported mappings to debug output, call FT_Done_Face(), and continue to the next entry
100   e. See if the entry's family has been added to the family list. If it hasn't, create one and add it.
101   f. Check to see if the font's style has been added to its family. If so, call FT_Done_Face, and continue to the next entry
102   g. If the style has not been added, create a new SFont for that family and face, increment the font count, and continue to the next entry.
103
1043. set the needs_update flag to true
1054. Return B_OK
106
107Supported character mappings are Windows and Apple Unicode, Windows
108symbol, and Apple Roman character mappings, in order of preference
109from first to last.
110
111FontStyle \*GetFont(font_family family, font_style face)
112--------------------------------------------------------
113
114Returns an FontStyle object for the specified family and style or NULL
115if not found.
116
1171. Call \_FindFamily() for the given family
1182. If non-NULL, call its FindStyle() method
1193. Return the result
120
121FontInstance \*GetInstance(font_family family, font_style face, int16 size, int16 rotation, int16 shear)
122--------------------------------------------------------------------------------------------------------
123
124Returns a usable instance of a specified font object with specified
125properties.
126
127
1281. Duplicates and performs the code found in GetFont
1292. Assuming that the FontStyle object is non-NULL, it calls its GetInstance method and returns the result.
130
131
132int32 CountFamilies(void)
133-------------------------
134
135Returns the number of valid font families available to the system.
136
137
1381. Return the number of items in the family list
139
140
141status_t IsInitialized(void)
142----------------------------
143
144Returns the initialization status variable
145
146
147int32 CountStyles(font_family family)
148-------------------------------------
149
150Returns the number of styles available for a given font family.
151
152
1531. Call \_FindFamily() to get the appropriate font family
1542. If non-NULL, call its return the result of its CountStyles method
155
156FontStyle \*GetStyle(font_family family, font_style style)
157----------------------------------------------------------
158
159Gets the FontStyle object of the family, style, and flags.
160
1611. Call \_FindFamily() to get the appropriate font family
1622. If non-NULL, call the family's GetStyle method on the font_style parameter and return the result
1633. If family is NULL, return NULL
164
165void RemoveFamily(const char \*family)
166--------------------------------------
167
168Removes a font family from the family list
169
1701. Look up font family in the family list via \_FindFamily()
1712. If it exists, delete it
172
173FontFamily \*_FindFamily(const char \*name)
174-------------------------------------------
175
176Looks up a FontFamily object based on its family name. Returns NULL if not found.
177
1781. Call the family list's find() method.
1792. Return the appropriate FontFamily object or NULL if not found.
180
181ServerFont \*GetSystemPlain(void), ServerFont \*GetSystemBold(void), ServerFont \*GetSystemFixed(void)
182------------------------------------------------------------------------------------------------------
183
184These return a copy of a pointer to the system-wide ServerFont objects
185which represent the appropriate system font settings. It is the
186responsibility of the caller to delete the object returned. NULL is
187returned if no setting has been set for a particular system font.
188
189
190bool SetSystemPlain(const char \*family, const char \*style, float size)
191------------------------------------------------------------------------
192
193bool SetSystemBold(const char \*family, const char \*style, float size)
194-----------------------------------------------------------------------
195
196bool SetSystemFixed(const char \*family, const char \*style, float size)
197------------------------------------------------------------------------
198
199
200The system fonts settings may be set via these calls by specifying the
201family, style, and size. They return true if everything worked out ok
202and false if not. Settings are not changed if false is returned.
203
2041. Call \_FindFamily on the family parameter. if NULL, return false
2052. Call the family's GetStyle member. if NULL, return false
2063. if the appropriate system font pointer is non-NULL, delete it
2074. call the style's Instantiate member with the size parameter
208
209
210void RemoveUnusedFamilies(void)
211-------------------------------
212
213The purpose of this function is to allow for a complete rescan of the
214fonts in the appropriate directories.
215
216
2171. Iterate through the family list
218
219   A. Get a family
220   B. if it has no dependents, remove it from the list and delete it
221
2222. Set the needs_update flag to true
223
224
225bool FontsNeedUpdated(void)
226---------------------------
227
228Returns the value of the needs_update flag
229