FontServer class
The FontServer provides the base functionality for providing font support for the rest of the system and insulates the rest of the server from having to deal too much with FreeType.
Member Functions
FontServer(void) |
~FontServer(void) |
void Lock(void) |
void Unlock(void) |
FT_Library GetLibrary(void) |
void ScanDirectory(const char *path) |
FontStyle *GetFont(font_family family, font_style face) |
FontInstance *GetInstance(font_family family, font_style face, int16 size, int16 rotation, int16 shear) |
int32 CountFontFamilies(void) |
status_t GetFamily(int32 index, font_family family) |
int32 CountFontStyles(font_family family) |
status_t GetStyle(font_family family, font_style style, int32 *flags) |
void RemoveFamily(FontFamily *family) |
FontFamily *_FindFamily(const char *name) |
FontServer(void)
1) Create access semaphore
2) Call FT_Init_FreeType()
3) If no error initializing the FreeType library, set init flag to true
4) Call ScanDirectory() on /boot/beos/etc/fonts/psfonts, .../ttfonts, ~/config/fonts/psfonts and .../ttfonts
~FontServer(void)
1) Call FT_Done_FreeType()
void Lock(void)
void Unlock(void)
These functions simply acquire and release the internal access semaphore.
FT_Library GetLibrary(void)
Returns the internal FT_Library object
void ScanDirectory(const char *path)
ScanDirectory is where the brunt of the work of the FontServer is done - scans the directory of all fonts which can be loaded.
1) Iterate through the font family STL map and set each FontFamily object's Delete flag to true
2) Enter a while() loop, iterating through each entry in the given directory, executing as follows:
a) Ensure that the entry is not '.' or '..'
b) Call FT_New_Face on the entry's full path
c) If a valid FT_Face is returned, iterate through to see if there are any supported character mappings in the current entry.
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
e) See if the entry's family has been added to the family list. If it hasn't, create one and add it.
f) Check to see if the font's style has been added to its family. If so, call set the family's Delete flag to false, call FT_Done_Face, and continue to the next entry
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.
3) Iterate through all styles in each family and delete all SFont objects which have a true Delete flag
Supported character mappings are Windows and Apple Unicode, Windows symbol, and Apple Roman character mappings, in order of preference from first to last.
FontStyle *GetFont(font_family family, font_style face)
Returns an FontStyle object for the specified family and style or NULL if not found.
1) Call _FindFamily() for the given family
2) If non-NULL, call its FindStyle() method
3) Return the result
FontInstance *GetInstance(font_family family, font_style face, int16 size, int16 rotation, int16 shear)
Returns a usable instance of a specified font object with specified properties.
1) Duplicates and performs the code found in GetFont
2) Assuming that the FontStyle object is non-NULL, it calls its GetInstance method and returns the result.
int32 CountFontFamilies(void)
Returns the number of valid font families available to the system.
1) Return the number of items in the family list
status_t GetFamily(int32 index, font_family family)
Gets the name of the family with the index passed to the function and sets the font_family object to the appropriate value.
1) If index > family list count, return B_ERROR
2) Look up the string at the index, copy it, and return B_OK
int32 CountFontStyles(font_family family)
Returns the number of styles available for a given font family.
1) Call _FindFamily() to get the appropriate font family
2) If non-NULL, call its return the result of its CountStyles method
status_t GetStyle(font_family family, font_style style, int32 *flags)
Gets the name of the family with the index passed to the function and sets the font_family object to the appropriate value.
1) Call _FindFamily() to get the appropriate font family
2) If non-NULL, look up the string at the index, and copy it to the passed style object, otherwise, return B_ERROR
3) Get the style's FontStyle object and set flags to the flags contained in the FontStyle object
4) Return B_OK
void RemoveFamily(FontFamily *family)
Removes a font family from the family list
1) Look up font family in the family list
2) If it exists, delete it
protected:
FontFamily *_FindFamily(const char *name)
Looks up a FontFamily object based on its family name. Returns NULL if not found.
1) Call the family list's find() method.
2) Return the appropriate FontFamily object or NULL if not found.