diff options
-rw-r--r-- | configure.ac | 9 | ||||
-rw-r--r-- | src/layer_text.cpp | 51 | ||||
-rw-r--r-- | src/layer_text.h | 9 |
3 files changed, 61 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac index 30d5341..1e8d3d4 100644 --- a/configure.ac +++ b/configure.ac @@ -111,6 +111,15 @@ AC_C_INLINE # Checks for library functions. AC_CHECK_FUNCS([atexit strdup]) +# +# Config options +# +AC_ARG_WITH(font-path, + AS_HELP_STRING([--with-font-path=PATH], + [Specify base directory for selecting TTF fonts [default=/usr/share/fonts/truetype/]]), + [FONT_PATH=$withval], [FONT_PATH=/usr/share/fonts/truetype/]) +AC_DEFINE_UNQUOTED([FONT_PATH], ["$FONT_PATH"], [TTF fonts base directory]) + CXXFLAGS="$CXXFLAGS $CFLAGS" AC_CONFIG_FILES([Makefile src/Makefile chuck/Makefile]) diff --git a/src/layer_text.cpp b/src/layer_text.cpp index 38ba0e5..bbfff93 100644 --- a/src/layer_text.cpp +++ b/src/layer_text.cpp @@ -2,8 +2,14 @@ #include "config.h" #endif +#include <string.h> +#include <stdlib.h> #include <math.h> +#ifdef __WIN32__ +#include <windows.h> +#endif + #include <SDL.h> #include <SDL_ttf.h> #include <SDL_rotozoom.h> @@ -129,6 +135,51 @@ LayerText::color(SDL_Color color) alpha(alphav); } +#ifdef __WIN32__ + +void +LayerText::font(const char *file) +{ + free(filev); + + if (PathIsRelative(file)) { + /* relative path */ + const char *systemroot = getenv("SYSTEMROOT"); + + filev = (char *)malloc(strlen(systemroot) + 7 + strlen(file) + 1); + strcpy(filev, systemroot); + strcat(filev, "\\fonts\\"); + strcat(filev, file); + } else { + /* absolute path */ + filev = strdup(file); + } + + geo(geov); +} + +#else /* assume POSIX */ + +void +LayerText::font(const char *file) +{ + free(filev); + + if (*file != '/') { + /* relative path */ + filev = (char *)malloc(sizeof(FONT_PATH) + strlen(file)); + strcpy(filev, FONT_PATH); + strcat(filev, file); + } else { + /* absolute path */ + filev = strdup(file); + } + + geo(geov); +} + +#endif + void LayerText::style_osc(LayerText *obj, lo_arg **argv) { diff --git a/src/layer_text.h b/src/layer_text.h index 745f54f..6227ff5 100644 --- a/src/layer_text.h +++ b/src/layer_text.h @@ -72,14 +72,7 @@ private: obj->text(&argv[0]->s); } - inline void - font(const char *file) - { - free(filev); - filev = strdup(file); - - geo(geov); - } + void font(const char *file); OSCServer::MethodHandlerId *font_osc_id; static void font_osc(LayerText *obj, lo_arg **argv) |