From f3a31c417244d5376541f5cceca30f213c54bb8e Mon Sep 17 00:00:00 2001 From: Hib Eris Date: Wed, 30 Dec 2009 09:59:00 +0100 Subject: [PATCH] Make poppler (optionally) relocatable on Windows --- configure.ac | 26 +++++++++++++++++++++ poppler/GlobalParams.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index 0ae6dd5..14fce0b 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,32 @@ AC_ARG_ENABLE(fixedpoint, [ --enable-fixedpoint use fixed point (instead of floating point) arithmetic], AC_DEFINE(USE_FIXEDPOINT, [1], [Use fixed point arithmetic])) +dnl Relocation support +AC_ARG_ENABLE(relocatable, + AC_HELP_STRING([--disable-relocatable], + [Hardcode the poppler library location (on Windows).]), + enable_relocatable=$enableval, + [if test x$os_win32 = xyes; then + # default to yes on native Windows. + enable_relocatable="yes" + else + # default to no everywhere else. + enable_relocatable="no" + fi + ] +) + +if test x$enable_relocatable = xyes; then + if test x$os_win32 = xyes; then + AC_DEFINE([ENABLE_RELOCATABLE], + [1],[Do not hardcode the library location]) + else + AC_MSG_ERROR( + [Invalid setting for relocatable, only supported on windows]) + + fi +fi + AC_DEFINE_DIR(POPPLER_DATADIR, "{datarootdir}/poppler", [Poppler data dir]) dnl ##### Checks for header files. diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc index eda0a34..928123d 100644 --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -44,6 +44,7 @@ #endif #ifdef _WIN32 # include +# include #endif #include "goo/gmem.h" #include "goo/GooString.h" @@ -140,6 +141,62 @@ DisplayFontParam::~DisplayFontParam() { } } +#if ENABLE_RELOCATABLE && defined(_WIN32) + +/* search for data relative to where we are installed */ + +static HMODULE hmodule; + +extern "C" { +BOOL WINAPI +DllMain (HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpvReserved) +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + hmodule = hinstDLL; + break; + } + + return TRUE; +} +} + +static char * +get_poppler_datadir (void) +{ + static char retval[_MAX_PATH]; + static int beenhere = 0; + + unsigned char *p; + + if (beenhere) + return retval; + + if (!GetModuleFileName (hmodule, (CHAR *) retval, sizeof(retval) - 20)) + return POPPLER_DATADIR; + + p = _mbsrchr ((const unsigned char *) retval, '\\'); + *p = '\0'; + p = _mbsrchr ((const unsigned char *) retval, '\\'); + if (p) { + if (stricmp ((const char *) (p+1), "bin") == 0) + *p = '\0'; + } + strcat (retval, "\\share\\poppler"); + + beenhere = 1; + + return retval; +} + +#undef POPPLER_DATADIR +#define POPPLER_DATADIR get_poppler_datadir () + +#endif + #ifdef _WIN32 //------------------------------------------------------------------------ -- 1.6.0.4