chiark / gitweb /
terminal/unifont: add built-in fallback glyph
authorDavid Herrmann <dh.herrmann@gmail.com>
Thu, 2 Oct 2014 17:47:21 +0000 (19:47 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Fri, 3 Oct 2014 13:57:00 +0000 (15:57 +0200)
In case we cannot render a glyph, we want a fallback we can display
instead. If we rely on the font itself to provide the fallback character,
we have nothing to display if that character is not available. Therefore,
add a static fallback that we can use at any time.

src/libsystemd-terminal/unifont.c
src/libsystemd-terminal/unifont.h

index 75200159884a10649dbe379f47d3f28e41b80e0f..2acfa9821ab2520e19f2604b25d025adaaba2c2f 100644 (file)
@@ -221,3 +221,21 @@ int unifont_lookup(unifont *u, unifont_glyph *out, uint32_t ucs4) {
                 memcpy(out, &g, sizeof(g));
         return 0;
 }
+
+void unifont_fallback(unifont_glyph *out) {
+        static const uint8_t fallback_data[] = {
+                /* unifont 0xfffd '�' (unicode replacement character) */
+                0x00, 0x00, 0x00, 0x7e,
+                0x66, 0x5a, 0x5a, 0x7a,
+                0x76, 0x76, 0x7e, 0x76,
+                0x76, 0x7e, 0x00, 0x00,
+        };
+
+        assert(out);
+
+        out->width = 8;
+        out->height = 16;
+        out->stride = 1;
+        out->cwidth = 1;
+        out->data = fallback_data;
+}
index 0ded61472f4612888599d8efc2e060a942f83daf..30527cb3fa1aaada578dd8e732ed5b5d5ac5a71d 100644 (file)
@@ -54,3 +54,4 @@ unsigned int unifont_get_width(unifont *u);
 unsigned int unifont_get_height(unifont *u);
 unsigned int unifont_get_stride(unifont *u);
 int unifont_lookup(unifont *u, unifont_glyph *out, uint32_t ucs4);
+void unifont_fallback(unifont_glyph *out);