From 17b0cca50de329d1897b245a0a3b077609570730 Mon Sep 17 00:00:00 2001 From: kraus Date: Mon, 27 May 2024 21:43:16 +0200 Subject: [PATCH] issue #2406 --- tools/font/bdfconv/Makefile | 8 ++++++++ tools/font/otf2bdf/otf2bdf.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tools/font/bdfconv/Makefile b/tools/font/bdfconv/Makefile index c8d7c5bd..edcc30d7 100644 --- a/tools/font/bdfconv/Makefile +++ b/tools/font/bdfconv/Makefile @@ -92,6 +92,14 @@ issue1769: bdfconv ./bdfconv -v -f 1 -b 2 -m '32-128' 3x7_Multi_V7.bdf -o u8g2_font_3x7_multi.c -n u8g2_font_3x7_multi -d ../bdf/helvR12.bdf convert bdf.tga -trim u8g2_font_3x7_multi.png +issue2406: bdfconv + -../otf2bdf/otf2bdf -y -v -r 72 -p 16 -o tmp.bdf ../tmp/zfull/zfull-regular.ttf + #-../otf2bdf/otf2bdf -v -r 72 -p 16 -o tmp.bdf ../ttf/Logisoso.ttf + #-../otf2bdf/otf2bdf -v -r 72 -p 16 -o tmp.bdf ../ttf/PressStart2P.ttf + #-../otf2bdf/otf2bdf -v -r 72 -p 16 -o tmp.bdf ../ttf/Wizzard.ttf + ./bdfconv -v -f 1 -b 2 -m '32-128' tmp.bdf -o u8g2_zfull.c -n u8g2_zfull -d ../bdf/helvR12.bdf + convert bdf.tga -trim u8g2_zfull.png + emoticons21: bdfconv ./bdfconv -v -f 1 -m '32-64' ../emoticons/emoticons21.bdf -o emoticons21.c -n u8g2_font_emoticons21_tn -d ../bdf/helvB18.bdf diff --git a/tools/font/otf2bdf/otf2bdf.c b/tools/font/otf2bdf/otf2bdf.c index 940fd9e8..61c7e9b7 100644 --- a/tools/font/otf2bdf/otf2bdf.c +++ b/tools/font/otf2bdf/otf2bdf.c @@ -135,6 +135,8 @@ static char *prog; */ static int verbose = 0; +static int alternate_y_offset_calculation = 0; // u8g2 issue 2406 https://github.com/olikraus/u8g2/issues/2406 + /* * Flags used when loading glyphs. */ @@ -880,6 +882,10 @@ generate_font(FILE *out, char *iname, char *oname) ht = ey - sy; x_off = sx + face->glyph->bitmap_left; y_off = sy + face->glyph->bitmap_top - face->glyph->bitmap.rows; + // u8g2 issue 2406 + // the above calculation seems to be wrong, this should be: + if ( alternate_y_offset_calculation ) + y_off = face->glyph->bitmap_top - ey; bbx.maxas = MAX(bbx.maxas, ht + y_off); bbx.maxds = MAX(bbx.maxds, -y_off); @@ -902,6 +908,10 @@ generate_font(FILE *out, char *iname, char *oname) fprintf(tmp, "DWIDTH %hd 0\n", dwidth); fprintf(tmp, "BBX %ld %ld %hd %hd\n", wd, ht, x_off, y_off); + // debug output (u8g2 issue 2406) + //if ( remapped_code >= 96 && remapped_code <= 103 ) + // fprintf(stderr, "%05ld BBX %ld %ld %hd %hd sy=%d, ey=%d bitmap_top=%d bitmap.rows=%d\n", (long) remapped_code, wd, ht, x_off, y_off, (int)sy, (int)ey, face->glyph->bitmap_top, face->glyph->bitmap.rows); + /* * Check for an error return here in case the temporary file system * fills up or the file is deleted while it is being used. @@ -1242,6 +1252,7 @@ usage(int eval) printf("-m mapfile\tGlyph reencoding file.\n"); printf("-n\t\tTurn off glyph hinting.\n"); printf("-a\t\tForce auto hinting.\n"); + printf("-y\t\tApply bugfix for the bbx y offset calculation (u8g2 issue 2406).\n"); printf("-g\t\tOutput raw glyphs instead of unicode chars.\n"); printf("-et\t\tDisplay the encoding tables available in the font.\n"); printf("-c c\t\tSet the character spacing (default: from font).\n"); @@ -1310,6 +1321,9 @@ main(int argc, char *argv[]) case 'a': case 'A': load_flags |= FT_LOAD_FORCE_AUTOHINT; break; + case 'y': case 'Y': + alternate_y_offset_calculation = 1; + break; case 'g': case 'G': forcenocmap = 1; break;