gdiplus: Don't require an HDC for the convert_unit function.

This commit is contained in:
Vincent Povirk 2010-08-08 15:24:45 -05:00 committed by Alexandre Julliard
parent e2b4d4e713
commit 85a5710688
4 changed files with 30 additions and 21 deletions

View File

@ -314,18 +314,18 @@ GpStatus hresult_to_status(HRESULT res)
}
/* converts a given unit to its value in pixels */
REAL convert_unit(HDC hdc, GpUnit unit)
REAL convert_unit(REAL logpixels, GpUnit unit)
{
switch(unit)
{
case UnitInch:
return (REAL) GetDeviceCaps(hdc, LOGPIXELSX);
return logpixels;
case UnitPoint:
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 72.0;
return logpixels / 72.0;
case UnitDocument:
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 300.0;
return logpixels / 300.0;
case UnitMillimeter:
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 25.4;
return logpixels / 25.4;
case UnitWorld:
ERR("cannot convert UnitWorld\n");
return 0.0;

View File

@ -47,7 +47,7 @@ extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
REAL startAngle, REAL sweepAngle);
extern REAL gdiplus_atan2(REAL dy, REAL dx);
extern GpStatus hresult_to_status(HRESULT res);
extern REAL convert_unit(HDC hdc, GpUnit unit);
extern REAL convert_unit(REAL logpixels, GpUnit unit);
extern void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,
REAL *y1, REAL *x2, REAL *y2);

View File

@ -84,6 +84,12 @@ static BYTE convert_path_point_type(BYTE type)
return ret;
}
static REAL graphics_res(GpGraphics *graphics)
{
if (graphics->image) return graphics->image->xres;
else return (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
}
static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
{
HPEN gdipen;
@ -108,7 +114,7 @@ static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
(pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
width *= pen->width * convert_unit(graphics->hdc,
width *= pen->width * convert_unit(graphics_res(graphics),
pen->unit == UnitWorld ? graphics->unit : pen->unit);
}
@ -156,7 +162,7 @@ static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
GpMatrix *matrix;
int i;
unitscale = convert_unit(graphics->hdc, graphics->unit);
unitscale = convert_unit(graphics_res(graphics), graphics->unit);
/* apply page scale */
if(graphics->unit != UnitDisplay)
@ -4602,7 +4608,7 @@ GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace
stat = GdipCreateMatrix(&matrix);
if (stat == Ok)
{
unitscale = convert_unit(graphics->hdc, graphics->unit);
unitscale = convert_unit(graphics_res(graphics), graphics->unit);
if(graphics->unit != UnitDisplay)
unitscale *= graphics->scale;

View File

@ -2008,14 +2008,15 @@ GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
if(image->type == ImageTypeMetafile){
HDC hdc = GetDC(0);
*height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Height;
*width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Width;
REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(0, hdc);
*height = convert_unit(res, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Height;
*width = convert_unit(res, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Width;
}
else if(image->type == ImageTypeBitmap){
@ -2072,11 +2073,12 @@ GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
if(image->type == ImageTypeMetafile){
HDC hdc = GetDC(0);
*height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Height);
REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(0, hdc);
*height = roundr(convert_unit(res, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Height);
}
else if(image->type == ImageTypeBitmap)
*height = ((GpBitmap*)image)->height;
@ -2178,11 +2180,12 @@ GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
if(image->type == ImageTypeMetafile){
HDC hdc = GetDC(0);
*width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Width);
REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(0, hdc);
*width = roundr(convert_unit(res, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Width);
}
else if(image->type == ImageTypeBitmap)
*width = ((GpBitmap*)image)->width;