From 2b848ad16e1fcfac5a83036a754774513803e017 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 17 Sep 2020 14:55:42 +0100 Subject: [PATCH] Finally, Windows-accurate font sizing And of course Windows has some weird bug that has to be emulated with FreeType. --- src/Draw.cpp | 24 ++++++++++-------------- src/Font.cpp | 14 +++++++++++++- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index f434e606..330bfefa 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -683,27 +683,23 @@ void InitTextObject(const char *name) switch (mag) { -#ifdef JAPANESE case 1: + #ifdef JAPANESE height = 12; - width = 6 * 2; + width = 6; + #else + // For some weird reason, Windows's 6x12 Courier New is + // closer to 5x10, but FreeType renders it as proper 6x12, + // so we have to cheat a little. + height = 10; + width = 5; + #endif break; case 2: height = 20; - width = 10 * 2; + width = 10; break; -#else - case 1: - height = 10; - width = 9; - break; - - case 2: - height = 18; - width = 17; - break; -#endif } font = LoadFreeTypeFont(path.c_str(), width, height); diff --git a/src/Font.cpp b/src/Font.cpp index b38336b3..34a8993b 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -1110,7 +1110,19 @@ Font* LoadFreeTypeFontFromData(const unsigned char *data, size_t data_size, size if (FT_New_Memory_Face(font->library, font->data, (FT_Long)data_size, 0, &font->face) == 0) { - FT_Set_Pixel_Sizes(font->face, cell_width, cell_height); + // Select a rough size, for vector glyphs + FT_Size_RequestRec request = {FT_SIZE_REQUEST_TYPE_CELL, cell_height << 6, cell_height << 6, 0, 0}; // 'cell_height << 6, cell_height << 6' isn't a typo: it's needed by the Japanese font + FT_Request_Size(font->face, &request); + + // If an accurate bitmap font is available, however, use that instead + for (FT_Int i = 0; i < font->face->num_fixed_sizes; ++i) + { + if (font->face->available_sizes[i].width == cell_width && font->face->available_sizes[i].height == cell_height) + { + FT_Select_Size(font->face, i); + break; + } + } font->glyph_list_head = NULL;