summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/fontwrapper-ft.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2011-04-14 14:35:50 +0200
committerAdam Borowski <kilobyte@angband.pl>2011-04-14 14:48:29 +0200
commita32c3bcafd50de5be8e1f43f9b6013dfc32d04f3 (patch)
tree74c84e06c04c481537afbb8fcaab2185148e0def /crawl-ref/source/fontwrapper-ft.cc
parent9f0dde9167be6cefe9814699d69d567ae9acb695 (diff)
downloadcrawl-ref-a32c3bcafd50de5be8e1f43f9b6013dfc32d04f3.tar.gz
crawl-ref-a32c3bcafd50de5be8e1f43f9b6013dfc32d04f3.zip
Work around FreeType having problems opening files on Windows.
According to its documentation, FT_New_Face() expects the file's name in UTF-8 regardless of the system locale. Too bad, there's a bug where sometimes on Windows an 8 bit code page is used instead: http://www.mail-archive.com/freetype@nongnu.org/msg00939.html Since we don't know if the version we're talking to is fixed or not, it's safer to load the font file ourselves. This fixes cases where zipped (not installed) builds were put into a directory with a non-ASCII name.
Diffstat (limited to 'crawl-ref/source/fontwrapper-ft.cc')
-rw-r--r--crawl-ref/source/fontwrapper-ft.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/crawl-ref/source/fontwrapper-ft.cc b/crawl-ref/source/fontwrapper-ft.cc
index b0096d71d6..c89838c018 100644
--- a/crawl-ref/source/fontwrapper-ft.cc
+++ b/crawl-ref/source/fontwrapper-ft.cc
@@ -7,10 +7,12 @@
#include FT_FREETYPE_H
#include "defines.h"
+#include "errno.h"
#include "files.h"
#include "format.h"
#include "fontwrapper-ft.h"
#include "glwrapper.h"
+#include "syscalls.h"
#include "tilebuf.h"
#include "tilefont.h"
#include "unicode.h"
@@ -47,11 +49,25 @@ bool FTFontWrapper::load_font(const char *font_name, unsigned int font_size,
// TODO enne - need to find a cross-platform way to also
// attempt to locate system fonts by name...
+ // 1KB: fontconfig if we are not scared of hefty libraries
std::string font_path = datafile_path(font_name, false, true);
if (font_path.c_str()[0] == 0)
die_noline("Could not find font '%s'\n", font_name);
- error = FT_New_Face(library, font_path.c_str(), 0, &face);
+ // Certain versions of freetype have problems reading files on Windows,
+ // do that ourselves.
+ FILE *f = fopen_u(font_path.c_str(), "rb");
+ if (!f)
+ die_noline("Could not read font '%s'\n", font_name);
+ unsigned long size = file_size(f);
+ FT_Byte *ttf = (FT_Byte*)malloc(size);
+ ASSERT(ttf);
+ if (fread(ttf, 1, size, f) != size)
+ die_noline("Could not read font '%s': %s\n", font_name, strerror(errno));
+ fclose(f);
+ // FreeType needs the font until FT_Done_Face(), and we never call it.
+
+ error = FT_New_Memory_Face(library, ttf, size, 0, &face);
if (error == FT_Err_Unknown_File_Format)
die_noline("Unknown font format for file '%s'\n", font_path.c_str());
else if (error)