gdiplus: Store device resolution in the graphics object.

This commit is contained in:
Dmitry Timoshkov 2012-07-24 17:18:48 +09:00 committed by Alexandre Julliard
parent 9697829511
commit e536a128f7
4 changed files with 60 additions and 26 deletions

View File

@ -156,6 +156,7 @@ struct GpGraphics{
TextRenderingHint texthint;
GpUnit unit; /* page unit */
REAL scale; /* page scale */
REAL xres, yres;
GpMatrix * worldtrans; /* world transform */
BOOL busy; /* hdc handle obtained by GdipGetDC */
GpRegion *clip;

View File

@ -84,12 +84,6 @@ 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 COLORREF get_gdi_brush_color(const GpBrush *brush)
{
ARGB argb;
@ -260,7 +254,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_res(graphics),
width *= pen->width * convert_unit(graphics->xres,
pen->unit == UnitWorld ? graphics->unit : pen->unit);
}
@ -313,18 +307,22 @@ static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace d
static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
GpPointF *ptf, INT count)
{
REAL unitscale;
REAL scale_x, scale_y;
GpMatrix *matrix;
int i;
unitscale = convert_unit(graphics_res(graphics), graphics->unit);
scale_x = convert_unit(graphics->xres, graphics->unit);
scale_y = convert_unit(graphics->yres, graphics->unit);
/* apply page scale */
if(graphics->unit != UnitDisplay)
unitscale *= graphics->scale;
{
scale_x *= graphics->scale;
scale_y *= graphics->scale;
}
GdipCloneMatrix(graphics->worldtrans, &matrix);
GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
GdipScaleMatrix(matrix, scale_x, scale_y, MatrixOrderAppend);
GdipTransformMatrixPoints(matrix, ptf, count);
GdipDeleteMatrix(matrix);
@ -2200,6 +2198,8 @@ GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **gra
(*graphics)->compmode = CompositingModeSourceOver;
(*graphics)->unit = UnitDisplay;
(*graphics)->scale = 1.0;
(*graphics)->xres = GetDeviceCaps(hdc, LOGPIXELSX);
(*graphics)->yres = GetDeviceCaps(hdc, LOGPIXELSY);
(*graphics)->busy = FALSE;
(*graphics)->textcontrast = 4;
list_init(&(*graphics)->containers);
@ -2239,6 +2239,8 @@ GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics)
(*graphics)->compmode = CompositingModeSourceOver;
(*graphics)->unit = UnitDisplay;
(*graphics)->scale = 1.0;
(*graphics)->xres = image->xres;
(*graphics)->yres = image->yres;
(*graphics)->busy = FALSE;
(*graphics)->textcontrast = 4;
list_init(&(*graphics)->containers);
@ -5792,11 +5794,7 @@ GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
if(graphics->busy)
return ObjectBusy;
if (graphics->image)
*dpi = graphics->image->xres;
else
*dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
*dpi = graphics->xres;
return Ok;
}
@ -5810,11 +5808,7 @@ GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
if(graphics->busy)
return ObjectBusy;
if (graphics->image)
*dpi = graphics->image->yres;
else
*dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
*dpi = graphics->yres;
return Ok;
}
@ -5999,14 +5993,18 @@ static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace d
GpCoordinateSpace src_space, GpMatrix **matrix)
{
GpStatus stat = GdipCreateMatrix(matrix);
REAL unitscale;
REAL scale_x, scale_y;
if (dst_space != src_space && stat == Ok)
{
unitscale = convert_unit(graphics_res(graphics), graphics->unit);
scale_x = convert_unit(graphics->xres, graphics->unit);
scale_y = convert_unit(graphics->yres, graphics->unit);
if(graphics->unit != UnitDisplay)
unitscale *= graphics->scale;
{
scale_x *= graphics->scale;
scale_y *= graphics->scale;
}
/* transform from src_space to CoordinateSpacePage */
switch (src_space)
@ -6017,7 +6015,7 @@ static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace d
case CoordinateSpacePage:
break;
case CoordinateSpaceDevice:
GdipScaleMatrix(*matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
GdipScaleMatrix(*matrix, 1.0/scale_x, 1.0/scale_y, MatrixOrderAppend);
break;
}
@ -6040,7 +6038,7 @@ static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace d
case CoordinateSpacePage:
break;
case CoordinateSpaceDevice:
GdipScaleMatrix(*matrix, unitscale, unitscale, MatrixOrderAppend);
GdipScaleMatrix(*matrix, scale_x, scale_y, MatrixOrderAppend);
break;
}
}

View File

@ -2305,7 +2305,11 @@ GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
stat = GdipCreateFromHDC(hdc, graphics);
if (stat == Ok)
{
(*graphics)->image = image;
(*graphics)->xres = image->xres;
(*graphics)->yres = image->yres;
}
}
else if (image->type == ImageTypeMetafile)
stat = METAFILE_GetGraphicsContext((GpMetafile*)image, graphics);

View File

@ -1517,6 +1517,7 @@ static void test_resolution(void)
{
GpStatus stat;
GpBitmap *bitmap;
GpGraphics *graphics;
REAL res=-1.0;
HDC screendc;
int screenxres, screenyres;
@ -1560,6 +1561,15 @@ static void test_resolution(void)
expect(Ok, stat);
expectf((REAL)screenyres, res);
stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
expect(Ok, stat);
stat = GdipGetDpiX(graphics, &res);
expect(Ok, stat);
expectf((REAL)screenxres, res);
stat = GdipGetDpiY(graphics, &res);
expect(Ok, stat);
expectf((REAL)screenyres, res);
/* test changing the resolution */
stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
expect(Ok, stat);
@ -1572,6 +1582,27 @@ static void test_resolution(void)
expect(Ok, stat);
expectf(screenyres*3.0, res);
stat = GdipGetDpiX(graphics, &res);
expect(Ok, stat);
expectf((REAL)screenxres, res);
stat = GdipGetDpiY(graphics, &res);
expect(Ok, stat);
expectf((REAL)screenyres, res);
stat = GdipDeleteGraphics(graphics);
expect(Ok, stat);
stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
expect(Ok, stat);
stat = GdipGetDpiX(graphics, &res);
expect(Ok, stat);
expectf(screenxres*2.0, res);
stat = GdipGetDpiY(graphics, &res);
expect(Ok, stat);
expectf(screenyres*3.0, res);
stat = GdipDeleteGraphics(graphics);
expect(Ok, stat);
stat = GdipDisposeImage((GpImage*)bitmap);
expect(Ok, stat);
}