summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2019-03-28 18:00:06 +0200
committerEli Zaretskii <eliz@gnu.org>2019-03-28 18:00:06 +0200
commit2da9f8bf4222fda504f43b4757e154999cdbbf2c (patch)
tree1d26e676a935a1897906a425c7eb8b9d6a8281dd
parent2654c0b61b2cb8ee14d84f042ae6fc605adf64a8 (diff)
downloademacs-2da9f8bf4222fda504f43b4757e154999cdbbf2c.tar.gz
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.
-rw-r--r--src/w32term.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/w32term.c b/src/w32term.c
index 0f0d6482fc3..4d5f2e7c3cc 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -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);
}