From 36316b400e48e0ee64ee1a016c8bde68785b7dc0 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 3 Jun 2015 19:44:25 +0100 Subject: Fix Windows 8.1 operation on hi-dpi displays. MuPDF only. Call SetProcessDPIAware if it's available; this stops Windows doing its own horrible scaling causing blurriness. Also, interrogate the screen display to get the real dpi and use that as our basis. --- platform/x11/pdfapp.c | 5 +++++ platform/x11/pdfapp.h | 1 + platform/x11/win_main.c | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index c6bbdd3c..3d796e47 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -134,6 +134,11 @@ void pdfapp_init(fz_context *ctx, pdfapp_t *app) app->tint_b = 240; } +void pdfapp_setresolution(pdfapp_t *app, int res) +{ + app->resolution = res; +} + void pdfapp_invert(pdfapp_t *app, const fz_rect *rect) { fz_irect b; diff --git a/platform/x11/pdfapp.h b/platform/x11/pdfapp.h index 1bac5872..e3633577 100644 --- a/platform/x11/pdfapp.h +++ b/platform/x11/pdfapp.h @@ -141,6 +141,7 @@ struct pdfapp_s }; void pdfapp_init(fz_context *ctx, pdfapp_t *app); +void pdfapp_setresolution(pdfapp_t *app, int res); void pdfapp_open(pdfapp_t *app, char *filename, int reload); void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int bps); void pdfapp_close(pdfapp_t *app); diff --git a/platform/x11/win_main.c b/platform/x11/win_main.c index d24c9c3a..40d91004 100644 --- a/platform/x11/win_main.c +++ b/platform/x11/win_main.c @@ -1169,6 +1169,28 @@ viewproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) return DefWindowProc(hwnd, message, wParam, lParam); } +typedef BOOL (SetProcessDPIAwareFn)(void); + +static int +get_system_dpi(void) +{ + HMODULE hUser32 = LoadLibrary(TEXT("user32.dll")); + SetProcessDPIAwareFn *ptr; + int hdpi, vdpi; + HDC desktopDC; + + ptr = (SetProcessDPIAwareFn *)GetProcAddress(hUser32, "SetProcessDPIAware"); + if (ptr != NULL) + ptr(); + FreeLibrary(hUser32); + + desktopDC = GetDC(NULL); + hdpi = GetDeviceCaps(desktopDC, LOGPIXELSX); + vdpi = GetDeviceCaps(desktopDC, LOGPIXELSY); + /* hdpi,vdpi = 100 means 96dpi. */ + return ((hdpi + vdpi) * 96.0 + 0.5) / 200; +} + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { @@ -1180,6 +1202,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow fz_context *ctx; int arg; int bps = 0; + int displayRes = get_system_dpi(); ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) @@ -1188,6 +1211,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow exit(1); } pdfapp_init(ctx, &gapp); + pdfapp_setresolution(&gapp, displayRes); GetModuleFileNameA(NULL, argv0, sizeof argv0); install_app(argv0); -- cgit v1.2.3