Finally, Windows-accurate font sizing
And of course Windows has some weird bug that has to be emulated with FreeType.
This commit is contained in:
parent
c9f17c4411
commit
2b848ad16e
2 changed files with 23 additions and 15 deletions
24
src/Draw.cpp
24
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);
|
||||
|
|
14
src/Font.cpp
14
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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue