Index: core/global.cpp =================================================================== --- core/global.cpp (revision 0) +++ core/global.cpp (revision 0) @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2006 Holger Freyther + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _OKULAR_GLOBAL_H +#define _OKULAR_GLOBAL_H + +#include "global.h" + +#include + +#ifdef Q_WS_X11 +#include +#endif + +#ifdef Q_WS_MAC +#include +#include +#endif + +namespace Okular { + +#ifdef Q_WS_X11 + double getDpiX() { + return QX11Info::appDpiX(); + } + + double getDpiY() { + return QX11Info::appDpiY(); + } +#endif + +#ifdef Q_WS_MAC + /* + * Code copied from http://developer.apple.com/qa/qa2001/qa1217.html + */ + // Handy utility function for retrieving an int from a CFDictionaryRef + static int GetIntFromDictionaryForKey( CFDictionaryRef desc, CFStringRef key ) + { + CFNumberRef value; + int num = 0; + if ( (value = (CFNumberRef)CFDictionaryGetValue(desc, key)) == NULL || CFGetTypeID(value) != CFNumberGetTypeID()) + return 0; + CFNumberGetValue(value, kCFNumberIntType, &num); + return num; + } + + CGDisplayErr GetDisplayDPI( + CFDictionaryRef displayModeDict, + CGDirectDisplayID displayID, + double *horizontalDPI, double *verticalDPI ) + { + CGDisplayErr err = kCGErrorFailure; + io_connect_t displayPort; + CFDictionaryRef displayDict; + + // Grab a connection to IOKit for the requested display + displayPort = CGDisplayIOServicePort( displayID ); + if ( displayPort != MACH_PORT_NULL ) + { + // Find out what IOKit knows about this display + displayDict = IODisplayCreateInfoDictionary(displayPort, 0); + if ( displayDict != NULL ) + { + const double mmPerInch = 25.4; + double horizontalSizeInInches = + (double)GetIntFromDictionaryForKey(displayDict, + CFSTR(kDisplayHorizontalImageSize)) / mmPerInch; + double verticalSizeInInches = + (double)GetIntFromDictionaryForKey(displayDict, + CFSTR(kDisplayVerticalImageSize)) / mmPerInch; + + // Make sure to release the dictionary we got from IOKit + CFRelease(displayDict); + + // Now we can calculate the actual DPI + // with information from the displayModeDict + *horizontalDPI = + (double)GetIntFromDictionaryForKey( displayModeDict, kCGDisplayWidth ) + / horizontalSizeInInches; + *verticalDPI = (double)GetIntFromDictionaryForKey( displayModeDict, + kCGDisplayHeight ) / verticalSizeInInches; + err = CGDisplayNoErr; + } + } + return err; + } + + double getDpiX() { + double x,y; + CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay), + kCGDirectMainDisplay, + &x, &y ); + + return err == CGDisplayNoErr ? x : 72.0; + } + + double getDpiY() { + double x,y; + CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay), + kCGDirectMainDisplay, + &x, &y ); + + return err == CGDisplayNoErr ? y : 72.0; + } +#endif + +#ifdef Q_WS_WIN +#error "Broken please fix it on Win32" + OKULAR_EXPORT double getDpiX() { + } + + OKULAR_EXPORT double getDpiY() { + } +#endif +} + +#endif Property changes on: core/global.cpp ___________________________________________________________________ Name: svn:eol-style + native Index: core/global.h =================================================================== --- core/global.h (revision 0) +++ core/global.h (revision 0) @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Holger Freyther + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _OKULAR_GLOBAL_H +#define _OKULAR_GLOBAL_H + +#include "okular_export.h" + +namespace Okular { + OKULAR_EXPORT double getDpiX(); + OKULAR_EXPORT double getDpiY(); +} + +#endif Property changes on: core/global.h ___________________________________________________________________ Name: svn:eol-style + native Index: generators/dvi/generator_dvi.cpp =================================================================== --- generators/dvi/generator_dvi.cpp (revision 600069) +++ generators/dvi/generator_dvi.cpp (working copy) @@ -11,13 +11,13 @@ #include "core/page.h" #include "core/link.h" #include "core/utils.h" +#include "core/global.h" #include "dviFile.h" #include "dviPageInfo.h" #include "dviRenderer.h" #include "pageSize.h" #include -#include #include #include #include @@ -45,7 +45,7 @@ kDebug() << "# of pages: " << m_dviRenderer->dviFile->total_pages << endl; - m_resolution = QX11Info::appDpiY(); + m_resolution = Okular::getDpiY(); loadPages( pagesVector, 0 ); ready = true; Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (revision 600069) +++ CMakeLists.txt (working copy) @@ -40,6 +40,7 @@ core/chooseenginedialog.cpp core/document.cpp core/generator.cpp + core/global.cpp core/link.cpp core/page.cpp core/pagetransition.cpp @@ -62,8 +63,13 @@ kde4_add_library(okularcore SHARED ${okularcore_SRCS}) -target_link_libraries(okularcore ${KDE4_KPARTS_LIBS} ${QT_QTCORE_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} m ) +# Special handling for linking okularcore on OSX/Apple +IF(APPLE) + SET(OKULAR_IOKIT "-framework IOKit" CACHE STRING "Apple IOKit framework") +ENDIF(APPLE) +target_link_libraries(okularcore ${UMBA_UMBA} ${OKULAR_IOKIT} ${KDE4_KPARTS_LIBS} ${QT_QTCORE_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} m ) + install(TARGETS okularcore DESTINATION ${LIB_INSTALL_DIR} ) # okularpart