From 7ff7b87e64d9b6784b61ed78c12a50fad6192c75 Mon Sep 17 00:00:00 2001 From: florianessl Date: Sat, 2 Aug 2025 15:32:31 +0200 Subject: [PATCH 1/2] Added a small heuristic check to font.cpp to identify broken fonts based on RM2000.fon --- src/font.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/font.cpp b/src/font.cpp index cab00932fa..0256935666 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -33,6 +33,7 @@ # include FT_BITMAP_H # include FT_MODULE_H # include FT_TRUETYPE_TABLES_H +# include FT_FONT_FORMATS_H #endif #ifdef HAVE_HARFBUZZ @@ -311,6 +312,32 @@ FTFont::FTFont(Filesystem_Stream::InputStream is, int size, bool bold, bool ital if (!strcmp(face->family_name, "RM2000") || !strcmp(face->family_name, "RMG2000")) { // Workaround for bad kerning in RM2000 and RMG2000 fonts rm2000_workaround = true; + } else if (!FT_HAS_COLOR(face) && FT_HAS_FIXED_SIZES(face)) { + auto font_format = FT_Get_Font_Format(face); + if (!strcmp(font_format, "Windows FNT")) { + static constexpr std::array, 4> glyphs = {{ + { 'h', 6}, + { 'l', 4}, + { 'I', 15}, + { ' ', 15} + }}; + // Check some metrics to identify custom fonts which were based + // on the broken RM2000 font & thus also need the same workaround + rm2000_workaround = true; + for (int i = 0; i < glyphs.size(); ++i) { + auto glyph_index = FT_Get_Char_Index(face, std::get<0>(glyphs[i])); + + if (glyph_index == 0 || FT_Load_Glyph(face, glyph_index, FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO) != FT_Err_Ok) { + rm2000_workaround = false; + break; + } + auto advance_x = Utils::RoundTo(face->glyph->advance.x / 64.0); + if (advance_x != std::get<1>(glyphs[i])) { + rm2000_workaround = false; + break; + } + } + } } } From 08223c326b231b1b3e05d9ce84924d705dd3187a Mon Sep 17 00:00:00 2001 From: florianessl Date: Sat, 2 Aug 2025 20:07:30 +0200 Subject: [PATCH 2/2] Change the iterator variable type because the compiler complained about signage --- src/font.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/font.cpp b/src/font.cpp index 0256935666..2a9f7ec0b8 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -324,7 +324,7 @@ FTFont::FTFont(Filesystem_Stream::InputStream is, int size, bool bold, bool ital // Check some metrics to identify custom fonts which were based // on the broken RM2000 font & thus also need the same workaround rm2000_workaround = true; - for (int i = 0; i < glyphs.size(); ++i) { + for (size_t i = 0; i < glyphs.size(); ++i) { auto glyph_index = FT_Get_Char_Index(face, std::get<0>(glyphs[i])); if (glyph_index == 0 || FT_Load_Glyph(face, glyph_index, FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO) != FT_Err_Ok) {