Created attachment 164832 [details]
Allow BDF-characters to have less than 16 rows
The current implementation is somewhat naive in assuming, the bitmaps will always contain exactly 16 rows. The assumption is not verified resulting in cryptic failure messages trying to parse a 8x13 font, for example.
The attached patch fixes this -- it parses the hex rows until it encounters the ENDCHAR-keyword or reads the 16 rows (the hard-coded constant currently in place).
This allows me to convert the KOI8-U font (koi8x13.bdf) from the x11-fonts/geminifonts port. Not that the result is very useful -- presumably, because non-UTF locales aren't supported yet.
Created attachment 164833 [details]
Allow BDF-characters to appear out of order
I made these changes locally, because the utility kept rejecting my font with the "Bad ordering" error. Although it turned out, the error was bogus and due simply to the misparsing addressed by the other patch, these hunks may still be useful in case a BDF with misordered characters is encountered by someone else.
> The current implementation is somewhat naive in assuming, the bitmaps will always contain exactly 16 rows. The assumption is not verified resulting in cryptic failure messages trying to parse a 8x13 font, for example.
Note that you can specify the height and width with -h and -w, but I agree that it's a bit silly to require it to be specified, and we should provide a useful error message if parsing fails.
(In reply to Ed Maste from comment #2)
> we should provide a useful error message if parsing fails.
Well, my changes make the function accept arbitrary number of rows UP TO the height. I don't know, if BDF-format allows different characters in the same file to have different heights, but with my patch the utility will be better prepared to handle such cases...
Created attachment 168728 [details]
read character size from BBX entry
(In reply to Mikhail Teterin from comment #3)
> I don't know, if BDF-format allows different characters in the same file to
> have different heights, but with my patch the utility will be better prepared
> to handle such cases...
I agree that a cryptic error message is unacceptable.
However, in the case of just stopping upon ENDCHAR the result with a 13 row .bdf will still be a 16x8 .fnt font that has the final 3 rows empty. This is probably not what is desired.
I've attached a patch that might be part of the solution - reading the height and width from the BBX entry in the font.
It doesn't fully work with koi8x13.bdf because most glyphs are 13x8 but there is one 9x6 and one 13x9.
Created attachment 180939 [details]
read FONTBOUNDINGBOX and BBX, handle other DWIDTH
I tried to convert fonts in x11-fonts/wqy (an open source Chinese bitmap font) for use with vt. The original fonts are in pcf, I used https://github.com/ganaware/pcf2bdf to convert them to bdf.
I found that the original assumptions in the code have several problems:
* Assuming DWIDTH = width or width * 2
Actually there can be varying widths. For wqy, there are DWIDTH between 2-13 for the 10pt font, and 2-12 for the 9pt font.
* Assuming number of lines in the bitmap == height
Actually it usually equals to the height in the BBX line.
This patch fixes the problems by:
* Read the FONTBOUNDINGBOX line.
This gives us the baseline position. If offset_y in this line is -3, we need to reserve 3 lines at the bottom.
* Read the BBX line.
The offset_x and offset_y information in this line tells us where to position the glyph. For example, if offset_y == -2, the font should be positioned 2 lines below the baseline.
* Position the glyph at the correct place.
The starting line is calculated by:
line_y = height + font_y - bb_h - bb_y + i;
The font's baseline (bottom) is height + font_y, the glyph's baseline is height + font_y - bb_y.
The font generated by this patch is used successfully with the wqy font on the vt terminal to display chinese characters. There seems to be problems for alphabet characters which are double-width (the 'W' in wqy font), so the working configuration requires a width of at least 10 pixels.
Created attachment 180943 [details]
fix x-position handling
The previous patch has some problems in deciding the x-position of the character.
The input line seems to have howmany(bb_w, 8) bytes. The bitmap is aligned to the left, and occupies the left bb_w bits.
The first shift moves the bitmap to the right, now it's right aligned to bit 0.
The parse_bitmap_line() function seems to assume that the glyph occupies the top dwidth bits. To put the character at bb_x position, the number of bits at right is howmany(dwidth, 8) * 8 - bb_x - bb_w.
Created attachment 194668 [details]
More complex patch
Added support all font width, improve parsing of BDFs (FONT, FONTBOUNDINGBOX, BBX etc)
*** Bug 228288 has been marked as a duplicate of this bug. ***
(In reply to Dmitry Wagin from comment #8)
also, the patch added support for HiDPI displays
In the x11-fonts/spleen port I'm converting all but one of the fonts
to vt(4) fonts. This works pretty well, but converting the
spleen-32x64  font fails with:
$ vtfontcvt -w 32 -h 64 spleen-32x64.bdf spleen-32x64.fnt
vtfontcvt: Unsupported wbytes 4!
While Dmitry's patch fixes the error message, all generated fonts are
now broken and do not display correctly. Characters appear as if some
part of them are cut off. Something is not quite right.
(In reply to Tobias Kortkamp from comment #11)
old patch version, I'll find the corrected
Created attachment 199764 [details]
More complex patch
A corrected version of the patch, please test.
(In reply to Dmitry Wagin from comment #13)
Thank you, Dmitry. This seems to work nicely now!
Created attachment 199765 [details]
There seems to be a new problem when building audio/cava and trying to
convert cava.bdf which previously worked fine:
vtfontcvt: Font spacing "C" (Character cell) required
I'm attaching cava.bdf in case you want to take a look.
A commit references this bug:
Date: Sun Dec 2 21:26:00 UTC 2018
New revision: 486487
x11-fonts/spleen: Update to 1.0.3
- Provide spleen-32x64 for vt(4). The vtfontcvt in supported FreeBSD
versions cannot deal with it at the moment, so provide a pregenerated
version of it for now. This was made possible by the vtfontcvt
feature patch from Dmitry Wagin (thanks!) .
PR: 205707 
(In reply to Tobias Kortkamp from comment #15)
incorrect font header, it just wasn't checked before.
"FONT -gnu-unifont-medium-r-normal--16-160-75-75-c-80-iso10646-1" defines the font family and face names as an X logical font description.
A commit references this bug:
Date: Mon Dec 3 11:13:41 UTC 2018
New revision: 486512
audio/cava: Add a dummy fontname to cava.bdf
Without it, the BDF is malformed with FONT set to just "psf" which
is not a proper XLFD. This confuses newer vtfontcvt versions which
check for character cell spacing.