Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put the font data in the const area #14

Closed
sago35 opened this issue Jun 8, 2020 · 4 comments
Closed

Put the font data in the const area #14

sago35 opened this issue Jun 8, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@sago35
Copy link
Member

sago35 commented Jun 8, 2020

The current dev branch code has font data in RAM.
This makes it very RAM intensive.

This issue shows how to put the font data in const, which will be done in the future.
It will also allow you to put it in spi flash afterwards.

I plan to put out a PR once I get my code together.
The PR will replace all existing fonts.

before:

var NotoEmojiRegular12pt = tinyfont.Font{
	Glyphs: []tinyfont.Glyph{
		/*  */ tinyfont.Glyph{Rune: 0x0, Width: 0x0, Height: 0x0, XAdvance: 0x10, XOffset: 0, YOffset: 0, Bitmaps: []uint8{}},
		/*  */ tinyfont.Glyph{Rune: 0xd, Width: 0x0, Height: 0x0, XAdvance: 0x10, XOffset: 0, YOffset: 0, Bitmaps: []uint8{}},
		/*   */ tinyfont.Glyph{Rune: 0x20, Width: 0x0, Height: 0x0, XAdvance: 0x10, XOffset: 0, YOffset: 0, Bitmaps: []uint8{}},
		/* # */ tinyfont.Glyph{Rune: 0x23, Width: 0xa, Height: 0xc, XAdvance: 0x10, XOffset: 3, YOffset: -11, Bitmaps: []uint8{0x19, 0x86, 0x41, 0x13, 0xff, 0x13, 0xc, 0xc3, 0x23, 0xff, 0x22, 0x9, 0x82, 0x61, 0x90}},
		/* 0 */ tinyfont.Glyph{Rune: 0x30, Width: 0x8, Height: 0xc, XAdvance: 0x10, XOffset: 4, YOffset: -10, Bitmaps: []uint8{0x3c, 0x66, 0xc2, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x3c}},
		/* 1 */ tinyfont.Glyph{Rune: 0x31, Width: 0x4, Height: 0xc, XAdvance: 0x10, XOffset: 6, YOffset: -11, Bitmaps: []uint8{0x37, 0x91, 0x11, 0x11, 0x11, 0x11}},
		/* 2 */ tinyfont.Glyph{Rune: 0x32, Width: 0x8, Height: 0xc, XAdvance: 0x10, XOffset: 4, YOffset: -11, Bitmaps: []uint8{0x7c, 0xc6, 0x6, 0x6, 0x6, 0x4, 0xc, 0x18, 0x30, 0x60, 0xc0, 0xff}},
		/* 3 */ tinyfont.Glyph{Rune: 0x33, Width: 0x8, Height: 0xc, XAdvance: 0x10, XOffset: 4, YOffset: -10, Bitmaps: []uint8{0x7c, 0xc6, 0x3, 0x2, 0x6, 0x38, 0x6, 0x3, 0x3, 0x3, 0x86, 0xfc}},
		// ...

after:

const cMplusConst10pt = "" +
	/*  */ "\x00\x11" + "\x00\x00\x00\x00" + "\x05\x0B" + "\x05\x00" + "\xF7" + "\x00" + "\x03\x9C\xE7\x39\xCE\x73\x80" +
	/* � */ "\x00\x11" + "\x00\x00\x00\x01" + "\x05\x0B" + "\x05\x00" + "\xF7" + "\x00" + "\x00\x00\x06\x79\x80\x00\x00" +
	/* � */ "\x00\x11" + "\x00\x00\x00\x02" + "\x05\x0B" + "\x05\x00" + "\xF7" + "\x00" + "\x02\xAA\xAA\xAA\xAA\xAA\xAA" +
	/* � */ "\x00\x11" + "\x00\x00\x00\x03" + "\x05\x0B" + "\x05\x00" + "\xF7" + "\x00" + "\x04\xBD\x29\x03\xE4\x21\x00" +
	/* � */ "\x00\x11" + "\x00\x00\x00\x04" + "\x05\x0B" + "\x05\x00" + "\xF7" + "\x00" + "\x07\xA1\xE8\x03\xD0\xF4\x00" +
	// ...
@deadprogram deadprogram added the enhancement New feature or request label Jul 9, 2020
@timboldt
Copy link

timboldt commented Aug 9, 2020

The egregious use of RAM for fonts was the primary reason I abandoned TinyGo for my e-paper clock. I had plenty of flash, but almost no RAM. The Arduino libraries solved this problem (although I was forced to switch to C++).

@sago35
Copy link
Member Author

sago35 commented Aug 10, 2020

Hi @timboldt

Sometimes LLVM will store data in ROM without using a const font, But even in that case, the build time is very long, as described in #22.

The method described in this issue has the following advantages:

  1. The build time will be shorter.
  2. RAM is no longer used.

I'll try to make a PR somewhere this week.

@timboldt
Copy link

This looks like the perfect answer to the main issues I had with fonts: long build times, and excess RAM usage.

@sago35
Copy link
Member Author

sago35 commented Aug 3, 2023

For example, fonts created with tinyfontgen-ttf are created in const.
So I believe that we have completed the support.

@sago35 sago35 closed this as completed Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants