From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#45124: Subject: 27.1; Image rendered from svg is too small on a hdpi display Date: Wed, 9 Dec 2020 00:08:20 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="AYA8+7DtMiR9J7Ip" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24380"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 45124@debbugs.gnu.org To: Dov Grobgeld Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 09 01:09:21 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmn2n-0006Cq-07 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Dec 2020 01:09:21 +0100 Original-Received: from localhost ([::1]:53864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmn2l-0006j9-T9 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Dec 2020 19:09:19 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmn2U-0006hl-Ix for bug-gnu-emacs@gnu.org; Tue, 08 Dec 2020 19:09:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48701) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kmn2U-0003Nt-C0 for bug-gnu-emacs@gnu.org; Tue, 08 Dec 2020 19:09:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kmn2U-0005sV-6t for bug-gnu-emacs@gnu.org; Tue, 08 Dec 2020 19:09:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Dec 2020 00:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45124 X-GNU-PR-Package: emacs Original-Received: via spool by 45124-submit@debbugs.gnu.org id=B45124.160747251622564 (code B ref 45124); Wed, 09 Dec 2020 00:09:02 +0000 Original-Received: (at 45124) by debbugs.gnu.org; 9 Dec 2020 00:08:36 +0000 Original-Received: from localhost ([127.0.0.1]:60247 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kmn24-0005rr-18 for submit@debbugs.gnu.org; Tue, 08 Dec 2020 19:08:36 -0500 Original-Received: from outbound.soverin.net ([116.202.65.218]:39215) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kmn1z-0005rZ-6v for 45124@debbugs.gnu.org; Tue, 08 Dec 2020 19:08:34 -0500 Original-Received: from smtp.soverin.net (unknown [10.10.3.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 4287F601C4 for <45124@debbugs.gnu.org>; Wed, 9 Dec 2020 00:08:24 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [159.69.232.138]) by soverin.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1607472503; bh=vU+BC+ynsMUFGqoBW48fM9NFVdSFeIX5IqpTIqnRh5Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lnS51aLiqcqrmevoM4f3V0+nJYoEZ9476tY5PgJOcdatlE+LmpolJZ4p0qDx/D1tc xj0n7wlpM2y/KJeIWfba1pOdsOCawhiUpr08PqssFn7gmaeJ7j8dpj3y8lvxPEnFR4 MfX+BSguYB5bY8/hPIx4/TKvIkN8ht0J6LHinHzlJs6YMCCpRV3FSl+qy1I3iHWqAl gosb7QAbZqSvK2VOig8h2KBwKfJvoG4HdVjzEVU+mHziwZ9ndKGHleiJoIZBB1nLkq fws/2KB05Hq2fj02skqi1Dik95LNxRmbcUHHYsDf+idMVlUPethDAq7H1ArexyzA3y DFb4WOIXEhY9Q== Original-Received: by breton.holly.idiocy.org (Postfix, from userid 501) id 594ED2028690CB; Wed, 9 Dec 2020 00:08:21 +0000 (GMT) Mail-Followup-To: Alan Third , Dov Grobgeld , 45124@debbugs.gnu.org Content-Disposition: inline In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:195470 Archived-At: --AYA8+7DtMiR9J7Ip Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Tue, Dec 08, 2020 at 08:28:43PM +0200, Dov Grobgeld wrote: > When loading an svg file into emacs by find file, e.g. the attached file > inkscape-drawing.svg, it is not rendered by the active x11 resolution. The > svg file has a native size of about 173.mm, but when loaded into emacs, its > width becomes about 95mm. My monitor is a 4k 27" screen which has a dpi of > about 163. It thus appears that the svg file is rendered at 90 dpi, since > 90/167*173 ≈ 95. > > Note that xdpinfo properly returns: > > resolution: 162x161 dots per inch Something like the attached (patch against the master branch) might do the trick... This makes everything smaller on macOS, which isn't great because on my laptop everything is already too small. I'm not sure what we'd have to do to get SVGs rendering at roughly the right size. -- Alan Third --AYA8+7DtMiR9J7Ip Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Use-real-DPI-when-rendering-SVGs-bug-45124.patch" >From 5a9e26a16b46797d10dee5c725877177d750e536 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Wed, 9 Dec 2020 00:02:44 +0000 Subject: [PATCH] Use real DPI when rendering SVGs (bug#45124) * src/image.c (svg_css_length_to_pixels): Pass in a DPI value instead of using a hard coded value. (svg_load_image): Set the DPI on the rsvg_handle, and pass it to svg_css_length_to_pixels. --- src/image.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/image.c b/src/image.c index f16b9454a1..1523b4c5e3 100644 --- a/src/image.c +++ b/src/image.c @@ -9759,11 +9759,8 @@ svg_load (struct frame *f, struct image *img) #if LIBRSVG_CHECK_VERSION (2, 46, 0) static double -svg_css_length_to_pixels (RsvgLength length) +svg_css_length_to_pixels (RsvgLength length, double dpi) { - /* FIXME: 96 appears to be a pretty standard DPI but we should - probably use the real DPI if we can get it. */ - double dpi = 96; double value = length.length; switch (length.unit) @@ -9837,6 +9834,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents, rsvg_handle = rsvg_handle_new_from_stream_sync (input_stream, base_file, RSVG_HANDLE_FLAGS_NONE, NULL, &err); + rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, + FRAME_DISPLAY_INFO (f)->resy); + if (base_file) g_object_unref (base_file); g_object_unref (input_stream); @@ -9848,6 +9848,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents, rsvg_handle = rsvg_handle_new (); eassume (rsvg_handle); + rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, + FRAME_DISPLAY_INFO (f)->resy); + /* Set base_uri for properly handling referenced images (via 'href'). Can be explicitly specified using `:base_uri' image property. See rsvg bug 596114 - "image refs are relative to curdir, not .svg file" @@ -9872,6 +9875,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, /* Try the instrinsic dimensions first. */ gboolean has_width, has_height, has_viewbox; RsvgLength iwidth, iheight; + double dpi = FRAME_DISPLAY_INFO (f)->resx; rsvg_handle_get_intrinsic_dimensions (rsvg_handle, &has_width, &iwidth, @@ -9881,19 +9885,19 @@ svg_load_image (struct frame *f, struct image *img, char *contents, if (has_width && has_height) { /* Success! We can use these values directly. */ - viewbox_width = svg_css_length_to_pixels (iwidth); - viewbox_height = svg_css_length_to_pixels (iheight); + viewbox_width = svg_css_length_to_pixels (iwidth, dpi); + viewbox_height = svg_css_length_to_pixels (iheight, dpi); } else if (has_width && has_viewbox) { - viewbox_width = svg_css_length_to_pixels (iwidth); - viewbox_height = svg_css_length_to_pixels (iwidth) + viewbox_width = svg_css_length_to_pixels (iwidth, dpi); + viewbox_height = svg_css_length_to_pixels (iwidth, dpi) * viewbox.width / viewbox.height; } else if (has_height && has_viewbox) { - viewbox_height = svg_css_length_to_pixels (iheight); - viewbox_width = svg_css_length_to_pixels (iheight) + viewbox_height = svg_css_length_to_pixels (iheight, dpi); + viewbox_width = svg_css_length_to_pixels (iheight, dpi) * viewbox.height / viewbox.width; } else if (has_viewbox) @@ -10002,6 +10006,10 @@ svg_load_image (struct frame *f, struct image *img, char *contents, rsvg_handle = rsvg_handle_new_from_stream_sync (input_stream, base_file, RSVG_HANDLE_FLAGS_NONE, NULL, &err); + + rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, + FRAME_DISPLAY_INFO (f)->resy); + if (base_file) g_object_unref (base_file); g_object_unref (input_stream); @@ -10013,6 +10021,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents, rsvg_handle = rsvg_handle_new (); eassume (rsvg_handle); + rsvg_handle_set_dpi_x_y (rsvg_handle, FRAME_DISPLAY_INFO (f)->resx, + FRAME_DISPLAY_INFO (f)->resy); + /* Set base_uri for properly handling referenced images (via 'href'). Can be explicitly specified using `:base_uri' image property. See rsvg bug 596114 - "image refs are relative to curdir, not .svg file" -- 2.29.2 --AYA8+7DtMiR9J7Ip--