Scalable Screen Font: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
mNo edit summary
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(2 intermediate revisions by 2 users not shown)
Line 17:
Designed specially for OS consoles, has only one function. It can render unscaled bitmap fonts directly to the framebuffer. Has absolutely no dependencies, and compiles to less than two kilobytes of code.
 
<sourcesyntaxhighlight lang="c">
#define SSFN_CONSOLEBITMAP_HICOLOR SSFN_CONSOLEBITMAP_TRUECOLOR /* use the special renderer for hicolor32 bit truecolor packed pixels */
#include <ssfn.h>
 
Line 25:
ssfn_dst.ptr = 0xE0000000; /* framebuffer address and bytes per line */
ssfn_dst.p = 4096;
ssfn_dst.fg = 0xFFFF0xFFFFFFFF; /* colors, white on black */
ssfn_dst.bg = 0;
ssfn_dst.x = 100; /* coordinates to draw to */
Line 36:
ssfn_putc('l');
ssfn_putc('o');
</syntaxhighlight>
</source>
 
== Normal Renderer ==
Line 42:
There's another for user space applications. This one can render all three types of fonts, supports gzip compressed fonts, it can scale, anti-alias and kern glyphs. Has minimal libc dependencies (memset, memcmp, realloc, free) and compiles to about 28 kilobytes of code. (Just for completeness, you can compile it in total dependency-free mode if you define SSFN_MAXLINES, but then there'll be no internal glyph cache and you must provide inflated fonts only to ssfn_load().)
 
<sourcesyntaxhighlight lang="c">
#define SSFN_IMPLEMENTATION /* use the normal renderer implementation */
#include <ssfn.h>
Line 82:
/* free resources */
ssfn_free(&ctx); /* free the renderer context's internal buffers */
</syntaxhighlight>
</source>
The renderer takes care of the font direction, it uses horizontal or vertical alignment automatically. It cannot determine right-to-left though, for that you'll need
a minimal BiDi state machine too. That has to be implemented in the text renderer (or text shaping library) that's built on top of the low level rasterizer. The [http://www.unicode.org/reports/tr9/ algorithm to properly display bidirectional texts] is specified by UNICODE. But once you have decided that you need to draw a glyph in right-to-left direction, just pass SSFN_STYLE_RTL to ssfn_select().
Line 98:
 
[[Category:Graphical UI]]
[[Category:Fonts]]