Commit 85a57106 authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

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

parent e2b4d4e7
...@@ -314,18 +314,18 @@ GpStatus hresult_to_status(HRESULT res) ...@@ -314,18 +314,18 @@ GpStatus hresult_to_status(HRESULT res)
} }
/* converts a given unit to its value in pixels */ /* 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) switch(unit)
{ {
case UnitInch: case UnitInch:
return (REAL) GetDeviceCaps(hdc, LOGPIXELSX); return logpixels;
case UnitPoint: case UnitPoint:
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 72.0; return logpixels / 72.0;
case UnitDocument: case UnitDocument:
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 300.0; return logpixels / 300.0;
case UnitMillimeter: case UnitMillimeter:
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 25.4; return logpixels / 25.4;
case UnitWorld: case UnitWorld:
ERR("cannot convert UnitWorld\n"); ERR("cannot convert UnitWorld\n");
return 0.0; return 0.0;
......
...@@ -47,7 +47,7 @@ extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2, ...@@ -47,7 +47,7 @@ extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
REAL startAngle, REAL sweepAngle); REAL startAngle, REAL sweepAngle);
extern REAL gdiplus_atan2(REAL dy, REAL dx); extern REAL gdiplus_atan2(REAL dy, REAL dx);
extern GpStatus hresult_to_status(HRESULT res); 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, extern void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,
REAL *y1, REAL *x2, REAL *y2); REAL *y1, REAL *x2, REAL *y2);
......
...@@ -84,6 +84,12 @@ static BYTE convert_path_point_type(BYTE type) ...@@ -84,6 +84,12 @@ static BYTE convert_path_point_type(BYTE type)
return ret; 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) static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
{ {
HPEN gdipen; HPEN gdipen;
...@@ -108,7 +114,7 @@ static INT prepare_dc(GpGraphics *graphics, GpPen *pen) ...@@ -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) + 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); (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); pen->unit == UnitWorld ? graphics->unit : pen->unit);
} }
...@@ -156,7 +162,7 @@ static void transform_and_round_points(GpGraphics *graphics, POINT *pti, ...@@ -156,7 +162,7 @@ static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
GpMatrix *matrix; GpMatrix *matrix;
int i; int i;
unitscale = convert_unit(graphics->hdc, graphics->unit); unitscale = convert_unit(graphics_res(graphics), graphics->unit);
/* apply page scale */ /* apply page scale */
if(graphics->unit != UnitDisplay) if(graphics->unit != UnitDisplay)
...@@ -4602,7 +4608,7 @@ GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace ...@@ -4602,7 +4608,7 @@ GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace
stat = GdipCreateMatrix(&matrix); stat = GdipCreateMatrix(&matrix);
if (stat == Ok) if (stat == Ok)
{ {
unitscale = convert_unit(graphics->hdc, graphics->unit); unitscale = convert_unit(graphics_res(graphics), graphics->unit);
if(graphics->unit != UnitDisplay) if(graphics->unit != UnitDisplay)
unitscale *= graphics->scale; unitscale *= graphics->scale;
......
...@@ -2008,14 +2008,15 @@ GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width, ...@@ -2008,14 +2008,15 @@ GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
if(image->type == ImageTypeMetafile){ if(image->type == ImageTypeMetafile){
HDC hdc = GetDC(0); HDC hdc = GetDC(0);
REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
*height = convert_unit(hdc, ((GpMetafile*)image)->unit) * ReleaseDC(0, hdc);
*height = convert_unit(res, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Height; ((GpMetafile*)image)->bounds.Height;
*width = convert_unit(hdc, ((GpMetafile*)image)->unit) * *width = convert_unit(res, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Width; ((GpMetafile*)image)->bounds.Width;
ReleaseDC(0, hdc);
} }
else if(image->type == ImageTypeBitmap){ else if(image->type == ImageTypeBitmap){
...@@ -2072,11 +2073,12 @@ GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height) ...@@ -2072,11 +2073,12 @@ GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
if(image->type == ImageTypeMetafile){ if(image->type == ImageTypeMetafile){
HDC hdc = GetDC(0); HDC hdc = GetDC(0);
REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
*height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Height);
ReleaseDC(0, hdc); ReleaseDC(0, hdc);
*height = roundr(convert_unit(res, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Height);
} }
else if(image->type == ImageTypeBitmap) else if(image->type == ImageTypeBitmap)
*height = ((GpBitmap*)image)->height; *height = ((GpBitmap*)image)->height;
...@@ -2178,11 +2180,12 @@ GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width) ...@@ -2178,11 +2180,12 @@ GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
if(image->type == ImageTypeMetafile){ if(image->type == ImageTypeMetafile){
HDC hdc = GetDC(0); HDC hdc = GetDC(0);
REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
*width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Width);
ReleaseDC(0, hdc); ReleaseDC(0, hdc);
*width = roundr(convert_unit(res, ((GpMetafile*)image)->unit) *
((GpMetafile*)image)->bounds.Width);
} }
else if(image->type == ImageTypeBitmap) else if(image->type == ImageTypeBitmap)
*width = ((GpBitmap*)image)->width; *width = ((GpBitmap*)image)->width;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment