summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Devernay <frederic.devernay@inrialpes.fr>2011-08-06 12:56:05 +0200
committerMartin Lambers <marlam@marlam.de>2011-08-06 12:56:05 +0200
commit093a435d2444e1dfd9dcc4f01f4f05e928628fff (patch)
tree14bc6d85f3d98b379465acafca100e1459ed9772
parenta785b63789e0af2fb53d56f2192dd74e91837286 (diff)
downloadbino-093a435d2444e1dfd9dcc4f01f4f05e928628fff.tar.gz
Mac OS X: Create fontconfig configuration file to make subtitles work.
-rw-r--r--AUTHORS3
-rw-r--r--src/subtitle_renderer.cpp43
2 files changed, 39 insertions, 7 deletions
diff --git a/AUTHORS b/AUTHORS
index 3e62f57..66c28db 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,7 +1,8 @@
Maintainer:
Martin Lambers
-Version 1.1.2:
+Version 1.1.3:
+Frédéric Devernay
Martin Lambers
Version 1.0.0:
diff --git a/src/subtitle_renderer.cpp b/src/subtitle_renderer.cpp
index d41c7ac..93c2adc 100644
--- a/src/subtitle_renderer.cpp
+++ b/src/subtitle_renderer.cpp
@@ -4,6 +4,7 @@
* Copyright (C) 2011
* Martin Lambers <marlam@marlam.de>
* Joe <cuchac@email.cz>
+ * Frédéric Devernay <Frederic.Devernay@inrialpes.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,6 +33,9 @@
#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
# include <windows.h>
#endif
+#if defined __APPLE__
+# include <unistd.h>
+#endif
extern "C"
{
@@ -138,15 +142,16 @@ void subtitle_renderer::render(uint32_t *bgra32_buffer)
const char *subtitle_renderer::get_fontconfig_conffile()
{
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+#if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __APPLE__
/* Fontconfig annoyingly requires a configuration file, but there is no
- * default location for it on Windows. So we just create a temporary one.
- * Note that due to lack of mkstemp() on Windows, this code has race
- * conditions. Note also that if something goes wrong and we return NULL
- * here, the application will likely crash when we try to render a subtitle. */
+ * default location for it on Windows or Mac OS X. So we just create a temporary one.
+ * Note that if something goes wrong and we return NULL here, the application will
+ * likely crash when trying to render a subtitle. */
+ FILE *f;
+# if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
+ /* Note that due to lack of mkstemp() on Windows, this code has race conditions. */
char tmppathname[MAX_PATH];
static char tmpfilename[MAX_PATH];
- FILE *f;
DWORD ret;
ret = GetTempPath(MAX_PATH, tmppathname);
if (ret > MAX_PATH || ret == 0)
@@ -155,14 +160,38 @@ const char *subtitle_renderer::get_fontconfig_conffile()
return NULL;
if (!(f = fopen(tmpfilename, "w")))
return NULL;
+# else /* __APPLE__ */
+ static char tmpfilename[] = "/tmp/fontsXXXXXX.conf";
+ int d = mkstemps(tmpfilename, 5);
+ if (d == -1)
+ return NULL;
+ if (!(f = fdopen(d, "w")))
+ return NULL;
+# endif
fprintf(f,
"<?xml version=\"1.0\"?>\n"
"<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n"
"<fontconfig>\n"
+# if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
"<dir>WINDOWSFONTDIR</dir>\n"
"<dir>~/.fonts</dir>\n"
"<cachedir>WINDOWSTEMPDIR_FONTCONFIG_CACHE</cachedir>\n"
"<cachedir>~/.fontconfig</cachedir>\n"
+# else /* __APPLE__ */
+ "<dir>/usr/share/fonts</dir>\n"
+ "<dir>/usr/X11/lib/X11/fonts</dir>\n"
+ "<dir>/usr/X11/share/fonts</dir>\n"
+ "<dir>/opt/X11/share/fonts</dir>\n"
+ "<dir>/Library/Fonts</dir>\n"
+ "<dir>/Network/Library/Fonts</dir>\n"
+ "<dir>/System/Library/Fonts</dir>\n"
+ "<dir>~/Library/Application Support/Bino/fonts</dir>\n"
+ "<cachedir>/var/cache/fontconfig</cachedir>\n"
+ "<cachedir>/usr/X11/var/cache/fontconfig</cachedir>\n"
+ "<cachedir>/opt/X11/var/cache/fontconfig</cachedir>\n"
+ "<cachedir>~/Library/Application Support/Bino/cache/fonts</cachedir>\n"
+ "<cachedir>~/.fontconfig</cachedir>\n"
+# endif
"<config>\n"
"<blank>\n"
"<int>0x0020</int> <int>0x00A0</int> <int>0x00AD</int> <int>0x034F</int> <int>0x0600</int>\n"
@@ -184,6 +213,8 @@ const char *subtitle_renderer::get_fontconfig_conffile()
fclose(f);
return tmpfilename;
#else
+ /* Systems other than Windows and Mac OS are expected to have a default
+ * fontconfig configuration file so that we can simply return NULL. */
return NULL;
#endif
}