# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1335769994 0 # Node ID 19c34a1c1489f07239a032d55cf7ac66e27127f5 # Parent ea749fb90f7e3e5e221821ee15af3c3c6338a330 Added code to do DPI conversion on Windows. This almost fixes the printer contexts rendering... values still seem slightly off. Will look for a better calculation. diff -r ea749fb90f7e -r 19c34a1c1489 win/dw.c --- a/win/dw.c Sun Apr 29 19:46:30 2012 +0000 +++ b/win/dw.c Mon Apr 30 07:13:14 2012 +0000 @@ -10102,6 +10102,27 @@ #endif } +#ifdef GDIPLUS +/* Internal function to increase or decrease coordinates/sizes + * by the difference of the screen DPI (96) and the context DPI. + */ +void _convert_dpi(HDC hdc, int *x, int *y, int mult) +{ + float ratiox = (float)GetDeviceCaps(hdc, LOGPIXELSX)/96.0; + float ratioy = (float)GetDeviceCaps(hdc, LOGPIXELSY)/96.0; + if(mult) + { + *x *= ratiox; + *y *= ratioy; + } + else + { + *x /= ratiox; + *y /= ratioy; + } +} +#endif + /* Draw text on a window (preferably a render window). * Parameters: * handle: Handle to the window. @@ -10118,7 +10139,6 @@ ColorInfo *cinfo = NULL; COLORREF background; TCHAR *wtext = UTF8toWide(text); - POINT pt; if(handle) hdc = GetDC(handle); @@ -10151,12 +10171,10 @@ SetBkMode(hdc, OPAQUE); SetBkColor(hdc, background); } - pt.x = x; - pt.y = y; -#ifdef GDIPLUS1 - LPtoDP(hdc, &pt, 1); +#ifdef GDIPLUS + _convert_dpi(hdc, &x, &y, TRUE); #endif - TextOut(hdc, pt.x, pt.y, wtext, (int)_tcslen(wtext)); + TextOut(hdc, x, y, wtext, (int)_tcslen(wtext)); if(oldFont) SelectObject(hdc, oldFont); if(mustdelete) @@ -10211,6 +10229,10 @@ GetTextExtentPoint32(hdc, wtext, (int)_tcslen(wtext), &sz); +#ifdef GDIPLUS + _convert_dpi(hdc, &(sz.cx), &(sz.cy), FALSE); +#endif + if(width) *width = sz.cx; @@ -10616,6 +10638,14 @@ sheight = height; } +#ifdef GDIPLUS + /* Do conversion on all the coordinates */ + _convert_dpi(hdcdest, &xdest, &ydest, TRUE); + _convert_dpi(hdcdest, &width, &height, TRUE); + _convert_dpi(hdcsrc, &xsrc, &ysrc, TRUE); + _convert_dpi(hdcsrc, &swidth, &sheight, TRUE); +#endif + /* If it is a 32bpp bitmap (with alpha) use AlphaBlend unless it fails */ if ( srcp && srcp->depth == 32 && AlphaBlend( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, swidth, sheight, bf ) ) { @@ -11690,6 +11720,11 @@ pixmap->hdc = p->pd.hDC; pixmap->transcolor = DW_RGB_TRANSPARENT; +#ifdef GDIPLUS + /* Convert the size based on the DPI */ + _convert_dpi(pixmap->hdc, &(pixmap->width), &(pixmap->height), FALSE); +#endif + SelectObject(pixmap->hdc, pixmap->hbm); /* Start the job */