unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* "Fix" sag scaling for hidpi
@ 2021-02-04 20:49 Yuan Fu
  2021-02-04 22:07 ` Stefan Monnier
  0 siblings, 1 reply; 192+ messages in thread
From: Yuan Fu @ 2021-02-04 20:49 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 614 bytes --]

To get crisp images on hidpi displays, a common approach is to load an image double de dimension and rescale it down. E.g., load an 200x200 image and rescale it to 100x100. In Emacs this can be done by

(insert-image (create-image "200x200img.png" 'png nil :scale 0.5))

And Emacs will display a crisp 100x100 image in the buffer. However, this doesn’t work for sag images. If I do

(progn
  (require 'svg)
  (let ((svg (svg-create 200 200)))
    (svg-text svg "test"
              :font-size 100
              :y 150)
    (insert-image (svg-image svg :scale 0.5))))

The image is still blurry:


[-- Attachment #2: Screen Shot 2021-02-04 at 3.43.05 PM.png --]
[-- Type: image/png, Size: 7332 bytes --]

[-- Attachment #3: Type: text/plain, Size: 206 bytes --]



Turns out image.c resolves the dimension for svg images before generating them and skips rescaling all together. The following patch changes that behavior and allows me to generate crisp svg images:


[-- Attachment #4: Screen Shot 2021-02-04 at 3.40.38 PM.png --]
[-- Type: image/png, Size: 9238 bytes --]

[-- Attachment #5: Type: text/plain, Size: 16 bytes --]



WDYT?

Yuan



[-- Attachment #6: svg-scale.patch --]
[-- Type: application/octet-stream, Size: 1483 bytes --]

From e64330c4dd1519424b9ab20b72071498dc1f5f9b Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Thu, 4 Feb 2021 15:30:38 -0500
Subject: [PATCH] demo

---
 src/image.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/image.c b/src/image.c
index a124cf91ba..4b2504bb52 100644
--- a/src/image.c
+++ b/src/image.c
@@ -2203,16 +2203,7 @@ image_set_transform (struct frame *f, struct image *img)
   /* Determine size.  */
   int width, height;
 
-#ifdef HAVE_RSVG
-  /* SVGs are pre-scaled to the correct size.  */
-  if (EQ (image_spec_value (img->spec, QCtype, NULL), Qsvg))
-    {
-      width = img->width;
-      height = img->height;
-    }
-  else
-#endif
-    compute_image_size (img->width, img->height, img->spec, &width, &height);
+  compute_image_size (img->width, img->height, img->spec, &width, &height);
 
   /* Determine rotation.  */
   double rotation = 0.0;
@@ -10008,6 +9999,14 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
   compute_image_size (viewbox_width, viewbox_height, img->spec,
                       &width, &height);
 
+  Lisp_Object value = image_spec_value (img->spec, QCscale, NULL);
+  if (NUMBERP (value))
+    {
+      double scale = XFLOATINT(value);
+      width /= scale;
+      height /= scale;
+    }
+
   if (! check_image_size (f, width, height))
     {
       image_size_error ();
-- 
2.24.3 (Apple Git-128)


[-- Attachment #7: Type: text/plain, Size: 2 bytes --]




^ permalink raw reply related	[flat|nested] 192+ messages in thread

end of thread, other threads:[~2021-02-17 22:52 UTC | newest]

Thread overview: 192+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-04 20:49 "Fix" sag scaling for hidpi Yuan Fu
2021-02-04 22:07 ` Stefan Monnier
2021-02-04 23:10   ` Yuan Fu
2021-02-05  9:02     ` Lars Ingebrigtsen
2021-02-05 10:24       ` Robert Pluim
2021-02-06 10:00         ` Lars Ingebrigtsen
2021-02-06 11:15           ` Eli Zaretskii
2021-02-06 11:35             ` Lars Ingebrigtsen
2021-02-06 12:20               ` Eli Zaretskii
2021-02-07 12:05                 ` Lars Ingebrigtsen
2021-02-07 13:14               ` Robert Pluim
2021-02-09 20:01               ` Alan Third
2021-02-10  8:29                 ` Lars Ingebrigtsen
2021-02-10 18:00                 ` Yuan Fu
2021-02-10 18:07                   ` Yuan Fu
2021-02-10 18:17                     ` Lars Ingebrigtsen
2021-02-10 18:24                       ` Robert Pluim
2021-02-10 18:41                         ` Lars Ingebrigtsen
2021-02-10 18:52                         ` Basil L. Contovounesios
2021-02-11 13:53                           ` Robert Pluim
2021-02-11 14:30                             ` Basil L. Contovounesios
2021-02-11 15:11                               ` Robert Pluim
2021-02-11 22:18                                 ` Cleaning out old X11 toolkits? chad
2021-02-12  7:09                                   ` Eli Zaretskii
2021-02-12  8:44                                     ` Colin Baxter
2021-02-12 11:22                                       ` Eli Zaretskii
2021-02-12  9:30                                     ` Robert Pluim
2021-02-12  9:35                                       ` Lars Ingebrigtsen
2021-02-12 10:00                                         ` Robert Pluim
2021-02-12 10:02                                           ` Lars Ingebrigtsen
2021-02-12 10:04                                             ` Lars Ingebrigtsen
2021-02-12 10:18                                               ` Robert Pluim
2021-02-12 10:30                                                 ` Lars Ingebrigtsen
2021-02-12 21:49                                         ` Jean Louis
2021-02-12 22:03                                           ` Jean Louis
2021-02-12 22:45                                             ` Stefan Kangas
2021-02-13  7:51                                           ` Eli Zaretskii
2021-02-13 12:05                                             ` Jean Louis
2021-02-12 11:28                                       ` Eli Zaretskii
2021-02-12 11:38                                         ` tomas
2021-02-12 13:26                                         ` Robert Pluim
2021-02-12 13:57                                           ` Basil L. Contovounesios
2021-02-15 16:49                                         ` Sean Whitton
2021-02-12 11:47                                     ` Ulrich Mueller
2021-02-12 10:00                                   ` martin rudalics
2021-02-12 10:14                                     ` Robert Pluim
2021-02-12 17:56                                       ` martin rudalics
2021-02-12 18:14                                         ` Merging native-comp and pgtk Stefan Monnier
2021-02-12 18:36                                           ` Eli Zaretskii
2021-02-12 22:29                                             ` Andy Moreton
2021-02-12 23:06                                               ` Stefan Monnier
2021-02-12 23:28                                                 ` Andy Moreton
2021-02-13  9:39                                                 ` Eli Zaretskii
2021-02-13 13:27                                                   ` Stefan Monnier
2021-02-13 14:10                                                     ` Andy Moreton
2021-02-13 14:14                                                       ` Eli Zaretskii
2021-02-13 14:17                                                     ` Eli Zaretskii
2021-02-13 15:48                                                     ` martin rudalics
2021-02-13 15:58                                                       ` Eli Zaretskii
2021-02-14  8:34                                                         ` martin rudalics
2021-02-13  9:20                                               ` Eli Zaretskii
2021-02-13 13:07                                                 ` Andy Moreton
2021-02-13 14:16                                                   ` Eli Zaretskii
2021-02-13 18:01                                                     ` Andy Moreton
2021-02-13 18:12                                                       ` Eli Zaretskii
2021-02-14  7:33                                                 ` Andrea Corallo via Emacs development discussions.
2021-02-14 15:25                                                   ` Eli Zaretskii
2021-02-13  9:26                                               ` Andreas Schwab
2021-02-13 12:45                                                 ` Andy Moreton
2021-02-16 23:22                                               ` Phillip Lord
2021-02-17 15:32                                                 ` Eli Zaretskii
2021-02-17 17:32                                                   ` Andy Moreton
2021-02-17 18:09                                                     ` Óscar Fuentes
2021-02-17 22:20                                                       ` Andy Moreton
2021-02-17 22:52                                                         ` Óscar Fuentes
2021-02-17 19:20                                                     ` Eli Zaretskii
2021-02-12 23:04                                             ` Stefan Monnier
2021-02-13  9:30                                               ` Eli Zaretskii
2021-02-13 13:24                                                 ` Stefan Monnier
2021-02-13 14:15                                                   ` Eli Zaretskii
2021-02-12 21:47                                           ` Andrea Corallo via Emacs development discussions.
2021-02-13  7:39                                             ` Eli Zaretskii
2021-02-13 11:16                                             ` Lars Ingebrigtsen
2021-02-13 11:28                                               ` Tassilo Horn
2021-02-13 11:57                                                 ` Lars Ingebrigtsen
2021-02-13 12:17                                                   ` Dmitry Gutov
2021-02-13 14:53                                                     ` Lars Ingebrigtsen
2021-02-13 20:30                                                       ` Dmitry Gutov
2021-02-13 21:03                                                         ` Lars Ingebrigtsen
2021-02-13 21:30                                                           ` Dmitry Gutov
2021-02-13 21:42                                                             ` Lars Ingebrigtsen
2021-02-13 22:48                                                               ` Lars Ingebrigtsen
2021-02-13 23:44                                                                 ` Tassilo Horn
2021-02-13 17:38                                                   ` Stefan Kangas
2021-02-14 18:36                                                     ` Andrea Corallo via Emacs development discussions.
2021-02-14 19:23                                                       ` Stefan Kangas
2021-02-14 19:32                                                         ` Andrea Corallo via Emacs development discussions.
2021-02-14 23:18                                                           ` Óscar Fuentes
2021-02-15 14:15                                                             ` Andrea Corallo via Emacs development discussions.
2021-02-13 13:41                                               ` Stefan Monnier
2021-02-13 14:18                                                 ` Eli Zaretskii
2021-02-13 20:32                                                   ` Dmitry Gutov
2021-02-14  3:34                                                     ` Eli Zaretskii
2021-02-14  4:32                                                   ` Stefan Monnier
2021-02-13 14:58                                                 ` Lars Ingebrigtsen
2021-02-14 18:34                                                   ` Andrea Corallo via Emacs development discussions.
2021-02-14  7:42                                               ` Andrea Corallo via Emacs development discussions.
2021-02-12 18:32                                         ` Cleaning out old X11 toolkits? Eli Zaretskii
2021-02-13  9:01                                           ` martin rudalics
2021-02-13  9:44                                             ` Eli Zaretskii
2021-02-13 10:29                                               ` martin rudalics
2021-02-14 12:50                                           ` Robert Pluim
2021-02-14 15:53                                             ` Eli Zaretskii
2021-02-15  9:48                                               ` Robert Pluim
2021-02-15 15:23                                                 ` Eli Zaretskii
2021-02-15 16:02                                                   ` Robert Pluim
2021-02-15 16:13                                                     ` tomas
2021-02-15 17:03                                                     ` Eli Zaretskii
2021-02-15 17:20                                                       ` Robert Pluim
2021-02-12 13:04                                     ` Dmitry Gutov
2021-02-12 17:56                                       ` martin rudalics
2021-02-12 18:33                                         ` Eli Zaretskii
2021-02-12 20:09                                           ` martin rudalics
2021-02-12 20:13                                             ` Eli Zaretskii
2021-02-13  9:02                                               ` martin rudalics
2021-02-13  9:47                                                 ` Eli Zaretskii
2021-02-13 10:29                                                 ` Colin Baxter
2021-02-13 13:24                                                   ` martin rudalics
2021-02-13 13:53                                                     ` Ulrich Mueller
2021-02-13 15:49                                                       ` martin rudalics
2021-02-13 19:23                                                         ` Jean Louis
2021-02-14  8:35                                                           ` martin rudalics
2021-02-14  9:33                                                             ` Ulrich Mueller
2021-02-14 17:16                                                               ` martin rudalics
2021-02-14 17:48                                                               ` Eli Zaretskii
2021-02-14 18:18                                                                 ` Andy Moreton
2021-02-14 19:15                                                                   ` Eli Zaretskii
2021-02-14 22:33                                                                     ` Óscar Fuentes
2021-02-15  8:17                                                                     ` martin rudalics
2021-02-15  9:19                                                                     ` Andy Moreton
2021-02-13 14:39                                                     ` Colin Baxter
2021-02-13 14:43                                                       ` Jean Louis
2021-02-13 15:50                                                       ` martin rudalics
2021-02-13 16:04                                                         ` Colin Baxter
2021-02-13 21:42                                                 ` Stefan Monnier
2021-02-14 12:41                                                   ` Robert Pluim
2021-02-14 15:51                                                     ` Eli Zaretskii
2021-02-14 18:18                                                       ` Stefan Monnier
2021-02-14 19:10                                                         ` Eli Zaretskii
2021-02-12 11:20                                   ` Ulrich Mueller
2021-02-12 13:33                                   ` James Cloos
2021-02-12 13:49                                     ` Robert Pluim
2021-02-10 19:19                         ` "Fix" sag scaling for hidpi Stefan Monnier
2021-02-11 14:01                           ` Robert Pluim
2021-02-11 14:59                             ` Stefan Monnier
2021-02-11 15:16                               ` Robert Pluim
2021-02-10 23:55                   ` Alan Third
2021-02-11  2:01                     ` Yuan Fu
2021-02-11 17:34                       ` Yuan Fu
2021-02-11 20:18                         ` Alan Third
2021-02-12 22:47                           ` Alan Third
2021-02-13 11:13                             ` Lars Ingebrigtsen
2021-02-13 11:17                               ` Alan Third
2021-02-13 11:52                                 ` Lars Ingebrigtsen
2021-02-13 12:54                                   ` Alan Third
2021-02-13 13:09                                     ` Alan Third
2021-02-13 15:09                                       ` Lars Ingebrigtsen
2021-02-13 16:00                                         ` Alan Third
2021-02-13 23:30                                           ` Alan Third
2021-02-13 20:09                                         ` Yuan Fu
2021-02-13 21:14                                           ` Lars Ingebrigtsen
2021-02-13 22:50                                       ` Dmitry Gutov
2021-02-13 23:14                                         ` Alan Third
2021-02-14  0:02                                           ` Dmitry Gutov
2021-02-14  2:06                                             ` Yuan Fu
2021-02-14  2:09                                               ` Yuan Fu
2021-02-14 12:19                                               ` Dmitry Gutov
2021-02-14  9:58                                             ` Alan Third
2021-02-13 15:08                                     ` Lars Ingebrigtsen
2021-02-13 15:59                                       ` Alan Third
2021-02-13 21:08                                         ` Lars Ingebrigtsen
2021-02-13 21:53                                           ` Alan Third
2021-02-13 21:57                                             ` Lars Ingebrigtsen
2021-02-13 22:13                                               ` Alan Third
2021-02-13 18:29                                       ` chad
2021-02-13 19:52                                         ` chad
2021-02-13 20:06                                       ` Yuan Fu
2021-02-13 21:11                                         ` Lars Ingebrigtsen
2021-02-13 23:20                                           ` Alan Third
2021-02-09 17:26         ` Grzegorz Kowzan
2021-02-05 20:29       ` Alan Third
2021-02-07 21:58     ` Alan Third

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).