comparison win/dw.c @ 1683:19c34a1c1489

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.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 30 Apr 2012 07:13:14 +0000
parents ea749fb90f7e
children 31dd366acfc8
comparison
equal deleted inserted replaced
1682:ea749fb90f7e 1683:19c34a1c1489
10100 if(!pixmap) 10100 if(!pixmap)
10101 ReleaseDC(handle, hdcPaint); 10101 ReleaseDC(handle, hdcPaint);
10102 #endif 10102 #endif
10103 } 10103 }
10104 10104
10105 #ifdef GDIPLUS
10106 /* Internal function to increase or decrease coordinates/sizes
10107 * by the difference of the screen DPI (96) and the context DPI.
10108 */
10109 void _convert_dpi(HDC hdc, int *x, int *y, int mult)
10110 {
10111 float ratiox = (float)GetDeviceCaps(hdc, LOGPIXELSX)/96.0;
10112 float ratioy = (float)GetDeviceCaps(hdc, LOGPIXELSY)/96.0;
10113 if(mult)
10114 {
10115 *x *= ratiox;
10116 *y *= ratioy;
10117 }
10118 else
10119 {
10120 *x /= ratiox;
10121 *y /= ratioy;
10122 }
10123 }
10124 #endif
10125
10105 /* Draw text on a window (preferably a render window). 10126 /* Draw text on a window (preferably a render window).
10106 * Parameters: 10127 * Parameters:
10107 * handle: Handle to the window. 10128 * handle: Handle to the window.
10108 * pixmap: Handle to the pixmap. (choose only one of these) 10129 * pixmap: Handle to the pixmap. (choose only one of these)
10109 * x: X coordinate. 10130 * x: X coordinate.
10116 int mustdelete = 0; 10137 int mustdelete = 0;
10117 HFONT hFont = 0, oldFont = 0; 10138 HFONT hFont = 0, oldFont = 0;
10118 ColorInfo *cinfo = NULL; 10139 ColorInfo *cinfo = NULL;
10119 COLORREF background; 10140 COLORREF background;
10120 TCHAR *wtext = UTF8toWide(text); 10141 TCHAR *wtext = UTF8toWide(text);
10121 POINT pt;
10122 10142
10123 if(handle) 10143 if(handle)
10124 hdc = GetDC(handle); 10144 hdc = GetDC(handle);
10125 else if(pixmap) 10145 else if(pixmap)
10126 hdc = pixmap->hdc; 10146 hdc = pixmap->hdc;
10149 else 10169 else
10150 { 10170 {
10151 SetBkMode(hdc, OPAQUE); 10171 SetBkMode(hdc, OPAQUE);
10152 SetBkColor(hdc, background); 10172 SetBkColor(hdc, background);
10153 } 10173 }
10154 pt.x = x; 10174 #ifdef GDIPLUS
10155 pt.y = y; 10175 _convert_dpi(hdc, &x, &y, TRUE);
10156 #ifdef GDIPLUS1
10157 LPtoDP(hdc, &pt, 1);
10158 #endif 10176 #endif
10159 TextOut(hdc, pt.x, pt.y, wtext, (int)_tcslen(wtext)); 10177 TextOut(hdc, x, y, wtext, (int)_tcslen(wtext));
10160 if(oldFont) 10178 if(oldFont)
10161 SelectObject(hdc, oldFont); 10179 SelectObject(hdc, oldFont);
10162 if(mustdelete) 10180 if(mustdelete)
10163 DeleteObject(hFont); 10181 DeleteObject(hFont);
10164 if(!pixmap) 10182 if(!pixmap)
10208 } 10226 }
10209 } 10227 }
10210 oldFont = SelectObject(hdc, hFont); 10228 oldFont = SelectObject(hdc, hFont);
10211 10229
10212 GetTextExtentPoint32(hdc, wtext, (int)_tcslen(wtext), &sz); 10230 GetTextExtentPoint32(hdc, wtext, (int)_tcslen(wtext), &sz);
10231
10232 #ifdef GDIPLUS
10233 _convert_dpi(hdc, &(sz.cx), &(sz.cy), FALSE);
10234 #endif
10213 10235
10214 if(width) 10236 if(width)
10215 *width = sz.cx; 10237 *width = sz.cx;
10216 10238
10217 if(height) 10239 if(height)
10614 { 10636 {
10615 swidth = width; 10637 swidth = width;
10616 sheight = height; 10638 sheight = height;
10617 } 10639 }
10618 10640
10641 #ifdef GDIPLUS
10642 /* Do conversion on all the coordinates */
10643 _convert_dpi(hdcdest, &xdest, &ydest, TRUE);
10644 _convert_dpi(hdcdest, &width, &height, TRUE);
10645 _convert_dpi(hdcsrc, &xsrc, &ysrc, TRUE);
10646 _convert_dpi(hdcsrc, &swidth, &sheight, TRUE);
10647 #endif
10648
10619 /* If it is a 32bpp bitmap (with alpha) use AlphaBlend unless it fails */ 10649 /* If it is a 32bpp bitmap (with alpha) use AlphaBlend unless it fails */
10620 if ( srcp && srcp->depth == 32 && AlphaBlend( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, swidth, sheight, bf ) ) 10650 if ( srcp && srcp->depth == 32 && AlphaBlend( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, swidth, sheight, bf ) )
10621 { 10651 {
10622 /* Don't do anything */ 10652 /* Don't do anything */
10623 } 10653 }
11687 pixmap->height = GetDeviceCaps(p->pd.hDC, VERTRES); 11717 pixmap->height = GetDeviceCaps(p->pd.hDC, VERTRES);
11688 11718
11689 pixmap->hbm = CreateCompatibleBitmap(p->pd.hDC, pixmap->width, pixmap->height); 11719 pixmap->hbm = CreateCompatibleBitmap(p->pd.hDC, pixmap->width, pixmap->height);
11690 pixmap->hdc = p->pd.hDC; 11720 pixmap->hdc = p->pd.hDC;
11691 pixmap->transcolor = DW_RGB_TRANSPARENT; 11721 pixmap->transcolor = DW_RGB_TRANSPARENT;
11722
11723 #ifdef GDIPLUS
11724 /* Convert the size based on the DPI */
11725 _convert_dpi(pixmap->hdc, &(pixmap->width), &(pixmap->height), FALSE);
11726 #endif
11692 11727
11693 SelectObject(pixmap->hdc, pixmap->hbm); 11728 SelectObject(pixmap->hdc, pixmap->hbm);
11694 11729
11695 /* Start the job */ 11730 /* Start the job */
11696 StartDoc(p->pd.hDC, &(p->di)); 11731 StartDoc(p->pd.hDC, &(p->di));