From e4fcf6a5e19ece9977a4a4f6fad683d09b70f9dc Mon Sep 17 00:00:00 2001 From: Clownacy <Clownacy@users.noreply.github.com> Date: Wed, 4 Sep 2019 15:43:52 +0000 Subject: [PATCH] Fixed spacing for fonts that aren't Courier New Previous, I used a godawful hack to emulate Windows' API, but it seems this only ever worked for Courier New: with something like Liberation Mono, it would squash the font. Now I'm just giving up on it, and using actual font sizes rather than "cell" sizes. I'm not sure if this is accurate the original EXE. --- src/Draw.cpp | 2 +- src/Font.cpp | 28 ++-------------------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/Draw.cpp b/src/Draw.cpp index 100cc206..483dff2f 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -609,7 +609,7 @@ void InitTextObject(const char *name) size_t size; const unsigned char *data = FindResource("FONT", "FONT", &size); - font = LoadFontFromData(data, size, 5 * magnification, 10 * magnification); + font = LoadFontFromData(data, size, 8 * magnification, 9 * magnification); } void PutText(int x, int y, const char *text, unsigned long color) diff --git a/src/Font.cpp b/src/Font.cpp index 2376c6e0..1ab3c8e9 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -1074,35 +1074,11 @@ FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsign return NULL; } - unsigned int best_pixel_width = 0; - unsigned int best_pixel_height = 0; - - for (unsigned int i = 0;; ++i) - { - FT_Set_Pixel_Sizes(font_object->face, i, i); - - const unsigned int current_cell_width = font_object->face->size->metrics.max_advance / 64; - const unsigned int current_cell_height = font_object->face->size->metrics.height / 64; - - if (current_cell_width > cell_width && current_cell_height > cell_height) - { - break; - } - else - { - if (current_cell_width <= cell_width) - best_pixel_width = i; - - if (current_cell_height <= cell_height) - best_pixel_height = i; - } - } - #ifdef JAPANESE - best_pixel_width = 0; // Cheap hack to make the font square + cell_width = 0; // Cheap hack to make the font square #endif - FT_Set_Pixel_Sizes(font_object->face, best_pixel_width, best_pixel_height); + FT_Set_Pixel_Sizes(font_object->face, cell_width, cell_height); font_object->glyph_list_head = NULL;