shithub: cstory

Download patch

ref: 2b848ad16e1fcfac5a83036a754774513803e017
parent: c9f17c4411d8d20a62e0f3b26a16b2a6b68504a8
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 17 10:55:42 EDT 2020

Finally, Windows-accurate font sizing

And of course Windows has some weird bug that has to be emulated with
FreeType.

--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -683,27 +683,23 @@
 
 	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);
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -1110,7 +1110,19 @@
 
 				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;