edelib 1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
FontCache Class Reference
FLTK widgets and functions

Allow readable font names and cache their access. More...

`#include <edelib/FontCache.h>`

## Public Member Functions
| FontCache ()
| ~FontCache ()
bool | load (const char *dir, const char *db="edelib-font-cache", const char *prefix="ede")
bool | load (void)
void | clear (void)
int | count (void) const
bool | find (const char *n, Fl_Font &font, int &size)
FontInfo * | find (const char *n, int &size)
void | for_each_font (void(*)(const char *n, FontInfo *, void *), void *data=((void *) 0))
void | for_each_font_sorted (void(*)(const char *n, FontInfo *, void *), void *data=((void *) 0))

## Static Public Member Functions
static int | init_db (const char *dir, const char *db="edelib-font-cache", const char *prefix="ede")
static int | init_db (void)

## Detailed Description

Allow readable font names and cache their access.

FLTK does not provide any kind of facility for advanced font handling, and this class is to provide at least some basis for this. Each font in FLTK can only be accessed by it's index number, stored in internal font array and set by labelfont(). This scheme is inefficient for non standard fonts (not predefined inside FLTK) as index number can be different each time application starts, causing high probability to select different font face.

FontCache tries to fix this; all fonts are prepopulated (either with FontCache::init_db() or external tool like edelib-update-font-cache), where cache database will be stored in XDG cache directory (

See Also
  user_cache_dir()).

Todo:
  complete

## Constructor & Destructor Documentation

FontCache | ( |  | ) |
| inline

Constructor.

~FontCache | ( |  | ) |
| inline

Destructor; close all database handlers.

## Member Function Documentation

void clear | ( | void |  | ) |

Unload database (if loaded) and explicitly clear all internal data.

int count | ( | void |  | ) | const

Return number of fonts inside database. If database is not loaded or is unable to get font number, return -1.

bool find | ( | const char * | n,
|  | Fl_Font & | font,
|  | int & | size
| ) |  |

Try to find given face and size in given database path. If found, register it as FLTK font and set font id and size.

FontInfo* find | ( | const char * | n,
|  | int & | size
| ) |  |

Try to find given FontInfo object for given name. This function will not register it as FLTK font, as other find() method. Returns NULL if name wasn't found.

void for_each_font | ( | void(*)(const char *n, FontInfo *, void *) | ,
|  | void * | data = `((void *) 0)`
| ) |  |

This function can be used to iterate all fonts, where on each font will be called callback. Fonts will not be in sorted order.

void for_each_font_sorted | ( | void(*)(const char *n, FontInfo *, void *) | ,
|  | void * | data = `((void *) 0)`
| ) |  |

Iterate over fonts, just as for_each_font(), except fonts will be sorted. To operate like this, all database keys must be fetched first and them sorted in memory. After that, it will access to database content.

This function is clearly inefficient if called on large database.

static int init_db | ( | const char * | dir,
|  | const char * | db = `"edelib-font-cache"`,
|  | const char * | prefix = `"ede"`
| ) |  |
| static

Initialize font cache database on given path and return number of stored fonts. It will call Fl::set_fonts("-*"), which will in turn open display and register all available fonts to FLTK.

This function is not meant to be used directly from application that wants to access font faces. Calling it, it will register unnecessary fonts in FLTK and will increase application memory usage. Here it is so external tools can use it.

static int init_db | ( | void |  | ) |
| static

Call init_db() with user_cache_dir() path.

bool load | ( | const char * | dir,
|  | const char * | db = `"edelib-font-cache"`,
|  | const char * | prefix = `"ede"`
| ) |  |

Try to load database in given folder with given name. If fails somehow (database does not exists or it is not valid), it will return false.

bool load | ( | void |  | ) |

Call load() with user_cache_dir() path.

The documentation for this class was generated from the following file:

- edelib/FontCache.h