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.
This commit is contained in:
Clownacy 2019-09-04 15:43:52 +00:00
parent ae8aeae2ac
commit e4fcf6a5e1
2 changed files with 3 additions and 27 deletions

View file

@ -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)

View file

@ -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;