From 0474a0d7d4478e967c7bbee93ab3606f0b215e66 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Wed, 10 Feb 2021 22:12:16 +0000 Subject: [PATCH] Remove aliasing on SVG images under scaled NS frames * src/image.c (FRAME_SCALE_FACTOR): New #define for getting frame scale factor. (image_set_transform): (svg_load_image): Use FRAME_SCALE_FACTOR. * src/nsterm.m (ns_frame_scale_factor): Get the scale factor for an NS frame. --- src/image.c | 13 +++++++++++-- src/nsterm.h | 1 + src/nsterm.m | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/image.c b/src/image.c index a124cf91ba0..8137dbea8d7 100644 --- a/src/image.c +++ b/src/image.c @@ -135,6 +135,12 @@ typedef struct ns_bitmap_record Bitmap_Record; # define COLOR_TABLE_SUPPORT 1 #endif +#if defined HAVE_NS +# define FRAME_SCALE_FACTOR(f) ns_frame_scale_factor (f) +#else +# define FRAME_SCALE_FACTOR(f) 1; +#endif + static void image_disable_image (struct frame *, struct image *); static void image_edge_detection (struct frame *, struct image *, Lisp_Object, Lisp_Object); @@ -2207,8 +2213,8 @@ image_set_transform (struct frame *f, struct image *img) /* SVGs are pre-scaled to the correct size. */ if (EQ (image_spec_value (img->spec, QCtype, NULL), Qsvg)) { - width = img->width; - height = img->height; + width = img->width / FRAME_SCALE_FACTOR (f); + height = img->height / FRAME_SCALE_FACTOR (f); } else #endif @@ -10008,6 +10014,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents, compute_image_size (viewbox_width, viewbox_height, img->spec, &width, &height); + width *= FRAME_SCALE_FACTOR (f); + height *= FRAME_SCALE_FACTOR (f); + if (! check_image_size (f, width, height)) { image_size_error (); diff --git a/src/nsterm.h b/src/nsterm.h index eae1d0725ea..017c2394ef1 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1252,6 +1252,7 @@ struct input_event; extern void ns_init_events (struct input_event *); extern void ns_finish_events (void); +extern double ns_frame_scale_factor (struct frame *); #ifdef NS_IMPL_GNUSTEP extern char gnustep_base_version[]; /* version tracking */ diff --git a/src/nsterm.m b/src/nsterm.m index 1b2328628ee..ca240eb55f1 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -857,6 +857,17 @@ ns_row_rect (struct window *w, struct glyph_row *row, } +double +ns_frame_scale_factor (struct frame *f) +{ +#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED > 1060 + return [[FRAME_NS_VIEW (f) window] backingScaleFactor]; +#else + return [[FRAME_NS_VIEW (f) window] userSpaceScaleFactor]; +#endif +} + + /* ========================================================================== Focus (clipping) and screen update -- 2.39.2