emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 2da9f8b: Fix display of sliced images on MS-Windows


From: Eli Zaretskii
Subject: [Emacs-diffs] master 2da9f8b: Fix display of sliced images on MS-Windows
Date: Thu, 28 Mar 2019 12:01:47 -0400 (EDT)

branch: master
commit 2da9f8bf4222fda504f43b4757e154999cdbbf2c
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    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.
---
 src/w32term.c | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/w32term.c b/src/w32term.c
index 0f0d648..4d5f2e7 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);
            }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]