chafa icon indicating copy to clipboard operation
chafa copied to clipboard

chafa8x8.py tuning/polishing

Open hpjansson opened this issue 4 years ago • 10 comments

@cdluminate

This is probably not a showstopper, but may be worth looking into anyway:

When I run chafa8x8.py GenA, it prints the following:

$ ./chafa8x8.py GenA
 -> number of centers: 4414
=> Result saved to chafa8x8.json
Number of glyphs: 4414
I'm sorry this file is too complex for me to understand (or is erroneous)

The last one looks like an error message from fontforge. The resulting TTF seems ok from a quick look with ttfdump, though, so it's likely mostly cosmetic.

hpjansson avatar Aug 07 '19 20:08 hpjansson

I was always ignoring that error message but nothing went wrong actually.

cdluminate avatar Aug 08 '19 01:08 cdluminate

Maybe I should write a PCF font exporter instead of using fontforge?

cdluminate avatar Feb 05 '23 04:02 cdluminate

PCF would be nice. I don't know how much work it is, though. It might be possible to do bitmap embeddings in TTF too.

The problem I'm seeing right now is that VTE puts vertical space between the characters, and mlterm adds horizontal space for some reason. So maybe the font dimensions/kerning is underspecified somehow.

hpjansson avatar Feb 06 '23 02:02 hpjansson

I had to do this:

diff --git a/tools/fontgen/chafa8x8.py b/tools/fontgen/chafa8x8.py
index 2905f30..344499e 100755
--- a/tools/fontgen/chafa8x8.py
+++ b/tools/fontgen/chafa8x8.py
@@ -293,8 +293,6 @@ def mainGenFont(argv: List[str]):
             glyph.importOutlines('chafa8x8_svg/%d.svg' % i)
             glyph.left_side_bearing = 0
             glyph.right_side_bearing = 0
-            glyph.width = 0
-            glyph.vwidth = 0
         # font.save('chafa8x8.sfd')
         font.generate(ag.ttf)
         font.close()

to make the font loader work correctly. Otherwise it gets the glyph x size wrong. I don't know why it's there, though.

hpjansson avatar Feb 06 '23 02:02 hpjansson

I had to do this:

diff --git a/tools/fontgen/chafa8x8.py b/tools/fontgen/chafa8x8.py
index 2905f30..344499e 100755
--- a/tools/fontgen/chafa8x8.py
+++ b/tools/fontgen/chafa8x8.py
@@ -293,8 +293,6 @@ def mainGenFont(argv: List[str]):
             glyph.importOutlines('chafa8x8_svg/%d.svg' % i)
             glyph.left_side_bearing = 0
             glyph.right_side_bearing = 0
-            glyph.width = 0
-            glyph.vwidth = 0
         # font.save('chafa8x8.sfd')
         font.generate(ag.ttf)
         font.close()

to make the font loader work correctly. Otherwise it gets the glyph x size wrong. I don't know why it's there, though.

Me neither -- I've forgotten the reason why the width is set as 0. But I remember back at that time I had a difficult time working around the character kerning/spacing issue in different terminals. They must be some workarounds that worked for the issue at that time.

cdluminate avatar Feb 06 '23 02:02 cdluminate

Just for record. The above weird zero width issue is fixed in https://github.com/hpjansson/chafa/commit/e1e9f723acbbe2b6460469b1ce9e976f9d20752c That is a temporary hack to mitigate vertical/horizontal gaps in VTE terminals. We can improve it in the future.

cdluminate avatar Feb 06 '23 18:02 cdluminate

Fwiw i find bdf format convenient, allows text editing. And converting to pcf with xfonts-utils: /usr/bin/bdftopcf

clort81 avatar Feb 11 '23 01:02 clort81

The BDF font writer is here: https://github.com/hpjansson/chafa/commit/48f57019fd56e21e5cbdec91e7f95af3c5779649 But it seems that Unicode support range is an issue:

$ bdftopcf -o chafa8x8.pcf chafa8x8.bdf
[...]
BDF Error on line 105340: char 'U+0x101075' has encoding too large (1052789)
BDF Error on line 105365: char 'U+0x101076' has encoding too large (1052790)
BDF Error on line 105390: char 'U+0x101077' has encoding too large (1052791)
BDF Error on line 105415: char 'U+0x101078' has encoding too large (1052792)
BDF Error on line 105440: char 'U+0x101079' has encoding too large (1052793)
BDF Warning on line 105463: No characters with valid encodings

cdluminate avatar Feb 11 '23 05:02 cdluminate

chafa8x8.bdf.zip

Fontforge can correctly read the resulting file. But the 0x100000 range is not supported for this format...

cdluminate avatar Feb 11 '23 05:02 cdluminate

Could one of the lower PUA ranges work?

hpjansson avatar Jul 14 '23 23:07 hpjansson