ref: f354b84f6a495e39e532e882f152deb72690a093
parent: add4e69374f90afc09f7a5e1389b8a372a119713
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Aug 14 12:26:37 EDT 2019
Revert "Glyphs now regenerate with the rest of the game's textures" This reverts commit aa6174b3f21eadb32eb227bb595e74bc3efc8983.
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -530,8 +530,6 @@
}
}
}
-
- RestoreGlyphs(gFont);
}
#ifdef WINDOWS
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -955,51 +955,6 @@
return lookup[value];
}
-static void SendGlyphToBackend(FontObject *font_object, Backend_Glyph *backend)
-{
- if (backend == NULL)
- return;
-
- FT_Bitmap bitmap;
- FT_Bitmap_New(&bitmap);
- FT_Bitmap_Convert(font_object->library, &font_object->face->glyph->bitmap, &bitmap, 1);
-
- switch (font_object->face->glyph->bitmap.pixel_mode)
- {
- case FT_PIXEL_MODE_LCD:
- for (unsigned int y = 0; y < bitmap.rows; ++y)
- {
- unsigned char *pixel_pointer = bitmap.buffer + y * bitmap.pitch;
-
- for (unsigned int x = 0; x < bitmap.width; ++x)
- {
- *pixel_pointer = GammaCorrect(*pixel_pointer);
- ++pixel_pointer;
- }
- }
-
- break;
-
- case FT_PIXEL_MODE_GRAY:
- for (unsigned int y = 0; y < bitmap.rows; ++y)
- {
- unsigned char *pixel_pointer = bitmap.buffer + y * bitmap.pitch;
-
- for (unsigned int x = 0; x < bitmap.width; ++x)
- {
- *pixel_pointer = GammaCorrect((*pixel_pointer * 0xFF) / (bitmap.num_grays - 1));
- ++pixel_pointer;
- }
- }
-
- break;
- }
-
- Backend_LoadGlyphPixels(backend, bitmap.buffer, bitmap.pitch);
-
- FT_Bitmap_Done(font_object->library, &bitmap);
-}
-
static CachedGlyph* GetGlyphCached(FontObject *font_object, unsigned long unicode_value)
{
CachedGlyph *glyph;
@@ -1023,15 +978,48 @@
FT_Load_Glyph(font_object->face, glyph_index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME);
#endif
+ glyph->unicode_value = unicode_value;
+ glyph->x = font_object->face->glyph->bitmap_left;
+ glyph->y = (FT_MulFix(font_object->face->ascender, font_object->face->size->metrics.y_scale) - font_object->face->glyph->metrics.horiBearingY + (64 / 2)) / 64;
+ glyph->x_advance = font_object->face->glyph->advance.x / 64;
+
+ FT_Bitmap bitmap;
+ FT_Bitmap_New(&bitmap);
+ FT_Bitmap_Convert(font_object->library, &font_object->face->glyph->bitmap, &bitmap, 1);
+
unsigned char pixel_mode;
switch (font_object->face->glyph->bitmap.pixel_mode)
{
case FT_PIXEL_MODE_LCD:
pixel_mode = FONT_PIXEL_MODE_LCD;
+
+ for (unsigned int y = 0; y < bitmap.rows; ++y)
+ {
+ unsigned char *pixel_pointer = bitmap.buffer + y * bitmap.pitch;
+
+ for (unsigned int x = 0; x < bitmap.width; ++x)
+ {
+ *pixel_pointer = GammaCorrect(*pixel_pointer);
+ ++pixel_pointer;
+ }
+ }
+
break;
case FT_PIXEL_MODE_GRAY:
pixel_mode = FONT_PIXEL_MODE_GRAY;
+
+ for (unsigned int y = 0; y < bitmap.rows; ++y)
+ {
+ unsigned char *pixel_pointer = bitmap.buffer + y * bitmap.pitch;
+
+ for (unsigned int x = 0; x < bitmap.width; ++x)
+ {
+ *pixel_pointer = GammaCorrect((*pixel_pointer * 0xFF) / (bitmap.num_grays - 1));
+ ++pixel_pointer;
+ }
+ }
+
break;
case FT_PIXEL_MODE_MONO:
@@ -1039,13 +1027,10 @@
break;
}
- glyph->backend = Backend_CreateGlyph((pixel_mode == FONT_PIXEL_MODE_LCD ? font_object->face->glyph->bitmap.width / 3 : font_object->face->glyph->bitmap.width), font_object->face->glyph->bitmap.rows, pixel_mode);
- glyph->unicode_value = unicode_value;
- glyph->x = font_object->face->glyph->bitmap_left;
- glyph->y = (FT_MulFix(font_object->face->ascender, font_object->face->size->metrics.y_scale) - font_object->face->glyph->metrics.horiBearingY + (64 / 2)) / 64;
- glyph->x_advance = font_object->face->glyph->advance.x / 64;
+ glyph->backend = Backend_CreateGlyph((pixel_mode == FT_PIXEL_MODE_LCD ? bitmap.width / 3 : bitmap.width), bitmap.rows, pixel_mode);
+ Backend_LoadGlyphPixels(glyph->backend, bitmap.buffer, bitmap.pitch);
- SendGlyphToBackend(font_object, glyph->backend);
+ FT_Bitmap_Done(font_object->library, &bitmap);
}
return glyph;
@@ -1188,21 +1173,5 @@
free(font_object->data);
FT_Done_FreeType(font_object->library);
free(font_object);
- }
-}
-
-void RestoreGlyphs(FontObject *font_object)
-{
- for (CachedGlyph *glyph = font_object->glyph_list_head; glyph != NULL; glyph = glyph->next)
- {
- unsigned int glyph_index = FT_Get_Char_Index(font_object->face, glyph->unicode_value);
-
-#ifndef DISABLE_FONT_ANTIALIASING
- FT_Load_Glyph(font_object->face, glyph_index, FT_LOAD_RENDER | (font_object->lcd_mode ? FT_LOAD_TARGET_LCD : 0));
-#else
- FT_Load_Glyph(font_object->face, glyph_index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME);
-#endif
-
- SendGlyphToBackend(font_object, glyph->backend);
}
}
--- a/src/Font.h
+++ b/src/Font.h
@@ -10,4 +10,3 @@
FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigned int cell_height);
void DrawText(FontObject *font_object, Backend_Surface *surface, int x, int y, unsigned long colour, const char *string, size_t string_length);
void UnloadFont(FontObject *font_object);
-void RestoreGlyphs(FontObject *font_object);