![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
[A5] feature request: "al_create_builtin_8x8_bitmap_font" |
Dennis
Member #1,090
July 2003
![]() |
Just posting this here, so I can link to this thread and the attachment in the message which I'll write to the developer mailing-list in a moment. Briefly, this is about a request to include an embedded font within the "allegro_font" addon, so that it would be possible for example to display some quick debugging info without having to load an external font file. I already wrote the function and adapted the font data from Allegro4 for that (see attached zip, which includes the code to create the font at runtime and a modified ex_bitmap.c to demonstrate usage). edit --- 0xDB | @dennisbusch_de --- |
Ron Novy
Member #6,982
March 2006
![]() |
Would it be better to have a function called al_load_default_font that just loads the systems default font? Or just something like a Courier or Terminal font should be fine on any system that has it. I still like the idea of having a built-in font though... ---- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
I think it would be good to have this as a standard add-on in 5.2. The function name is terrible though... Something like al_get_generic_font() is easier to remember. Perhaps it could take a scaling parameter. Also, it might be beneficial to have this in the same add-on: al_load_system_font( int family, int size, int flags ); // these could be hard-coded to known OS fonts ALLEGRO_FONT_MONOSPACE (e.g., Courier) ALLEGRO_FONT_SANS_SERIF (e.g., Arial) ALLEGRO_FONT_SERIF (e.g., Times New Roman) // user fonts ... some intersection of commonly defined fonts ALLEGRO_FONT_DESKTOP ALLEGRO_FONT_WINDOW_TITLE Alternatively: al_load_system_font( const char *name, int size, int flags ); "Verdana, Arial, sans-serif"
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Yes, system fonts would be awesome. Could use fontconfig on linux. That'd be very nice. -- |
Dennis
Member #1,090
July 2003
![]() |
I renamed the function to "al_create_default_font" and attached the new version (plus minor fixes) to the first post. I would keep the "create" in the function name as a hint that the user is responsible for cleaning it up in the end via "al_destroy_font". Loading system fonts would be sweet indeed. For the font family parameter there could maybe even be a parameter like ALLEGRO_FONT_SYSTEM_DEFAULT which would try to load whichever font is usually 100% certainly available on the executing platform (and maybe fall back to a built-in font if that fails). --- 0xDB | @dennisbusch_de --- |
furinkan
Member #10,271
October 2008
![]() |
I kinda like the char* version better. This allows for CSS style font loading, like Matthew has shown. We can use the same font families as CSS to allow specification of preferred font, backup font, and family. I think things would go smoother from an application programmer's point of view. |
Evert
Member #794
November 2000
![]() |
I've figured out how to do the thing on OS X: get Library locations (usually ~/Library with fall back to /Library, but there are cocoa functions for getting this that one should use instead of hardcoding) and then look for Fonts. The non-trivial part is figuring out the filename you want, which is typically "Fontname Bold Italic.ttf" or "FontnameBold.ttf", but could be anything really. I guess it's possible to try those first, then look at the font descriptions in each font file until the desired font is found. Anyway, this is mainly a note to myself for how to implement this once an API is decided on and there is nothing left to do on 5.0. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Evert said: I've figured out how to do the thing on OS X: get Library locations (usually ~/Library with fall back to /Library, but there are cocoa functions for getting this that one should use instead of hardcoding) and then look for Fonts. Um, OSX should have a proper API for this. Doing it by searching for some font path is a little error prone. -- |
Elias
Member #358
May 2000
|
Thomas Fjellstrom said: Um, OSX should have a proper API for this. Doing it by searching for some font path is a little error prone. The alternative would be to not use Freetype at all and use OS functions to render glyphs instead (without ever knowing the font path). This would be more work to implement though. -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I suppose they could have left out a way to find fonts by attributes. That would suck though. I wonder if fontconfig works on OSX too? -- |
Evert
Member #794
November 2000
![]() |
Thomas Fjellstrom said: Um, OSX should have a proper API for this.
Sure. If I want an NSFont. But I don't, I want an ALLEGRO_FONT, which means I want to know a path to a filename. Elias said: The alternative would be to not use Freetype at all and use OS functions to render glyphs instead (without ever knowing the font path). This would be more work to implement though.
Wouldn't work with bitmap fonts and means a substantial redisign of the font addon. |
Trent Gamblin
Member #261
April 2000
![]() |
Is an 8x8 font really useful for 90% of the games that will be made? I understand it's good for old retro games, and maybe as a debugging aid, but even as a debugging aid, it's too small!
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Evert said: Sure. If I want an NSFont. But I don't, I want an ALLEGRO_FONT, which means I want to know a path to a filename. Yeah I misworded that. But it doesn't really matter, OSs like OSX and Windows really couldn't care less about apps that don't use the native toolkits. -- |
Evert
Member #794
November 2000
![]() |
Thomas Fjellstrom said: OSs like OSX and Windows really couldn't care less about apps that don't use the native toolkits.
No, but we do. According to Apple's documentation for how the Library directory is laid out, Fonts is a standard location, so the method I outlined above should work fine there. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Evert said: According to Apple's documentation for how the Library directory is laid out, Fonts is a standard location, so the method I outlined above should work fine there. Sure, but actually trying to search for a specific font family or other things just won't work. At best you'll be able to do is look at the file name, and thats probably not enough, unless we want to hard code font filenames. But thats not guaranteed to work at all. Might be an idea to see if fontconfig works on osx and windows. It could be very useful. -- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Trent Gamblin said: Is an 8x8 font really useful for 90% of the games that will be made? I understand it's good for old retro games, and maybe as a debugging aid, but even as a debugging aid, it's too small! A scale parameter could be used when creating the default font. 16x16 or 32x32 should be plenty big enough. |
Evert
Member #794
November 2000
![]() |
Thomas Fjellstrom said: Might be an idea to see if fontconfig works on osx and windows. It could be very useful. It's available in DarwinPorts, which gives its description as "An XML-based font configuration API for X Windows", so I'm guessing no native version. This (from the port file) Quote:
platform macosx {
suggests it's almost (but not quite) looking in the same locations I posted earlier (the function we use for the native file location API on OS X will actually return an array of locations, so if you asked for Library locations it would return all of Library, Networl/Library, System/Library, $HOME/Library; it's important to look in all those locations, I guess). |
Michał Cichoń
Member #11,736
March 2010
|
I did some time ago my function to enumerate font families and so on. Of course FreeType was used. Loading all fonts to collect font family info during application startup is time consuming task. Therefore I decided to use cache in which I store all necessary information about font face (family, style, physical file path, etc.). Such cache can be loaded and used next time. In the result I could type "Times New Roman" instead of "times.ttf". I think also meta families could be used, like monospace, sherif, etc. At the moment I have more than 500 font files under windows. This is fresh install with fonts from Office 2010. Collecting information about all fonts during application startup will cause ~2 second penalty in release mode. I think it is good idea to introduce some functions to enumerate fonts installed in the system. To keep this consistent FreeType should be used to collect necessary data. That's because Windows, Mac and other OS's use different methods to handle combinations of style/face. For there are fonts: Arial, Arial Narrow and Arial Black. Font family is 'Arial', styles are 'Narrow', 'Black', 'Italic', etc. Some come from font attributes some directly from names. Windows will treat those fonts like different fonts. Adobe products will treat all three as 'Arial' family and list 'Narrow' and 'Black' as styles. I'm not sure how this will work on Mac OS X or Linux. But it is clear that same set of font files will lead to different list of fonts on different OS's. With FreeType Allegro can provide unified way of enumerating fonts. "God starts from scratch too" |
Evert
Member #794
November 2000
![]() |
Michał Cichoń said: I did some time ago my function to enumerate font families and so on. Of course FreeType was used. Loading all fonts to collect font family info during application startup is time consuming task. Could do, I suppose. On the other hand, I don't think we need to do it if the user asks for a specific font type and we can do an educated guess first. Quote: I'm not sure how this will work on Mac OS X or Linux.
OS X lists "Arial.ttf", "Arial Bold.ttf", "Arial Italic.ttf" and "Arial Bold Italic.ttf" as "Family Arial" with "Typeface Regular, Bold, Italic, Bold Italic", but it lists "Arial Narrow.ttf", "Arial Narrow Bold.ttf" etc. as "Family Arial Narrow" with "Typeface Regular, Bold, Italic, Bold Italic". Quote: But it is clear that same set of font files will lead to different list of fonts on different OS's. With FreeType Allegro can provide unified way of enumerating fonts. Since this would sit on top of the TTF addon, which uses FreeType on all platforms, that shouldn't be a problem. Probably a good thing actually. |
Michał Cichoń
Member #11,736
March 2010
|
Yes, if user ask for specific font file, family name shouldn't be used. But still, enumerating all fonts is time consuming process. Results should be cached for example in file (memory file could be also used). I think functions for font enumeration should be placed in font add-on. In that way debug font will also be included in result list. TTF add-on should provide sub-enumeration routine. "God starts from scratch too" |
m c
Member #5,337
December 2004
![]() |
So as the function searches for a font:
Should programmers should probably be able to specify additional search paths? Ones that would will also override system fonts if clash (i.e ./fonts relative to program executable's assumed path). Might be useful in highly user-customizable, redistributed programs. Loading /temp/allegro-fonts.cache or w/e, should have a timestamp for each entry, should validate that each entry still exists and has not been modified since, should do this at add-on initialization. My 2 cents (\ /) |
Elias
Member #358
May 2000
|
The cache should probably be enabled explicitly. Something like: path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH) al_set_fontinfo_cache(path + "fontinfo.txt") That way the cached info would be in ~/.config/mygame/fontinfo.txt for example (under Linux). -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
It would better belong in temp, or data rather than settings. -- |
Michał Cichoń
Member #11,736
March 2010
|
Probably. But this should does not matter. I think ALLEGRO_FILE should be supported in the first place. Second, const char* may be provided not otherwise. User may want to collect information about system fonts, game fonts or mixed. Let say something like: 1enum ALLEGRO_FONT_INFO_CACHE_FLAGS
2{
3 ALLEGRO_SYSTEM_FONTS = 0x0001,
4 ALLEGRO_USER_FONTS = 0x0002
5};
6enum ALLEGRO_FONT_META_FAMILY
7{
8 ALLEGRO_SHERIF,
9 ALLEGRO_MONOSPACE,
10 ...
11};
12enum ALLEGRO_FONT_STYLE_FLAGS
13{
14 ALLEGRO_REGULAR = 0x01,
15 ALLEGRO_ITALIC = 0x02,
16 ALLEGRO_BOLD = 0x04
17};
18ALLEGRO_FONT_INFO_CACHE* al_font_info_cache_create(int flags);
19void al_font_info_cache_destroy(ALLEGRO_FONT_INFO_CACHE* cache);
20ALLEGRO_FONT_INFO_CACHE* al_font_info_cache_load_f(ALLEGRO_FILE* file);
21void al_font_info_cache_save_f(ALLEGRO_FONT_INFO_CACHE* cache, ALLEGRO_FILE* file);
22void al_font_info_cache_add_font_f(ALLEGRO_FILE* file);
23ALLEGRO_FONT_INFO* al_font_info_get_first(ALLEGRO_FONT_INFO_CACHE* cache);
24ALLEGRO_FONT_INFO* al_font_info_get_next(ALLEGRO_FONT_INFO_CACHE* cache, ALLEGRO_FONT_INFO* current);
25ALLEGRO_USTR* al_font_info_get_familiy_name(ALLEGRO_FONT_INFO* info);
26int al_font_info_get_meta_family(ALLEGRO_FONT_INFO* info);
27int al_font_info_get_style_flags(ALLEGRO_FONT_INFO* info);
28bool al_font_info_is_fixed_size(ALLEGRO_FONT_INFO* info);
29int al_font_info_get_first_size(ALLEGRO_FONT_INFO* info);
30int al_font_info_get_next_size(ALLEGRO_FONT_INFO* info, int current);
31
32/* system font, user font, custom font, etc... */
33int al_font_info_get_source(ALLEGRO_FONT_INFO* info);
In my font renderer I have interfaces IFontFamily, IFont, IFontManager and IFontRenderer. Font can be created using IFontFamily, other IFont but with different style/size, literal family name. Results of my attempt to translate all those to Allegro style functions for sure is not perfect. My intention is to introduce functions which provide all necessary (and common) information about font face. I will think about proper interface. Any hints/requirements/wishes will be most welcome. "God starts from scratch too" |
Elias
Member #358
May 2000
|
Would this read in all system fonts? cache = al_font_info_cache(ALLEGRO_SYSTEM_FONTS); And what would be the code to get an ALLEGRO_FONT once I have the ALLEGRO_FONT_INFO of the font I want? -- |
|
1
2
|