Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #324 from UltimateHackingKeyboard/font_refactor
Browse files Browse the repository at this point in the history
Add new icons, sanitize long texts.
  • Loading branch information
mondalaci authored Oct 10, 2024
2 parents 414e812 + 21c64ac commit 4bf0273
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 69 deletions.
105 changes: 97 additions & 8 deletions device/src/keyboard/oled/fonts/font_awesome_12.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Opts: --lv-font-name FontAwesome12 --format lvgl --bpp 4 -o font_awesome_12.c --size 12 --font /opt/fontawesome/otfs/font_awesome_6_regular.ttf --range 0xf057,0xf8dd,0xf1e6,0xe000,0xf071 --no-compress
******************************************************************************/

#include "font_awesome_12.h"
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
Expand All @@ -22,6 +23,7 @@

/*Store the image of the glyphs*/
static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = {
// These have to follow order defined in font_awesome_12_data
/* U+E000 "circle-xmark-large" */
0x0, 0x0, 0x13, 0x31, 0x0, 0x0, 0x0, 0x3b,
0xfe, 0xef, 0xb3, 0x0, 0x5, 0xf8, 0x10, 0x1,
Expand Down Expand Up @@ -78,27 +80,110 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = {
0xd4, 0xa8, 0xc, 0x60, 0x0, 0xe, 0x42, 0xf0,
0x4e, 0x11, 0x0, 0x0, 0x2, 0xa, 0xa0, 0xa,
0x60, 0x0, 0x0, 0x0, 0x1d, 0x10, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0
};
0x0, 0x0, 0x0, 0x0, 0x0,


/* U+E001 "lock-square-a" */
0x0, 0x66, 0x66, 0x66, 0x66, 0x0,
0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0,
0xf5, 0x0, 0x3, 0x30, 0x0, 0x5f,
0xf5, 0x0, 0x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 0xff, 0xff, 0xf4, 0x10, 0x0, 0x3, 0xff,
0xff, 0xf7, 0x0, 0x0, 0xb, 0xee, 0xff, 0x60,
0x0, 0x0, 0x9d, 0x10, 0x20, 0x0, 0x0, 0x0,
0x11, 0x0, 0x0, 0x0, 0x0, 0x0,

/* U+F06B "gift" */
0x0, 0x3, 0x0, 0x2, 0x30, 0x0, 0x1, 0xee,
0xe2, 0x5f, 0xec, 0x0, 0x7, 0xa0, 0x9b, 0xf4,
0xd, 0x40, 0x18, 0xd4, 0x5f, 0xd4, 0x5f, 0x61,
0xed, 0xdd, 0xdf, 0xed, 0xdd, 0xec, 0xf2, 0x0,
0xe, 0x90, 0x0, 0x4d, 0xdf, 0xff, 0xff, 0xff,
0xff, 0xfa, 0x4d, 0x22, 0x2e, 0xa2, 0x22, 0xf1,
0x4d, 0x0, 0xe, 0x90, 0x0, 0xf1, 0x4d, 0x0,
0xe, 0x90, 0x0, 0xf1, 0x3d, 0x0, 0xe, 0x90,
0x0, 0xf1, 0x1e, 0xdd, 0xdf, 0xed, 0xde, 0xd0,
0x1, 0x44, 0x44, 0x44, 0x44, 0x0,

/* U+E422 "lock-a" */
0x0, 0x0, 0x57, 0x30, 0x0, 0x0, 0x2, 0xef,
0xff, 0x80, 0x0, 0x0, 0xce, 0x30, 0x8f, 0x40,
0x0, 0xf, 0x70, 0x0, 0xf8, 0x0, 0x2, 0xf6,
0x0, 0xe, 0xa0, 0x8, 0xff, 0xff, 0xff, 0xff,
0xd2, 0xff, 0xff, 0xfb, 0xff, 0xff, 0x7f, 0xff,
0xf8, 0x1f, 0xff, 0xf8, 0xff, 0xff, 0x39, 0x8f,
0xff, 0x8f, 0xff, 0x81, 0x21, 0xff, 0xf8, 0xff,
0xf4, 0xff, 0x99, 0xff, 0x8e, 0xff, 0xff, 0xff,
0xff, 0xf6, 0x28, 0x99, 0x99, 0x99, 0x96, 0x0,

/* U+E423 "lock-hashtag" */
0x0, 0x1, 0x56, 0x30, 0x0, 0x0, 0x2, 0xef,
0xff, 0x80, 0x0, 0x0, 0xce, 0x31, 0x9f, 0x30,
0x0, 0xf, 0x70, 0x0, 0xf8, 0x0, 0x1, 0xf5,
0x0, 0xe, 0x90, 0x8, 0xff, 0xff, 0xff, 0xff,
0xd1, 0xff, 0xfd, 0x9f, 0x6f, 0xff, 0x6f, 0xfc,
0x21, 0x30, 0x7f, 0xf7, 0xff, 0xfb, 0x7f, 0x3f,
0xff, 0x7f, 0xfd, 0x53, 0x71, 0xaf, 0xf7, 0xff,
0xfb, 0x7f, 0x4f, 0xff, 0x7c, 0xff, 0xff, 0xff,
0xff, 0xf3, 0x4, 0x44, 0x44, 0x44, 0x42, 0x0
};

/*---------------------
* GLYPH DESCRIPTION
*--------------------*/

#define COMPUTE_GLYPH_LEN(BOXW, BOXH) (((BOXW)*(BOXH)+1)/2)
const uint8_t GlyphOffset_0 = 0;
#define GLYPH_DATA(INDEX0, INDEX1, NAME, ADVW, BOXW, BOXH, OFSX, OFSY) const uint16_t GlyphOffset_##INDEX1 = GlyphOffset_##INDEX0 + COMPUTE_GLYPH_LEN(BOXW, BOXH);
#include "font_awesome_12_data.h"
#undef GLYPH_DATA

static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
{.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,
{.bitmap_index = 0, .adv_w = 192, .box_w = 12, .box_h = 13, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 78, .adv_w = 192, .box_w = 13, .box_h = 13, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 163, .adv_w = 192, .box_w = 12, .box_h = 11, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 229, .adv_w = 144, .box_w = 9, .box_h = 13, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 288, .adv_w = 216, .box_w = 14, .box_h = 11, .ofs_x = 0, .ofs_y = -1}

#define GLYPH_DATA(INDEX0, INDEX1, NAME, ADVW, BOXW, BOXH, OFSX, OFSY) {.bitmap_index = GlyphOffset_##INDEX0, .adv_w = ADVW, .box_w = BOXW, .box_h = BOXH, .ofs_x = OFSX, .ofs_y = OFSY},
#include "font_awesome_12_data.h"
#undef GLYPH_DATA
};


/*---------------------
* CHARACTER MAPPING
*--------------------*/

// unused I believe
static const uint16_t unicode_list_0[] = {
0x0, 0x1057, 0x1071, 0x11e6, 0x18dd
};
Expand All @@ -112,7 +197,11 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
}
};


void DebugFont() {
for (uint8_t i = 0; i < 5; i++) {
printk("Glyph %d: %d\n", i, glyph_dsc[i].bitmap_index);
}
}

/*--------------------
* ALL CUSTOM DATA
Expand Down
16 changes: 16 additions & 0 deletions device/src/keyboard/oled/fonts/font_awesome_12.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __FONT_AWESOME_12_H__
#define __FONT_AWESOME_12_H__


// Typedefs:


typedef enum {
#define GLYPH_DATA(INDEX0, INDEX1, NAME, ADVW, BOXW, BOXH, OFSX, OFSY) FontIcon_##NAME = 32+INDEX0,
#include "font_awesome_12_data.h"
#undef GLYPH_DATA
FontIcon_AfterLast,
FontIcon_Count = FontIcon_AfterLast - 32,
} font_icons_t;

#endif
14 changes: 14 additions & 0 deletions device/src/keyboard/oled/fonts/font_awesome_12_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Indexes have to go in order one by one!

GLYPH_DATA(0, 1, CircleXmarkLarge, 192, 12, 13, 0, -2)
GLYPH_DATA(1, 2, CircleXmark, 192, 13, 13, 0, -2)
GLYPH_DATA(2, 3, TriangleExclamation, 192, 12, 11, 0, -1)
GLYPH_DATA(3, 4, Plug, 144, 9, 13, 0, -2)
GLYPH_DATA(4, 5, SignalStream, 216, 14, 11, 0, -1)
GLYPH_DATA(5, 6, LockSquareA, 192, 12, 13, 0, -2)
GLYPH_DATA(6, 7, LockSquareOne, 192, 12, 13, 0, -2)
GLYPH_DATA(7, 8, PlugsConnected, 192, 12, 13, 0, -2)
GLYPH_DATA(8, 9, Gift, 224, 12, 13, 1, -5)
GLYPH_DATA(9, 10, LockA, 168, 11, 13, 0, -2)
GLYPH_DATA(10, 11, LockHashtag, 168, 11, 13, 0, -2)

25 changes: 20 additions & 5 deletions device/src/keyboard/oled/fonts/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,28 @@
* - f057 - circle-xmark
* - f8dd - signal-stream
* - f1e6 - plug
* - e000 - circle-xmark-large (custom)
* - f071 - triangle-exclamation
* - f06b - gift
*
* customs:
* - e000 - circle-xmark-large (custom)
* - e001,e002 - caps lock, numlock
* - e003 - connected plug
*
* Commands to create icon fonts:
* `
* fontforge -lang=ff -c 'Open($1); Generate($2);' Font\ Awesome\ 6\ Pro-Regular-400.otf font_awesome_6_regular.ttf
* npx lv_font_conv --lv-font-name FontAwesome12 --format lvgl --bpp 4 -o font_awesome_12.c --size 12 --font /opt/fontawesome/otfs/font_awesome_6_regular.ttf --range 0xf057,0xf8dd,0xf1e6,0xe000,0xf071 --no-compress
* Script to create icon fonts, to be run from the root of a decompressed fontawesome folder:
```
#!/bin/bash
mkdir ttfs
fontforge -lang=ff -c 'Open($1); Generate($2);' otfs/Font\ Awesome\ 6\ Pro-Regular-400.otf ttfs/font_awesome_6_regular.ttf
fontforge -lang=ff -c 'Open($1); Generate($2);' otfs/Font\ Awesome\ 6\ Pro-Solid-900.otf ttfs/font_awesome_6_solid.ttf
fontforge -lang=ff -c 'Open($1); Generate($2);' otfs/Font\ Awesome\ Kit\ 4711ad2078-Regular-400.otf ttfs/font_awesome_custom.ttf
npx lv_font_conv --lv-font-name CustomIcons --format lvgl --bpp 4 -o icons_custom.c --size 12 --font ttfs/font_awesome_custom.ttf --range 0xe000-0xe003 --no-compress
npx lv_font_conv --lv-font-name RegularIcons --format lvgl --bpp 4 -o icons_regular.c --size 12 --font ttfs/font_awesome_6_regular.ttf --range 0xf057,0xf8dd,0xf1e6,0xf071,0xf06b --no-compress
npx lv_font_conv --lv-font-name SolidIcons --format lvgl --bpp 4 -o icons_solid.c --size 12 --font ttfs/font_awesome_6_solid.ttf --range 0xe423,0xe422 --no-compress
```
* */

extern const lv_font_t JetBrainsMono8;
Expand Down
Loading

0 comments on commit 4bf0273

Please sign in to comment.