Giter Site home page Giter Site logo

lvgl / lv_font_conv Goto Github PK

View Code? Open in Web Editor NEW
166.0 12.0 72.0 2.86 MB

Converts TTF/WOFF fonts to compact bitmap format

Home Page: https://lvgl.io/tools/fontconverter

License: MIT License

JavaScript 86.72% HTML 7.64% C 4.33% Dockerfile 0.60% Shell 0.71%
lvgl font ttf woff c conveter

lv_font_conv's Introduction

English | 中文 | Português do Brasil | 日本語


 

 

Light and Versatile Graphics Library

 

   

Website | Docs | Forum | Demos | Services


📒 Overview

Mature and Well-known
LVGL is the most popular free and open source embedded graphics library to create beautiful UIs for any MCU, MPU and display type. It's supported by industry leading vendors and projects like  Arm, STM32, NXP, Espressif, Nuvoton, Arduino, RT-Thread, Zephyr, NuttX, Adafruit and many more.

Feature Rich
It has all the features to create modern and beautiful GUIs: 30+ built-in widgets, a powerful style system, web inspired layout managers, and a typography system supporting many languages. To integrate LVGL into your platform, all you need is at least 32kB RAM and 128 kB Flash, a C compiler, a frame buffer, and at least an 1/10 screen sized buffer for rendering.

Services
Our team is ready to help you with graphics design, UI implementation and consulting services. Contact us if you need some support during the development of your next GUI project.

🚀 Features

Free and Portable

  • A fully portable C (C++ compatible) library with no external dependencies.
  • Can be compiled to any MCU or MPU, with any (RT)OS.
  • Supports monochrome, ePaper, OLED or TFT displays, or even monitors. Porting Guide
  • Distributed under the MIT license, so you can easily use it in commercial projects too.
  • Needs only 32kB RAM and 128 kB Flash, a frame buffer, and at least an 1/10 screen sized buffer for rendering.
  • OS, External memory and GPU are supported but not required.

Widgets, Styles, Layouts and more

  • 30+ built-in Widgets:  Button, Label, Slider, Chart, Keyboard, Meter, Arc, Table and many more.
  • Flexible Style system with  ~100 style properties to customize any part of the widgets in any state.
  • Flexbox and Grid-like layouts engines to automatically size and position the widgets in a responsive way.
  • Texts are rendered with UTF-8 encoding supporting CJK, Thai, Hindi, Arabic, Persian writing systems.
  • Word wrapping, kerning, text scrolling, sub-pixel rendering, Pinyin-IME Chinese input, Emojis in texts.
  • Rendering engine supporting animations, anti-aliasing, opacity, smooth scrolling, shadows, image transformation, etc  
  • Supports Mouse, Touchpad, Keypad, Keyboard, External buttons, Encoder Input devices.
  • Multiple display support.

Binding and Build Support

  • MicroPython Binding exposes LVGL API
  • PikaScript Binding python on MCU lighter and easier.
  • No custom build system is used. You can build LVGL as you build the other files of your project.
  • Support for Make and CMake is included out of the box.
  • Develop on PC and use the same UI code on embedded hardware.
  • Convert the C UI code to HTML file with our Emscripten port.

Docs, Tools, and Services

❤️ Sponsor

If LVGL saved you a lot of time and money or you just had fun using it, consider Supporting its Development.

How do we spend the donations?
Our goal is to provide financial compensation for people who do the most for LVGL. It means not only the maintainers but anyone who implements a great feature should get a payment from the accumulated money. We use the donations to cover our operational costs like servers and related services.

How to donate?
We use GitHub Sponsors where you can easily send one time or recurring donations. You can also see all of our expenses in a transparent way.

How to get paid for your contribution?
If someone implements or fixes an issue labeled as Sponsored he or she will get a payment for that work. We estimate the required time, complexity and importance of the issue and set a price accordingly. To jump in just comment on a Sponsored issue saying "Hi, I'd like to deal with it. This is how I'm planning to fix/implement it...". A work is considered ready when it's approved and merged by a maintainer. After that you can submit and expense at opencollective.com and you will receive the payment in a few days.

Organizations supporting LVGL
Sponsors of LVGL

Individuals supporting LVGL
Backers of LVGL

📦 Packages

LVGL is available as:

🤖 Examples

See some examples of creating widgets, using layouts and applying styles. You will find C and MicroPython code, and links to try out or edit the examples in an online MicroPython editor.

For more examples check out the Examples folder.

Hello world label

Simple Hello world label example in LVGL

C code
/*Change the active screen's background color*/
lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x003a57), LV_PART_MAIN);

/*Create a white label, set its text and align it to the center*/
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "Hello world");
lv_obj_set_style_text_color(label, lv_color_hex(0xffffff), LV_PART_MAIN);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
MicroPython code | Online Simulator
# Change the active screen's background color
scr = lv.screen_active()
scr.set_style_bg_color(lv.color_hex(0x003a57), lv.PART.MAIN)

# Create a white label, set its text and align it to the center
label = lv.label(lv.screen_active())
label.set_text("Hello world")
label.set_style_text_color(lv.color_hex(0xffffff), lv.PART.MAIN)
label.align(lv.ALIGN.CENTER, 0, 0)

Button with Click Event

LVGL button with label example

C code
lv_obj_t * button = lv_button_create(lv_screen_active());                   /*Add a button to the current screen*/
lv_obj_center(button);                                             /*Set its position*/
lv_obj_set_size(button, 100, 50);                                  /*Set its size*/
lv_obj_add_event_cb(button, button_event_cb, LV_EVENT_CLICKED, NULL); /*Assign a callback to the button*/

lv_obj_t * label = lv_label_create(button);                        /*Add a label to the button*/
lv_label_set_text(label, "Button");                             /*Set the labels text*/
lv_obj_center(label);                                           /*Align the label to the center*/
...

void button_event_cb(lv_event_t * e)
{
  printf("Clicked\n");
}
MicroPython code | Online Simulator
def button_event_cb(e):
  print("Clicked")

# Create a Button and a Label
button = lv.button(lv.screen_active())
button.center()
button.set_size(100, 50)
button.add_event_cb(button_event_cb, lv.EVENT.CLICKED, None)

label = lv.label(button)
label.set_text("Button")
label.center()

Checkboxes with Layout

Checkboxes with layout in LVGL

C code
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER);

lv_obj_t * cb;
cb = lv_checkbox_create(lv_screen_active());
lv_checkbox_set_text(cb, "Apple");
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);

cb = lv_checkbox_create(lv_screen_active());
lv_checkbox_set_text(cb, "Banana");
lv_obj_add_state(cb, LV_STATE_CHECKED);
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);

cb = lv_checkbox_create(lv_screen_active());
lv_checkbox_set_text(cb, "Lemon");
lv_obj_add_state(cb, LV_STATE_DISABLED);
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);

cb = lv_checkbox_create(lv_screen_active());
lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED);
lv_checkbox_set_text(cb, "Melon\nand a new line");
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
MicroPython code | Online Simulator
def event_handler(e):
    code = e.get_code()
    obj = e.get_target_obj()
    if code == lv.EVENT.VALUE_CHANGED:
        txt = obj.get_text()
        if obj.get_state() & lv.STATE.CHECKED:
            state = "Checked"
        else:
            state = "Unchecked"
        print(txt + ":" + state)


lv.screen_active().set_flex_flow(lv.FLEX_FLOW.COLUMN)
lv.screen_active().set_flex_align(lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER)

cb = lv.checkbox(lv.screen_active())
cb.set_text("Apple")
cb.add_event_cb(event_handler, lv.EVENT.ALL, None)

cb = lv.checkbox(lv.screen_active())
cb.set_text("Banana")
cb.add_state(lv.STATE.CHECKED)
cb.add_event_cb(event_handler, lv.EVENT.ALL, None)

cb = lv.checkbox(lv.screen_active())
cb.set_text("Lemon")
cb.add_state(lv.STATE.DISABLED)
cb.add_event_cb(event_handler, lv.EVENT.ALL, None)

cb = lv.checkbox(lv.screen_active())
cb.add_state(lv.STATE.CHECKED | lv.STATE.DISABLED)
cb.set_text("Melon")
cb.add_event_cb(event_handler, lv.EVENT.ALL, None)

Styling a Slider

Styling a slider with LVGL

C code
lv_obj_t * slider = lv_slider_create(lv_screen_active());
lv_slider_set_value(slider, 70, LV_ANIM_OFF);
lv_obj_set_size(slider, 300, 20);
lv_obj_center(slider);

/*Add local styles to MAIN part (background rectangle)*/
lv_obj_set_style_bg_color(slider, lv_color_hex(0x0F1215), LV_PART_MAIN);
lv_obj_set_style_bg_opa(slider, 255, LV_PART_MAIN);
lv_obj_set_style_border_color(slider, lv_color_hex(0x333943), LV_PART_MAIN);
lv_obj_set_style_border_width(slider, 5, LV_PART_MAIN);
lv_obj_set_style_pad_all(slider, 5, LV_PART_MAIN);

/*Create a reusable style sheet for the INDICATOR part*/
static lv_style_t style_indicator;
lv_style_init(&style_indicator);
lv_style_set_bg_color(&style_indicator, lv_color_hex(0x37B9F5));
lv_style_set_bg_grad_color(&style_indicator, lv_color_hex(0x1464F0));
lv_style_set_bg_grad_dir(&style_indicator, LV_GRAD_DIR_HOR);
lv_style_set_shadow_color(&style_indicator, lv_color_hex(0x37B9F5));
lv_style_set_shadow_width(&style_indicator, 15);
lv_style_set_shadow_spread(&style_indicator, 5);
4
/*Add the style sheet to the slider's INDICATOR part*/
lv_obj_add_style(slider, &style_indicator, LV_PART_INDICATOR);

/*Add the same style to the KNOB part too and locally overwrite some properties*/
lv_obj_add_style(slider, &style_indicator, LV_PART_KNOB);

lv_obj_set_style_outline_color(slider, lv_color_hex(0x0096FF), LV_PART_KNOB);
lv_obj_set_style_outline_width(slider, 3, LV_PART_KNOB);
lv_obj_set_style_outline_pad(slider, -5, LV_PART_KNOB);
lv_obj_set_style_shadow_spread(slider, 2, LV_PART_KNOB);
MicroPython code | Online Simulator
# Create a slider and add the style
slider = lv.slider(lv.screen_active())
slider.set_value(70, lv.ANIM.OFF)
slider.set_size(300, 20)
slider.center()

# Add local styles to MAIN part (background rectangle)
slider.set_style_bg_color(lv.color_hex(0x0F1215), lv.PART.MAIN)
slider.set_style_bg_opa(255, lv.PART.MAIN)
slider.set_style_border_color(lv.color_hex(0x333943), lv.PART.MAIN)
slider.set_style_border_width(5, lv.PART.MAIN)
slider.set_style_pad_all(5, lv.PART.MAIN)

# Create a reusable style sheet for the INDICATOR part
style_indicator = lv.style_t()
style_indicator.init()
style_indicator.set_bg_color(lv.color_hex(0x37B9F5))
style_indicator.set_bg_grad_color(lv.color_hex(0x1464F0))
style_indicator.set_bg_grad_dir(lv.GRAD_DIR.HOR)
style_indicator.set_shadow_color(lv.color_hex(0x37B9F5))
style_indicator.set_shadow_width(15)
style_indicator.set_shadow_spread(5)

# Add the style sheet to the slider's INDICATOR part
slider.add_style(style_indicator, lv.PART.INDICATOR)
slider.add_style(style_indicator, lv.PART.KNOB)

# Add the same style to the KNOB part too and locally overwrite some properties
slider.set_style_outline_color(lv.color_hex(0x0096FF), lv.PART.KNOB)
slider.set_style_outline_width(3, lv.PART.KNOB)
slider.set_style_outline_pad(-5, lv.PART.KNOB)
slider.set_style_shadow_spread(2, lv.PART.KNOB)

English, Hebrew (mixed LTR-RTL) and Chinese texts

English, Hebrew and Chinese texts with LVGL

C code
lv_obj_t * ltr_label = lv_label_create(lv_screen_active());
lv_label_set_text(ltr_label, "In modern terminology, a microcontroller is similar to a system on a chip (SoC).");
lv_obj_set_style_text_font(ltr_label, &lv_font_montserrat_16, 0);
lv_obj_set_width(ltr_label, 310);
lv_obj_align(ltr_label, LV_ALIGN_TOP_LEFT, 5, 5);

lv_obj_t * rtl_label = lv_label_create(lv_screen_active());
lv_label_set_text(rtl_label,"מעבד, או בשמו המלא יחידת עיבוד מרכזית (באנגלית: CPU - Central Processing Unit).");
lv_obj_set_style_base_dir(rtl_label, LV_BASE_DIR_RTL, 0);
lv_obj_set_style_text_font(rtl_label, &lv_font_dejavu_16_persian_hebrew, 0);
lv_obj_set_width(rtl_label, 310);
lv_obj_align(rtl_label, LV_ALIGN_LEFT_MID, 5, 0);

lv_obj_t * cz_label = lv_label_create(lv_screen_active());
lv_label_set_text(cz_label,
                  "嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
lv_obj_set_style_text_font(cz_label, &lv_font_simsun_16_cjk, 0);
lv_obj_set_width(cz_label, 310);
lv_obj_align(cz_label, LV_ALIGN_BOTTOM_LEFT, 5, -5);
MicroPython code | Online Simulator
ltr_label = lv.label(lv.screen_active())
ltr_label.set_text("In modern terminology, a microcontroller is similar to a system on a chip (SoC).")
ltr_label.set_style_text_font(lv.font_montserrat_16, 0);

ltr_label.set_width(310)
ltr_label.align(lv.ALIGN.TOP_LEFT, 5, 5)

rtl_label = lv.label(lv.screen_active())
rtl_label.set_text("מעבד, או בשמו המלא יחידת עיבוד מרכזית (באנגלית: CPU - Central Processing Unit).")
rtl_label.set_style_base_dir(lv.BASE_DIR.RTL, 0)
rtl_label.set_style_text_font(lv.font_dejavu_16_persian_hebrew, 0)
rtl_label.set_width(310)
rtl_label.align(lv.ALIGN.LEFT_MID, 5, 0)

font_simsun_16_cjk = lv.font_load("S:../../assets/font/lv_font_simsun_16_cjk.fnt")

cz_label = lv.label(lv.screen_active())
cz_label.set_style_text_font(font_simsun_16_cjk, 0)
cz_label.set_text("嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。")
cz_label.set_width(310)
cz_label.align(lv.ALIGN.BOTTOM_LEFT, 5, -5)

▶️ Get started

This list will guide you to get started with LVGL step-by-step.

Get Familiar with LVGL

  1. Check the Online demos to see LVGL in action (3 minutes)
  2. Read the Introduction page of the documentation (5 minutes)
  3. Get familiar with the basics on the Quick overview page (15 minutes)

Start to Use LVGL

  1. Set up a Simulator (10 minutes)
  2. Try out some Examples
  3. Port LVGL to a board. See the Porting guide or check the ready to use Projects

Become a Pro

  1. Read the Overview page to get a better understanding of the library (2-3 hours)
  2. Check the documentation of the Widgets to see their features and usage

Get Help and Help Others

  1. If you have questions go to the Forum
  2. Read the Contributing guide to see how you can help to improve LVGL (15 minutes)

🤝 Services

LVGL LLC was established to provide a solid background for LVGL library and to offer several type of services to help you in UI development. With 15+ years of experience in the user interface and graphics industry we can help you the bring your UI to the next level.

  • Graphics design Our in-house graphics designers are experts in creating beautiful modern designs which fit to your product and the resources of your hardware.
  • UI implementation We can also implement your UI based on the design you or we have created. You can be sure that we will make the most out of your hardware and LVGL. If a feature or widget is missing from LVGL, don't worry, we will implement it for you.
  • Consulting and Support We can support you with consulting as well to avoid pricey and time consuming mistakes during the UI development.
  • Board certification For companies who are offering development boards, or production ready kits we do board certification which shows how board can run LVGL.

Check out our Demos as reference. For more information take look at the Services page.

Contact us and tell how we can help.

🌟 Contributing

LVGL is an open project and contribution is very welcome. There are many ways to contribute from simply speaking about your project, through writing examples, improving the documentation, fixing bugs or even hosting your own project under the LVGL organization.

For a detailed description of contribution opportunities visit the Contributing section of the documentation.

More than 300 people already left their fingerprint in LVGL. Be one them! See you here! 🙂

... and many other.

lv_font_conv's People

Contributors

deltoro05 avatar dependabot[bot] avatar embeddedt avatar kisvegabor avatar maldus512 avatar neuschaefer avatar niklasf avatar puzrin avatar rlidwka avatar sunzigang avatar treitmayr avatar viatorus avatar xiaoxiang781216 avatar xingrz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lv_font_conv's Issues

Postponed

This is cemetery area for ideas :).

  • Ligatures support. Current options do no allow to define those. Font format also does not support ligatures. Since LVGL has a restricted unicode implementation, this is not critical.

Option to define `lvgl.h` path

https://github.com/littlevgl/lvgl/blob/master/src/lv_font/lv_font_roboto_12.c#L1

Currently path to lvgl.h in font file is hardcoded. That's not convenient for outer fonts. For example, i have to fix path with sed in my projects. Can we have something more comfortable? For example, i could add option to define alternate path.

Questions:

  • Do you think this needs fix at all?
  • Is it possible to fix issue without new option?
  • If new option is the only choice, what is the good name? --lvglh looks a bit strange for me (but i'll be ok with it).

/cc @kisvegabor, @embeddedt

Decompression

I've started work on decompression and it's working without prefiltering.

Problems and questions:

  1. bitmap_format is missing from font_dsc. Possible values are here. (prefiltered option should be added to the enum)
  2. It's not clear how prefiltering works. It's ok with bpp = 8 but how do you handle line ending (or even byte ending) with bpp = 2,3,4?

Cpp compiler error with lvgl version 8.x

In the generated font source files, there is a section:

#if LV_VERSION_CHECK(7, 4, 0) 
    .underline_position = -1,
    .underline_thickness = 1,
#endif

This block evaluates to true on versions 7.4.0 or higher, but is false on versions from 8.0.0 or higher (different major version).

With lvgl version 8, if the file is compiled as cpp, the order of the fields becomes non-sequential and the compiler throws an error:

Compiling .pio/build/d1-mini-esp32_ili9341/src/font/latin1/robotocondensed_regular_16_latin1.cpp.o
src/font/latin1/robotocondensed_regular_16_latin1.cpp:2583:1: sorry, unimplemented: non-trivial designated
initializers not supported
*** [.pio/build/d1-mini-esp32_ili9341/src/font/latin1/robotocondensed_regular_16_latin1.cpp.o] Error 1
========================================= [FAILED] Took 4.83 seconds =========================================

If I change the #if block to include v8 then that font file compiles fine, because the fields are sequential again:

#if LV_VERSION_CHECK(7, 4, 0) || LV_VERSION_CHECK(8, 0, 0)
    .underline_position = -1,
    .underline_thickness = 1,
#endif

Would it be possible to add the || LV_VERSION_CHECK(8, 0, 0) to this check so the source files compile without change in v8 using cpp ?

Platform:

PLATFORM: Espressif 32 (3.3.0) > WeMos D1 MINI ESP32
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 3.10006.210326 (1.0.6) 
 - tool-esptoolpy 1.30100.210531 (3.1.0) 
 - toolchain-xtensa32 2.50200.97 (5.2.0)

Issue with missing subpixel3 element in index.js in online font converter

I've been using the online font converter the last few days. This morning, using the same workflow as before, I cannot get it to convert a font. When I press the Convert button nothing happens. I've tried Chrome 85.0.4183.121 and Firefox 81.0.

Chrome developer tools reports an exception on line 110 of index.js:

lcd_v: document.getElementById('subpixel3').checked,

It appears that the element subpixel3 does not exist.

Not sure if it's relevant, but there is also a report of a problem with a missing font:

https://lvgl.io/tools/assets/fonts/Montserrat-Regular.ttf

It's a great utility, and has been very easy to use, so perhaps it's something I'm doing wrong.

Many thanks!

lv_font_conv TypeError: this.src.glyphs.map(...).flat is not a function

I have following problem trying to play with lv_font_conv:

  1. Download last revision from github:
    git clone https://github.com/lvgl/lv_font_conv.git
  2. Download libraries:
    npm install
  3. Run lv_font_conv with following command line:
    node lv_font_conv --no-compress --no-prefilter --bpp 4 --size 12 --font Montserrat-Medium.ttf -r 0x20-0x7F,0xB0,0x2022 --format lvgl -o ./lv_font_montserrat_12.c --force-fast-kern-format

(with standard lvgl Montserrat-Medium.ttf font file

Get following error:

TypeError: this.src.glyphs.map(...).flat is not a function
at new Font (/home/screep/lvgl/lv_font_conv/lib/font/font.js:38:99)
at new LvFont (/home/screep/lvgl/lv_font_conv/lib/writers/lvgl/lv_font.js:16:5)
at Object.write_images [as lvgl] (/home/screep/lvgl/lv_font_conv/lib/writers/lvgl/index.js:12:16)
at convert (/home/screep/lvgl/lv_font_conv/lib/convert.js:25:35)

Could you please give me any ideas how to fix it?

PS:
node -v
v10.15.3

Thank you in advance

Looking forward for your reply

Fix lvgl.h include

Fix the file headers to match convention:

#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include <lvgl.h>
#else
#include <lvgl/lvgl.h>
#endif

Bug: CLI Font Convertor?

When I use the online font converter tool [1] (Figure 1), our test code is successful show the text content (Figure 2). But when I use the lv_font_conv, our test is not show text content (Figure 3).

I use the Roboto-Regular.ttf [2].

env DEBUG=* ./lv_font_conv.js --font Roboto-Regular.ttf --symbols 0123456789abcdefABCDEF --size 20 --format lvgl --bpp 2 -o roboto.c
  font last_id: 23 +0ms
  font minY: -1 +3ms
  font maxY: 16 +0ms
  font glyphIdFormat: 0 +0ms
  font kerningScale: 1 +1ms
  font advanceWidthFormat: 1 +0ms
  font xy_bits: 2 +0ms
  font wh_bits: 5 +0ms
  font advanceWidthBits: 9 +1ms
  font monospaced: false +0ms
  font indexToLocFormat: 0 +6ms
  font.table.kern 5 kerned glyphs of 22, 5 max list, 14 total pairs +0ms
  font.table.kern table format0 size = 48 +1ms
  font.table.kern unique left classes: 5 +1ms
  font.table.kern unique right classes: 5 +0ms
  font.table.kern table format3 size = 76 +3ms
  font.table.cmap 3 subtable(s): 0 "format 0", 3 "sparse" +0ms
  font.table.cmap table size = 60 +0ms
  font.table.kern 5 kerned glyphs of 22, 5 max list, 14 total pairs +2ms
  font.table.kern table format0 size = 48 +0ms
  font.table.kern unique left classes: 5 +0ms
  font.table.kern unique right classes: 5 +0ms
  font.table.kern table format3 size = 76 +0ms

Where do I make a mistake?

Note: I cannot install the lv_font_conv script. I'll create a new issue ASAP.

Test Code

void lv_tutorial_fonts(void)
{
    /*Create a style and use the new font*/
    static lv_style_t style1;
    lv_style_copy(&style1, &lv_style_plain);
    style1.text.font = &roboto;

    /*Create a label and set new text*/
    lv_obj_t * label = lv_label_create(lv_disp_get_scr_act(NULL), NULL);
    lv_obj_set_pos(label, 10, 10);
    lv_label_set_style(label, LV_LABEL_STYLE_MAIN, &style1);
    lv_label_set_text(label, "abAB12");
}

📷 Screenshots

Figure 1: The online font converter form
image

Figure 2: The online font converter result
2019-07-04 12-06-43 ekran görüntüsü

Figure 3: The lv_font_conv result
2019-07-04 12-03-15 ekran görüntüsü

📋 Reference

  1. https://littlevgl.com/font_conv_new
  2. https://raw.githubusercontent.com/google/fonts/master/apache/roboto/Roboto-Regular.ttf

How to use in node.js instead of CLI

I see the code as below in index.js file under web dir, could I call them in web directly?

const args = {
    font: fonts,
    size: parseInt(_size, 10),
    bpp: parseInt(_bpp, 10),
    no_compress : !(document.getElementById('compression').checked),
    lcd: document.getElementById('subpixel2').checked,
    lcd_v: document.getElementById('subpixel3').checked,
    format: 'lvgl',
    output: _name
  };

  convert(args).then(result => {
    const blob = new Blob([ result[_name] ], { type: 'text/plain;charset=utf-8' });

    FileSaver.saveAs(blob, _name + '.c');
  }).catch(err => {
    /*eslint-disable no-alert*/
    // Try to beautify normal errors
    if (err instanceof AppError) {
      alert(err.message.trim());
      return;
    }

    alert(err);

    /* eslint-disable no-console */
    console.error(err);
  });

Error: error in FT_New_Memory_Face: 2

Currently a WOFF I made (pixel-perfect symbols that were crappily made in FontForge for a low res monochrome oled display. Only reason I'm saying this is that there might be errors within the font like self-intersecting symbols) no longer works using the online font converter. This same WOFF file worked previously (I believe I last used the converter on Aug 17, 2019).

Settings:
Name: jolt_symbols
Size: 8
Bpp: 1
Compression? yes
Range: 0xF000-0xF00D

WOFF file (zipped for GitHub compatibility)
jolt_symbols_old.zip

The popup error dialog says "Error: error in FT_New_Memory_Face: 2"

I cannot install the lv_font_conv script

I used it before but I'm not very familiar nodejs, npm etc.

Try 1:

$ npm i lv_font_conv -g
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/lv_font_conv - Not found
npm ERR! 404 
npm ERR! 404  'lv_font_conv@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2019-07-04T09_48_47_767Z-debug.log

Try 2:

$ npm i littlevgl/lv_font_conv -g
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR!   stack: "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/seyyah/.npm/_logs/2019-07-04T09_50_17_836Z-debug.log

Try 3:

Firstly I fix EACCESS issue,

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

And then

$ npm i littlevgl/lv_font_conv -g
/usr/local/bin/lv_font_conv -> /usr/local/lib/node_modules/lv_font_conv/lv_font_conv.js

> [email protected] install /usr/local/lib/node_modules/lv_font_conv/node_modules/canvas
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download
# <<< LONG TIME WAIT THIS LINE AND DO NOT CONTINUE >>>>

Environment

$ nodejs -v
v10.16.0
$ npm -v
6.9.0
$ node -v
v12.5.0

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.10
Release:        18.10
Codename:       cosmic

📋 Reference

  1. https://stackoverflow.com/questions/25290986/how-to-fix-eacces-issues-with-npm-install/29787931

Check for very large fonts

Hi,

Right now there is an LV_FONT_FMT_TXT_LARGE switch in LVGL to choose between a more compact description of glyphs or a larger one for large fonts.

It was already reported several times that LVGL is not working with large fonts but only LV_FONT_FMT_TXT_LARGE needed to be enabled.

I wonder if we could do a check in the generated fonts like:

#if (LV_FONT_FMT_TXT_LARGE == 0)
# error "Too large font or glyphs in <font_name>. Enable LV_FONT_FMT_TXT_LARGE in lv_conf.h")
#endif

These line neds to added if

bitmap_array_size >= 1024 * 1024
any adv_w > 4096
any abs(ofs_x) or abs(ofs_y) > 127
any box_w or box_h > 255 

Let me know what you think.

Fails for sizes greater than 28

Hi,

I wanted to convert font Titillium Web of size 33 with range 0x20 - 0x17F and it failed. I noticed that it works for sizes <= 28.
Next i tried using converter offline so I installed it and called
lv_font_conv --font Titillium_Web/TitilliumWeb-Regular.ttf --r 0x20-0x17F --bpp 4 --size 33 --format lvgl -o titillium_33.c

Command failed as before.
This is an output

/usr/lib/node_modules/lv_font_conv/lv_font_conv.js:17
  throw err;
  ^

RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -128 and <= 127. Received -148
    at writeU_Int8 (internal/buffer.js:572:11)
    at Buffer.writeInt8 (internal/buffer.js:703:10)
    at LvKern.create_format0_data (/usr/lib/node_modules/lv_font_conv/lib/font/table_kern.js:74:18)
    at LvKern.should_use_format3 (/usr/lib/node_modules/lv_font_conv/lib/font/table_kern.js:211:31)
    at LvKern.toLVGL (/usr/lib/node_modules/lv_font_conv/lib/writers/lvgl/lv_table_kern.js:105:16)
    at LvFont.toLVGL (/usr/lib/node_modules/lv_font_conv/lib/writers/lvgl/lv_font.js:55:13)
    at Object.write_images [as lvgl] (/usr/lib/node_modules/lv_font_conv/lib/writers/lvgl/index.js:15:25)
    at convert (/usr/lib/node_modules/lv_font_conv/lib/convert.js:26:35)
    at Object.module.exports.run (/usr/lib/node_modules/lv_font_conv/lib/cli.js:303:15)
    at Object.<anonymous> (/usr/lib/node_modules/lv_font_conv/lv_font_conv.js:8:24)

When I try with size 28 it does everything as expected. But with 29 it fails for same reason.
Thanks in advance

Glyphs quality

Hi @puzrin,

First of all, congratulations for the great job done with de font converter 😉.

I was migrating from LittlevGL v5.3 to LittlevGL v6.0 and found some issues discussed here.

I already understood more or less the stuff related with new paradigma. Whichever, the thing I am worry about is the quality of the glyphs with new font converter.

As I show in this post, there is a bit lost in glyph quality. I guess is not about the new font converter at all but for the method of getting the .ttf into image.

What do you think? It might be an special case, but is important on my project.

Do you know if is there any possibility to use the method used in LittlevGL v5.3 just for getting the glyphs images?

Thanks in advance

Online test

As proof of concept, I'd like to test the converter running on a website. I mean something very basic: one button which triggers some hardcoded operation with hardcoded settings.
The goal would be to see that the converter really can run in a browser.

Could you help how to do this? Or does it require modifications on the script?

font conver

Perform all steps below and tick them with [x]

  • Check the related part of the Documentation
  • Update lvgl to the latest version
  • Reproduce the issue in a Simulator

Describe the bug

​ Garbled characters in the offline font conversion tool

  1. The converted output_roboto_r.c internal font display is normal, and the converted output_roboto_r.font external font display shows garbled characters;
  2. problem analysis:
    Use lvgl\tests\lv_test_core\lv_test_font_loader.c to compare the internal and external font libraries between the output_roboto_r.c file and output_roboto_r.font file;
    • It is analyzed that the adv_w parameter has different values in the output_roboto_r.c and output_roboto_r.font files;
  3. Convert output_roboto_r.c internal font command:
    lv_font_conv --font Roboto-Regular.ttf -r 0x20-0x7F -r 0x401,0x410-0x44F,0x451 --size 16 --format lvgl --bpp 4 --no-compress -o output_roboto_r.c
  4. Convert output_roboto_r.font external font library command:
    lv_font_conv --font Roboto-Regular.ttf -r 0x20-0x7F -r 0x401,0x410-0x44F,0x451 --size 16 --format bin --bpp 4 --no-compress -o output_roboto_r.font
  5. See the attachment for the converted font file;
  6. Please help analyze what caused the converted output_roboto_r.font to display garbled characters;

To Reproduce

  1. Convert output_roboto_r.c and output_roboto_r.font through the font conversion command, and compare them with the lv_test_font_loader tool;

Expected behavior

  1. It is expected that the converted external font library can be displayed normally;

Screenshots or video

  1. Use the lv_test_font_loader tool to compare adv_w screenshots with different values for internal and external fonts.

scr_font

2.See the attachment for the converted font file.

converted_font_file.zip

no such file or directory? Can't open the font file.

I place the font file WeiRuanYaHei-1.ttf at the same folder with lv_font_conv.js and run lv_font_conv --bpp 4 --size 16 --format bin --font WeiRuanYaHei-1.ttf -r 0x4e00 then lv_font_conv.js: error: Cannot read file "WeiRuanYaHei-1.ttf": ENOENT: no such file or directory, open 'WeiRuanYaHei-1.ttf'
Am I using it the wrong way?
I'm runing it on windows

Show error message in the online converter

Hi,

I'd like to display an alert if the converter finds an error, like "Font "TAHOMA.TTF" doesn't have any characters included in range 0xe80-0xeff".

Is there a way to get the error message printed into the console?

Subpx rendering in v7

I can see that converting TTF fonts with subpx rendering is only available for lvgl v6.0 - is that correct?

lv_table_head.js, lines 73-75 :

#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0)
.subpx = ${subpixels},
#endif

Using LVGL v7 and setting .subpx to anything different than LV_SUBPX_NONE produces bad results on the display with both

#define LV_FONT_SUBPX_BGR 1

and

#define LV_FONT_SUBPX_BGR 0

Pending issues in 0.2.0 (FreeType) version

This version is currently in dev branch. Please, post here all found bugs.

  • All previously reported "broken" fonts should work now.
  • Better look for many fonts (forced hinting)
  • May be... even better look for monochrome output (special monochrome hinter used)

Pending things are internal, not visible to end users:

  • Code cleanup, drop opentype.js use everywhere
  • Review FreeType calls, is anyone has experience
  • Improve build scripts for FreeType (current ones are ugly)

lvgl writer issues

  1. The lines of uncompressed bitmaps should be byte aligned
  2. Minor typos in the generated file. See this
  3. Kern pair descriptor is updated to accept pairs with 1 and 2 byte size
  4. It seems the bitmaps are stored from bottom to top (should be top->bottom):

Explanations for bitmap direction:
'!' is (here):

0xd0, 0xff, 0xfc,

In binary:

1101 0000
1111 1111
1111 1100

As '!' has box_w = 2 (here) I suppose it is:

XX
 X

XX
XX
XX
XX
XX
XX
XX

So it seems upside down.

Reduce npm bundle size

In 1.2.0, after all deps bundled into npm package, npx lv_font_conv -h runs MUCH faster.

  • 3s for first run
  • 1.8s for next immediate run

Probably, this an be better, if reduce bundle size/content. Quick investigation (via npm pack):

  • 1600К - current
  • 973К - remove openype.js unused files
  • 651К - if rewrite to not use lodash
  • 590К - drop pngjs garbage

Roadmap

Current convertor implements "reader" and "dumper". Now users can focus on creating "writers", without learning vector fonts details.

To make things useable (with new features), it worth to implement this steps:

  • Create new font specification
  • Investigate compressions (need binary writer)
  • Create writer for LVGL 6.0

Note, i'm interested only to investigate compressions. As a side effect - create font spec.

Subpixel additions cause compilation errors for v6.0 users

The new .subpx value added to the font descriptor doesn't exist in v6.0.x, nor do the LV_FONT_SUBPX_* defines, leading to a build error whenever a new font is generated and included.

I've been able to work around this issue by adding a version check macro around the .subpx definition in the font c file:

#if LV_VERSION_CHECK(6,1,0)
    .subpx = LV_FONT_SUBPX_NONE,
#endif

lv_table_head.js L73 could be modified to always include this version check on newly generated fonts, providing a permanent backward-compatible solution:
https://github.com/littlevgl/lv_font_conv/blob/26040af79b4f0d4738025dbe45086700bda096b0/lib/writers/lvgl/lv_table_head.js#L73

lvgl include directive

The exported font.c file refers to lvgl.h as
#include "lvgl/lvgl.h"
Since user will insert this file under the lvgl/src/lv_fon, the correct way to include is:
#include "../lvgl.h"

I had to do this manually otherwise it wont compile.

Backwards compatibility issue with C++ compilation

Issue Description

Some older versions of C++ compilers require that structs be initialized in the same order that they are declared. The current version of lv_font_conv generates .c font files that have some structs that do not meet his criteria.

Indicative Error

Compilation crashes with this error message:
sorry, unimplemented: non-trivial designated initializers not supported

Issue example

Struct declaration from lv_font.h in the LittlevGL library:

{
    uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */
    uint8_t box_w;  /**< Width of the glyph's bounding box*/
    uint8_t box_h;  /**< Height of the glyph's bounding box*/
    int8_t ofs_x;   /**< x offset of the bounding box*/
    int8_t ofs_y;  /**< y offset of the bounding box*/
    uint8_t bpp;   /**< Bit-per-pixel: 1, 2, 4, 8*/
}lv_font_glyph_dsc_t;

An example of the same struct that is generated in a font file by the current version of lv_font_conv:

static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
    {.bitmap_index = 0, .adv_w = 0, .box_h = 0, .box_w = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,
    {.bitmap_index = 0, .adv_w = 99, .box_h = 0, .box_w = 0, .ofs_x = 0, .ofs_y = 0},
    {.bitmap_index = 0, .adv_w = 70, .box_h = 15, .box_w = 3, .ofs_x = 1, .ofs_y = 0},
    {.bitmap_index = 6, .adv_w = 119, .box_h = 5, .box_w = 6, .ofs_x = 1, .ofs_y = 10},
    {.bitmap_index = 10, .adv_w = 255, .box_h = 15, .box_w = 16, .ofs_x = 0, .ofs_y = 0},
    {.bitmap_index = 40, .adv_w = 252, .box_h = 18, .box_w = 15, .ofs_x = 1, .ofs_y = -2},
    {.bitmap_index = 74, .adv_w = 309, .box_h = 15, .box_w = 17, .ofs_x = 1, .ofs_y = 0},
    {.bitmap_index = 106, .adv_w = 300, .box_h = 15, .box_w = 18, .ofs_x = 1, .ofs_y = 0},
   ..................
   ..................
}

Notice that: The .box_h and .box_w parameters in the generated struct are out of order with the struct declaration in lv_font.h

Suggested fix

There are 3 files in the lv_font_conv project that are responsible for generating the affected structs found in the font file:

  1. lv_table_cmap.js
  2. lv_table_glyf.js
  3. lv_table_head.js

The affected structs are:

  1. lv_font_fmt_txt_glyph_dsc_t
  2. lv_font_fmt_txt_cmap_t
  3. lv_font_fmt_txt_kern_pair_t
  4. lv_font_fmt_txt_dsc_t
  5. lv_font_t example_font

Fix example

From lv_table.glyf.js

  to_lv_glyph_dsc() {
    this.lv_compile();

    /* eslint-disable max-len */

    let result = [ '    {.bitmap_index = 0, .adv_w = 0, .box_h = 0, .box_w = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */' ];

    this.lv_data.forEach(d => {
      const idx = d.offset,
            adv_w = Math.round(d.glyph.advanceWidth * 16),
            h = d.glyph.bbox.height,
            w = d.glyph.bbox.width,
            x = d.glyph.bbox.x,
            y = d.glyph.bbox.y;
      result.push(`    {.bitmap_index = ${idx}, .adv_w = ${adv_w}, .box_h = ${h}, .box_w = ${w}, .ofs_x = ${x}, .ofs_y = ${y}}`);
    });

    return result.join(',\n');
  }

should become:

  to_lv_glyph_dsc() {
    this.lv_compile();

    /* eslint-disable max-len */

    let result = [ '    {.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */' ];

    this.lv_data.forEach(d => {
      const idx = d.offset,
            adv_w = Math.round(d.glyph.advanceWidth * 16),
            h = d.glyph.bbox.height,
            w = d.glyph.bbox.width,
            x = d.glyph.bbox.x,
            y = d.glyph.bbox.y;
      result.push(`    {.bitmap_index = ${idx}, .adv_w = ${adv_w}, .box_w = ${h}, .box_h = ${w}, .ofs_x = ${x}, .ofs_y = ${y}}`);
    });

    return result.join(',\n');
  }

Reproduction and conclusion

I am using g++ as a C++ compiler:
Target: x86_64-linux-gnu
gcc version: 7.4.0

Apparently newer versions of the g++ compiler allow out-of-order struct initialization. I seem to remember seeing version 8.0.0 and newer supports that.
However, many hardware projects have version constraints: for example I can only use 7.4.0. It would be a good idea to make this fix for backwards-compatibility's sake. I would do it myself but there are legal issues that prevent me from doing so. Hopefully I have given enough information for it to be an easy fix for whoever picks it up.

Crash on big --size

./lv_font_conv.js --font node_modules/roboto-fontface/fonts/roboto/Roboto-Regular.woff --bpp 3 --size 160 --format bin -r 0x20-0x7F -o t.bin

RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 65535. Received 66112

With --no-compress starts failing on smaller sizes.

AFAIK we have no hardcoded limits, the only restriction is 65536 total glyphs.

Force kern classes

Hi,

Is there a way to force the use of kern classes?
I've found that it's 20% to render text with kern classes compared to kern pairs.

CLI spec

Font params are grouped to current font until new font option found.

Common:

  • -s - output font size
  • -o - output file path
  • -b, --bpp - bits per pixel
  • -c, --compress - 'auto', compression algorythm (TBD)
    • RLE in general, but details depent on bpp & font size
  • --format - output format, useful for debug & experiments
    • json - intermediate, to connect loader and writers
    • images - write each glyph to separate file, useful to check result.
    • TBD

Fonts:

  • --font - local path or URL (may be used multiple times)
  • -r - single glyph or range, + optional mapping; belongs to previously declared --font)
    • -r 0x1F450 - single value, dec or hex format
    • -r 0x1F450-0x1F470 - range
    • -r 0x1F450=>0xF005 - single glyph with mapping
    • -r 0x1F450-0x1F470=>0xF005 - range with mapping
  • --symbols - list of characters to copy (instead of numeric format in -r)

Codepoint delta out of range

Goal

We're trying to create an lvgl font with material design icons instead of fontawesome.
All MDI icons are in "Unicode Plane 15 Private Use, First" with glyph ids 0xF0000-0xF1743.

Font files:

Observation

Depending on the range of characters selected, the Error: Codepoint delta out of range is displayed.
The same occurs in the online font converter as offline npm package.

Problem

It seems the problem lies with the cmap_split function that only takes the number of (consecutive) glyphs into account for sparse ranges and not the gap between the glyphs.

Workaround

If I place a small range of characters before the MDI icons, an extra index with format0_tiny is created.
The MDI icons then start with their own sparse_tiny index and a starting_index of 0xF0045.

Examples

This works:

lv_font_conv --font RobotoCondensed-Regular.ttf -r 0x20-0x7F,0xB7-0xBF --font materialdesignicons-webfont.ttf -r 0xF0045,0xF004D,0xF0054 --size 12 --format bin --bpp 3 -o output.font

start 104 - end 106 - dist 54 sparse_tiny
start 95 - end 103 - dist 32 format0_tiny
start 0 - end 94 - dist 16 format0_tiny

This doesn't work:

lv_font_conv --font RobotoCondensed-Regular.ttf -r 0x20-0x7F,0xB8-0xBF --font materialdesignicons-webfont.ttf -r 0xF0045,0xF004D,0xF0054 --size 12 --format bin --bpp 3 -o output.font

start 95 - end 105 - dist 54 sparse_tiny
start 0 - end 94 - dist 16 format0_tiny
Error: Codepoint delta out of range
    at Cmap.collect_sparse_data (/usr/local/lib/node_modules/lv_font_conv/lib/font/table_cmap.js:154:55)
    at Cmap.create_sparse_tiny_data (/usr/local/lib/node_modules/lv_font_conv/lib/font/table_cmap.js:177:23)
    at Cmap.compile (/usr/local/lib/node_modules/lv_font_conv/lib/font/table_cmap.js:61:33)
    at Cmap.toBin (/usr/local/lib/node_modules/lv_font_conv/lib/font/table_cmap.js:183:30)
    at Font.toBin (/usr/local/lib/node_modules/lv_font_conv/lib/font/font.js:118:17)
    at Object.write_images [as bin] (/usr/local/lib/node_modules/lv_font_conv/lib/writers/bin.js:15:25)
    at convert (/usr/local/lib/node_modules/lv_font_conv/lib/convert.js:25:35)
    at async Object.module.exports.run (/usr/local/lib/node_modules/lv_font_conv/lib/cli.js:300:15)

Conclusion

The 0xB7-0xBF or 0xB8-0xBF block determines wheter the conversion succeeds or fails.

It would be nice if the cmap_split function automatically adds an intermediate sparse list if the delta between glyphs is larger then 65535.

run on windows

The lv_font_conv application only works on linux?
Everything works fine on linux, but I try run on windows and have problems.

Does the application have dependencies that require the Linux operating system?

Investigate compressions

Need to investigate possible benefits of compression use.

Criterias

  • Base level to compare: uncompressed data, but with cropped bitmaps.
  • "Settings menu" with Material Design theme should fit into 128K stm32f0
  • Smoothness requirement: 2-3 bpp
  • Don't care about small 1 bpp font size for bi-tonal OLED-s.

Algorythms

  • I3BN (RLE), restricted to "white" or "white" + "black" only. Should be very simple and effective
    • For low bpp - additionally restrict with minimal required repeat count
  • Filtering
    • Lines delta coding. May help in some cases. For effective implementation - align output lines to word, and apply binary XOR
    • BWT (just for fun). Decoder requires additional memory to sort data.

This combinations should give optimal balance between compression ratio and hardware requirements.

Discrepancies on 'Glyph advanceWidth bits length' in 'head' table and value in 'glyf' table

My first tryings with the binary format were with UniFont.
It's a monospaced font.
lv_font_conv --font unifont-13.0.03.ttf -r 0x020-0x03F --size 12 --no-compress --format bin --bpp 1 -o ./bin/font_20-3f.bin

As this is a monospaced font, according the source in table_heads.js (line 84-85) a value of 0 is issued for Glyph advanceWidth bits length.
Although within the program the variable f.advanceWidthBits is set to 4 (debug output shows it).
In table 'glyf' the 'glyph data' starts with four bits for the advanceWidth value (four bits are always 0x6). The other values BBox X, etc. (according the specification) are alright and match the values which are issued within the lvgl C-format ().

On the other hand, the value for glyph_dsc[].adv_w within the lvgl C-format shows a 96 (0x60) on every entry (except for special entry 0 of course).

Desired features

  • Allow define fonts by URL.
    • we need Roboto for Material UI.
    • it's convenient to not store local copies of binaries
    • google's fonts is nice source for start
  • Allow specify font params (size, weight, italic, ...)
  • Specify glyphs
    • single glyphs (multiple times)
      • remapping (how?)
    • numeric range (multiple times)
      • remapping (how?)
    • named set (usually by language - acsii, simplified chinese)
  • [reserved] should be able to process kerning table & drop unused data
  • Easy to install & web support
    • node.js + webpack or parcel.js
  • Possibility to process glyph lists from lv_i18n
    • probably not direct part of this script, but we should verify possibility of this use case.
  • As usually, should allow read options from file.

Later:

  • Compression. Need to experiment with algorythms. But we need basic tool implementation to start.

Two TTF merge issue

Text

run 中文你好速度过快及时打款过来就可怜见 the test!\xEF\x8A\x87

image


The lost icon

image


configuration

image

temp.zip

Make fonts const in lvgl format

As discussed here the lvgl fonts could be const with a few modifications.

@puzrin If you have some time could you modify the end of the generated fonts like this?
See the parts added with #if LV_VERSION_CHECK(8, 0, 0).

/*--------------------
 *  ALL CUSTOM DATA
 *--------------------*/
#if LV_VERSION_CHECK(8, 0, 0)
/*Store all the custom data of the font*/
static  lv_font_fmt_txt_glyph_cache_t cache;
static const lv_font_fmt_txt_dsc_t font_dsc = {
#else
static lv_font_fmt_txt_dsc_t font_dsc = {
#endif
    .glyph_bitmap = gylph_bitmap,
    .glyph_dsc = glyph_dsc,
    .cmaps = cmaps,
    .kern_dsc = &kern_classes,
    .kern_scale = 16,
    .cmap_num = 2,
    .bpp = 4,
    .kern_classes = 1,
    .bitmap_format = 0,
#if LV_VERSION_CHECK(8, 0, 0)
    .cache = &cache
#endif
};

/*-----------------
 *  PUBLIC FONT
 *----------------*/

/*Initialize a public general font descriptor*/
#if LV_VERSION_CHECK(8, 0, 0)
const lv_font_t lv_font_montserrat_14 = {
#else
lv_font_t lv_font_montserrat_14 = {
#endif
    .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt,    /*Function pointer to get glyph's data*/
    .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt,    /*Function pointer to get glyph's bitmap*/
    .line_height = 16,          /*The maximum line height required by the font*/
    .base_line = 3,             /*Baseline measured from the bottom of the line*/
#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0)
    .subpx = LV_FONT_SUBPX_NONE,
#endif
#if LV_VERSION_CHECK(7, 4, 0)
    .underline_position = -1,
    .underline_thickness = 1,
#endif
    .dsc = &font_dsc           /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
};

Export data for underline

Based on lvgl/lvgl#1618 (comment)

FreeType can tell where to place the underline of a text and how thick it should be. See here.

It'd be great to add this info to the font descriptors like this:

/*Initialize a public general font descriptor*/
lv_font_t lv_font_montserrat_12 = {
    .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt,    /*Function pointer to get glyph's data*/
    .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt,    /*Function pointer to get glyph's bitmap*/
    .line_height = 15,          /*The maximum line height required by the font*/
    .base_line = 3,             /*Baseline measured from the bottom of the line*/
#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0)
    .subpx = LV_FONT_SUBPX_NONE,
#endif
#if LV_VERSION_CHECK(7, 2, 0)
    .underline_ofs = 3,
    .underline_tickness = 2,
#endif
    .dsc = &font_dsc           /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
};

Support 8 bpp

Hi,

How difficult would it be to support 8 bpp?
It's not reasonable for "normal" texts, but 8bpp could be used nicely for masking if the letters are considered as alpha maps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.