gdiplus: Replace convert_unit() by a clearer units_to_pixels() helper.

This commit is contained in:
Dmitry Timoshkov 2012-08-15 12:04:52 +09:00 committed by Alexandre Julliard
parent 6f4625559e
commit 6bb353858e
4 changed files with 11 additions and 59 deletions

View File

@ -320,29 +320,6 @@ GpStatus hresult_to_status(HRESULT res)
} }
} }
/* converts a given unit to its value in inches */
REAL convert_unit(REAL logpixels, GpUnit unit)
{
switch(unit)
{
case UnitInch:
return logpixels;
case UnitPoint:
return logpixels / 72.0;
case UnitDocument:
return logpixels / 300.0;
case UnitMillimeter:
return logpixels / 25.4;
case UnitWorld:
ERR("cannot convert UnitWorld\n");
return 0.0;
case UnitPixel:
case UnitDisplay:
default:
return 1.0;
}
}
/* converts a given unit to its value in pixels */ /* converts a given unit to its value in pixels */
REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
{ {

View File

@ -48,7 +48,6 @@ extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
REAL startAngle, REAL sweepAngle) DECLSPEC_HIDDEN; REAL startAngle, REAL sweepAngle) DECLSPEC_HIDDEN;
extern REAL gdiplus_atan2(REAL dy, REAL dx) DECLSPEC_HIDDEN; extern REAL gdiplus_atan2(REAL dy, REAL dx) DECLSPEC_HIDDEN;
extern GpStatus hresult_to_status(HRESULT res) DECLSPEC_HIDDEN; extern GpStatus hresult_to_status(HRESULT res) DECLSPEC_HIDDEN;
extern REAL convert_unit(REAL logpixels, GpUnit unit) DECLSPEC_HIDDEN;
extern REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN; extern REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
extern REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN; extern REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
extern REAL units_scale(GpUnit from, GpUnit to, REAL dpi) DECLSPEC_HIDDEN; extern REAL units_scale(GpUnit from, GpUnit to, REAL dpi) DECLSPEC_HIDDEN;

View File

@ -254,8 +254,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->xres, width *= units_to_pixels(pen->width, pen->unit == UnitWorld ? graphics->unit : pen->unit, graphics->xres);
pen->unit == UnitWorld ? graphics->unit : pen->unit);
} }
if(pen->dash == DashStyleCustom){ if(pen->dash == DashStyleCustom){
@ -311,8 +310,8 @@ static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
GpMatrix *matrix; GpMatrix *matrix;
int i; int i;
scale_x = convert_unit(graphics->xres, graphics->unit); scale_x = units_to_pixels(1.0, graphics->unit, graphics->xres);
scale_y = convert_unit(graphics->yres, graphics->unit); scale_y = units_to_pixels(1.0, graphics->unit, graphics->yres);
/* apply page scale */ /* apply page scale */
if(graphics->unit != UnitDisplay) if(graphics->unit != UnitDisplay)
@ -5990,8 +5989,8 @@ static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace d
if (dst_space != src_space && stat == Ok) if (dst_space != src_space && stat == Ok)
{ {
scale_x = convert_unit(graphics->xres, graphics->unit); scale_x = units_to_pixels(1.0, graphics->unit, graphics->xres);
scale_y = convert_unit(graphics->yres, graphics->unit); scale_y = units_to_pixels(1.0, graphics->unit, graphics->yres);
if(graphics->unit != UnitDisplay) if(graphics->unit != UnitDisplay)
{ {

View File

@ -2256,18 +2256,9 @@ GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
return InvalidParameter; return InvalidParameter;
if(image->type == ImageTypeMetafile){ if(image->type == ImageTypeMetafile){
HDC hdc = GetDC(0); *height = units_to_pixels(((GpMetafile*)image)->bounds.Height, ((GpMetafile*)image)->unit, image->yres);
REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX); *width = units_to_pixels(((GpMetafile*)image)->bounds.Width, ((GpMetafile*)image)->unit, image->xres);
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){ else if(image->type == ImageTypeBitmap){
*height = ((GpBitmap*)image)->height; *height = ((GpBitmap*)image)->height;
*width = ((GpBitmap*)image)->width; *width = ((GpBitmap*)image)->width;
@ -2326,15 +2317,8 @@ GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
if(!image || !height) if(!image || !height)
return InvalidParameter; return InvalidParameter;
if(image->type == ImageTypeMetafile){ if(image->type == ImageTypeMetafile)
HDC hdc = GetDC(0); *height = units_to_pixels(((GpMetafile*)image)->bounds.Height, ((GpMetafile*)image)->unit, image->yres);
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) else if(image->type == ImageTypeBitmap)
*height = ((GpBitmap*)image)->height; *height = ((GpBitmap*)image)->height;
else else
@ -2433,15 +2417,8 @@ GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
if(!image || !width) if(!image || !width)
return InvalidParameter; return InvalidParameter;
if(image->type == ImageTypeMetafile){ if(image->type == ImageTypeMetafile)
HDC hdc = GetDC(0); *width = units_to_pixels(((GpMetafile*)image)->bounds.Width, ((GpMetafile*)image)->unit, image->xres);
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) else if(image->type == ImageTypeBitmap)
*width = ((GpBitmap*)image)->width; *width = ((GpBitmap*)image)->width;
else else