![]() |
|
feature request + patch (5.1 branch): al_create_std_bitmap_font |
Dennis
Member #1,090
July 2003
![]() |
--- update 3, July 4th 2012 --- --- update 2, July 3rd 2012 --- --- update 1 --- --- original post --- I humbly request to include this in the 5.1 branch. stdfont.c said:
contains a ported binary version of the Allegro 4 internal standard font --- end of original post --- --- 0xDB | @dennisbusch_de --- |
Evert
Member #794
November 2000
![]() |
I think this could be an extra addon, something like "allegro_standard_font" or similar. This seems to me to fit nicely with Allegro 5's modular design. Apart from that technical detail, this seems like a good idea. Not sold on the A4 font though; it's a bit small at today's resolutions. Would it be possible to embed a TTF font? |
Dennis
Member #1,090
July 2003
![]() |
Embedding a TTF font should not be a problem in theory as long as there is some internal function which can read a TTF font from a memory address instead of from a given filename. I could then just write a small tool which reads a TTF file and generates a byte array in C code which I could then paste into the source and read the TTF font from there. The embedded TTF font should be royalty free, not GNU'ed or otherwise license contaminated and most importantly it should be as small as possible (bytesize not font-size). Evert said: Not sold on the A4 font though; it's a bit small at today's resolutions. My personal motivation for wanting it is to be able to quickly display some debugging information on screen near relevant in game objects without having to rely on external data. I could add a scaling parameter to the function in the OP. It would look blocky but it would be bigger. --- 0xDB | @dennisbusch_de --- |
Matthew Leverton
Supreme Loser
January 1999
![]() |
I dislike the name, but I don't see why it cannot be part of the regular font add-on. I don't really see a reason for an add-on that is full of embedded fonts. IMO, you either want a quick and dirty one for debugging or you want the full control of loading external TTFs. |
Elias
Member #358
May 2000
|
Yes, the intended use case of this should probably be some quick debug messages during development - not the font to use in your game/application. We may want an API to load a system font for that instead. Which probably would then be something like al_get_standard_font("Arial 12pt"). In light of that, I suggest changing the name to al_create_builtin_font (or similar). Also about the patch, I think it does not follow our style conventions. -- |
torhu
Member #2,727
September 2002
![]() |
I bet I'm not the only one using the a4_font.tga that comes with the Allegro 5 examples for my games. On my monitor it's a good size both for debug info printing and other text. It does the job, but a better looking font wouldn't hurt either. An easily available font for use early in the project, for debugging, or just when you can't be bothered to find something else would be handy. |
Dennis
Member #1,090
July 2003
![]() |
I only found one public domain font: http://tulrich.com/fonts/ The regular font face of that is about 160KB in .ttf and 140KB in .otf format. It might be possible to reduce that size to about 80KB to 95KB by storing it in a compressed form inside the code and the decompressing it in memory and loading it from there. However, that still seems huge for an embedded font. Elias said: In light of that, I suggest changing the name to al_create_builtin_font (or similar). Also about the patch, I think it does not follow our style conventions. Where can I find a copy of the style conventions? (are you referring to the local variable names inside the function?) Next up... Quote: We may want an API to load a system font for that instead. Which probably would then be something like al_get_standard_font("Arial 12pt"). That's outside the scope and purpose of this builtin font though but a good idea. Under Windows all fonts are stored under <WindowsInstallDir>/Fonts but maybe FreeType already has a function to enumerate system fonts? --- 0xDB | @dennisbusch_de --- |
Audric
Member #907
January 2001
|
Freefont itself doesn't know. |
weapon_S
Member #7,859
October 2006
![]() |
In the Allegro 4 manual there was the "Hacker's guide". |
Dennis
Member #1,090
July 2003
![]() |
Dennis said: I will rename the routine to al_create_builtin_font. Done. See updated main post (includes screenshot). I hope I didn't miss any important style convention from the A4 hackers guide. With the link Audric provided I'll look into starting with a new function for the TTF Addon soon(ish) but that will be a separate patch. --- 0xDB | @dennisbusch_de --- |
Elias
Member #358
May 2000
|
Is the scale parameter useful? You can achieve the exact same effect by drawing it at twice the size, it seems. -- |
Dennis
Member #1,090
July 2003
![]() |
I did not find a scale or size parameter in any of the text drawing routines and I was not aware of al_scale_transform when I wrote it. I think it does not hurt to have it though now that it's already there. The documentation could include a hint that scaling can be achieved by other means and that using the scaling parameter in the creation routine will cause the font to use up more texture memory as you pointed out in IRC. Using a combination of both al_scale_transform and a different scale on creation time may yield some interesting results though. Depending on how interpolation works, drawing a 2x or higher scaled(at creation time) version at less than 0.5 size (using al_scale_transform) may lead to cleaner or dirtier rendering output. EDIT: --- 0xDB | @dennisbusch_de --- |
Elias
Member #358
May 2000
|
A HQX addon would be interesting I guess. But it would be a separate addon and simply scale one bitmap to another. Maybe more useful than just doing an offline scale would be a new shader example which uses a real-time HQX shader. That's a bit of work though -- |
Dennis
Member #1,090
July 2003
![]() |
I started thinking about a simple up-scaling smoothing algorithm for this special monochrome (1 bit) case for scaling the available font data bits into something less blocky. It won't be able to generate nice curves, nor would it be able to get any non-multiple of 45 degrees lines corrected or even nicely extrapolated but I think the result would be good enough to make looking at it more tolerable than looking at blocky fat pixels. The basic idea is to test around a given target (fat)pixel for intersecting "lines" and then slapping one or more of 8 different (scaled) triangles into the (fat)pixel in a lower pixel resolution. I fixed my thoughts in the following (not yet complete) diagram: I'd basically have four different tests in four different orientations each. Each test would have to check at most 6 bits. Some tests must have precedence over others. Each test must specify which of the eight triangles to render into the gap to iron it out. There'd be a few special test cases as well. ---- append 2 (additional notes(view with monospaced font) to the above image and the algorithm) +------------------------------------------+ |Monochrome Font Upscaling Algo v.1.0 draft| |"Tri-add-rem" by Dennis-Busch@gmx.net | |July 1st 2012 | +------------------------------------------+ (see also "Tri-add-rem-draft10b.png") Short description: ------------------ Examine bits around source pixel and reshape scaled target "pixel"(square) by adding or removing one or more of four triangles to/from the target square. Random thought: Could easily be adapted for achieving differently styled result by using other shapes than triangles, e.g. cirlce sections. triangles 0 to 3: ----------------- (the sides on the right angle are supposed to be even in length and their length is half the target square side length) +--+ +--+ + + | / \ | |\ /| |/ \| | \ / | + + +--+ +--+ t0 t1 t2 t3 Bits around target square/source pixel: --------------------------------------- bit 0, bit 1, bit 2 bit 3, ts/sp, bit 4 bit 5, bit 6, bit 7 (ts = target square, sp = source pixel) A test case(rule) includes the following information: ----------------------------------------------------- a.) an "apply only on scale factor 3 or more" bit (to prevent erasing/adding full squares on scaling factor 2 for some otherwise generic rules) b.) a "stop bit" to specify that no other rule should be tested if this rule applies (rule tests must be sorted so that rules with higher precedence will be tested first) c.) the bit pattern (set, un-set, don't care) which the bits around the source pixel must represent in order to apply the triangle operations to the target square (need two bits per bit in the pattern to represent the "don't care" setting) d.) four triangle bits specifying which triangles to apply(add/remove) (if sp is set they will be removed otherwise they will be added) So there will be 22 bits per rule, so each rule needs 3 bytes to be stored: a,b,d can be stored together in one byte and c can be stored in two bytes 00ddddba | cccccccc (set/unset bits) | cccccccc (don't care bits) 1 1 1 (least significant bit) 0123 01234567 01234567 (triangle numbers, surrounding bit numbers) rules for 'set' source pixel (only remove triangles): ----------------------------------------------------- example for the first non-exclusive rule in the diagram on the image file 00101000 | 00001000 | 00000000 (left 'line' ending) 0123ba | 01234567 | 01234567 example for the first exclusive rule in the image file 00111111 | 00000000 | 00000000 (single square surrounded by unset bits) 0123ba | 01234567 | 01234567 todo: add rules rules for 'unset' source pixel (only add triangles): ---------------------------------------------------- example for the second exclusive rule in the image file 00111111 | 01011010 | 10100101 (empty square surrounded by set/don't care bits) 0123ba | 01234567 | 01234567 todo: add rules
--- 0xDB | @dennisbusch_de --- |
weapon_S
Member #7,859
October 2006
![]() |
Oh. Hey. Why not submit two add-ons?! |
Dennis
Member #1,090
July 2003
![]() |
Have you ever wasted two days implementing a complicated algorithm until you realized you can achieve the same effect with a MUCH SIMPLER method? No? Well, I just did that. As I was adding more and more of those rules I realized I can base all of that on much simpler rules: If the center pixel is set and the three neighbor pixels of a triangle are empty, remove that triangle. If the center pixel is not set and the orthogonal neighbor pixels of a triangle are filled, add that triangle. In both cases, if there are at least two triangles being added or removed, make them slightly smaller. Simple. And I already had this very complicated system (complete with lookup table and rule definitions in place... :X ). Overly complex code[1] and image below are included just for laughs: XD --- append --- --- 0xDB | @dennisbusch_de --- |
|