972
edits
[unchecked revision] | [unchecked revision] |
m (Added text directions) |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 1:
Scalable Screen Font is a compressed font format which comes with a small, free, MIT licensed rendering library. It was designed specially for hobby OS developers, therefore it has minimal dependencies. It is also floating-point arithmetic free, so it will work even if your kernel hasn't initialized the FPU or SSE yet.
= Supported Font Types =
* Bitmap - you can convert [[PC Screen Font]] with UNICODE table into SSFN directly. X11 Bitmap Distribution Format, Portable Compiled Fonts and Windows FNT/FON files are also supported.
* Pixmap - to have colorful emoji icons, you can convert TGA and PNG files into SSFN fonts.
* Vector - vector based fonts can be converted from PostScript Type1, OpenType and [[TrueType_Fonts|TrueType fonts]].
Fonts are compressed, and in case of vector fonts, with a data-loss compression
= Library =
The SSFN package comes with a single ANSI C/C++ header file, which has two renderers. The header contains everything, no shared library nor static linking needed. They are compatible with both [[VESA]] and [[GOP]] framebuffers.
== Simple Renderer ==
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
<
#define
#include <ssfn.h>
/* set up context by global variables */
/* render
ssfn_putc(
ssfn_putc('e');
ssfn_putc('l');
ssfn_putc('l');
ssfn_putc('o');
</syntaxhighlight>
== Normal Renderer ==
There's another for user space applications. This one can render all three types of fonts, supports gzip compressed fonts, it can scale,
<
#define SSFN_IMPLEMENTATION /* use the normal renderer implementation */
#include <ssfn.h>
ssfn_t ctx; /* the renderer context */
/* you don't need to initialize the library, just make sure the context is zerod out */
Line 58 ⟶ 62:
ssfn_select(&ctx,
SSFN_FAMILY_SERIF, NULL, /* family */
SSFN_STYLE_REGULAR | SSFN_STYLE_UNDERLINE,
);
/* describe the destination buffer. Could be a 32 bit linear framebuffer as well */
glyph = ssfn_render(&ctx, 0x41);▼
/* rasterize the first glyph in an UTF-8 string into a 32 bit packed pixel buffer. Returns how many bytes were consumed from the string */
ssfn_render(&ctx, &buf, "Hello");
ssfn_render(&ctx, &buf, "ello");
ssfn_render(&ctx, &buf, "llo"); /* assuming there's a ligature for "ll" in the font */
▲ &glyph->data /* bitmap data */
▲pen_x += glyph->adv_x; /* adjust the cursor */
▲pen_y += glyph->adv_y; /* ssfn handles vertical fonts too */
/* free resources */
ssfn_free(&ctx); /* free the renderer context's internal buffers */
</syntaxhighlight>
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
▲pen_x += glyph->adv_x; /* adjust X for the next glyph */
▲pen_y += glyph->adv_y; /* adjust the Y coordinate this time */
▲It is not as simple as one would think, because it's not enough to know if the given UNICODE character belongs to a right-to-left scripting system, BiDi requires a minimal 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, these are the required steps:
▲if(rtl) /* set up cursor position for the next glyph */
= Links =
Line 134 ⟶ 93:
== External Links ==
* [https://forum.osdev.org/viewtopic.php?f=2&t=33719 OSDEV forum] on Scalable Screen Fonts
* https://gitlab.com/bztsrc/scalable-
* [https://gitlab.com/bztsrc/scalable-
* [https://gitlab.com/bztsrc/scalable-
[[Category:Graphical UI]]
[[Category:Fonts]]
|