Fix display of sliced images on MS-Windows

* src/w32term.c (x_draw_image_foreground): Fix detection of
scaled images for sliced images.  Scale the original width of
a slice and its coordinates of origin as well.
This commit is contained in:
Eli Zaretskii 2019-03-28 18:00:06 +02:00
parent 2654c0b61b
commit 2da9f8bf42

View file

@ -1896,6 +1896,24 @@ x_draw_image_foreground (struct glyph_string *s)
orig_height = s->slice.height;
}
double w_factor = 1.0, h_factor = 1.0;
bool scaled = false;
int orig_slice_width = s->slice.width,
orig_slice_height = s->slice.height;
int orig_slice_x = s->slice.x, orig_slice_y = s->slice.y;
/* For scaled images we need to restore the original slice's
dimensions and origin coordinates, from before the scaling. */
if (s->img->width != orig_width || s->img->height != orig_height)
{
scaled = true;
w_factor = (double) orig_width / (double) s->img->width;
h_factor = (double) orig_height / (double) s->img->height;
orig_slice_width = s->slice.width * w_factor + 0.5;
orig_slice_height = s->slice.height * h_factor + 0.5;
orig_slice_x = s->slice.x * w_factor + 0.5;
orig_slice_y = s->slice.y * h_factor + 0.5;
}
if (s->img->mask)
{
HDC mask_dc = CreateCompatibleDC (s->hdc);
@ -1903,7 +1921,7 @@ x_draw_image_foreground (struct glyph_string *s)
SetTextColor (s->hdc, RGB (255, 255, 255));
SetBkColor (s->hdc, RGB (0, 0, 0));
if (s->slice.width == orig_width && s->slice.height == orig_height)
if (!scaled)
{
BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
compat_hdc, s->slice.x, s->slice.y, SRCINVERT);
@ -1922,14 +1940,14 @@ x_draw_image_foreground (struct glyph_string *s)
&& (pmode = SetStretchBltMode (s->hdc, HALFTONE)) != 0)
SetBrushOrgEx (s->hdc, 0, 0, NULL);
StretchBlt (s->hdc, x, y, s->slice.width, s->slice.height,
compat_hdc, s->slice.x, s->slice.y,
orig_width, orig_height, SRCINVERT);
compat_hdc, orig_slice_x, orig_slice_y,
orig_slice_width, orig_slice_height, SRCINVERT);
StretchBlt (s->hdc, x, y, s->slice.width, s->slice.height,
mask_dc, s->slice.x, s->slice.y,
orig_width, orig_height, SRCAND);
mask_dc, orig_slice_x, orig_slice_y,
orig_slice_width, orig_slice_height, SRCAND);
StretchBlt (s->hdc, x, y, s->slice.width, s->slice.height,
compat_hdc, s->slice.x, s->slice.y,
orig_width, orig_height, SRCINVERT);
compat_hdc, orig_slice_x, orig_slice_y,
orig_slice_width, orig_slice_height, SRCINVERT);
if (pmode)
SetStretchBltMode (s->hdc, pmode);
}
@ -1940,7 +1958,7 @@ x_draw_image_foreground (struct glyph_string *s)
{
SetTextColor (s->hdc, s->gc->foreground);
SetBkColor (s->hdc, s->gc->background);
if (s->slice.width == orig_width && s->slice.height == orig_height)
if (!scaled)
BitBlt (s->hdc, x, y, s->slice.width, s->slice.height,
compat_hdc, s->slice.x, s->slice.y, SRCCOPY);
else
@ -1951,8 +1969,8 @@ x_draw_image_foreground (struct glyph_string *s)
&& (pmode = SetStretchBltMode (s->hdc, HALFTONE)) != 0)
SetBrushOrgEx (s->hdc, 0, 0, NULL);
StretchBlt (s->hdc, x, y, s->slice.width, s->slice.height,
compat_hdc, s->slice.x, s->slice.y,
orig_width, orig_height, SRCCOPY);
compat_hdc, orig_slice_x, orig_slice_y,
orig_slice_width, orig_slice_height, SRCCOPY);
if (pmode)
SetStretchBltMode (s->hdc, pmode);
}