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#64908: 29.1; svg parse failure Date: Sat, 5 Aug 2023 19:31:24 +0100 Message-ID: References: <6fa9c98e-e7ce-33de-c21d-bb36ab8687da@orange.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="JrMTmeQFchcuHU2K" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26238"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 64908@debbugs.gnu.org To: David Ponce Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 05 20:32:27 2023 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 1qSM4h-0006aL-3N for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Aug 2023 20:32:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSM4J-00071C-Qa; Sat, 05 Aug 2023 14:32:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSM4I-000713-GG for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2023 14:32:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSM4I-0003kp-7x for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2023 14:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qSM4H-0000no-Lv for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2023 14:32:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 05 Aug 2023 18:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64908 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: unreproducible Original-Received: via spool by 64908-submit@debbugs.gnu.org id=B64908.16912602973050 (code B ref 64908); Sat, 05 Aug 2023 18:32:01 +0000 Original-Received: (at 64908) by debbugs.gnu.org; 5 Aug 2023 18:31:37 +0000 Original-Received: from localhost ([127.0.0.1]:58215 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qSM3t-0000n7-7S for submit@debbugs.gnu.org; Sat, 05 Aug 2023 14:31:37 -0400 Original-Received: from dane.soverin.net ([185.233.34.21]:59579) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qSM3q-0000mt-9Y for 64908@debbugs.gnu.org; Sat, 05 Aug 2023 14:31:35 -0400 Original-Received: from smtp.soverin.net (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dane.soverin.net (Postfix) with ESMTPS id 4RJB4J2wvrz20; Sat, 5 Aug 2023 18:31:28 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4RJB4H6g94zBX; Sat, 5 Aug 2023 18:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1691260288; bh=yiPYikaHFr446k6/G52fqc98UpJlziGyUxTn/fOVy5Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lfvAqpvw1gQjQ91P3rbLkxHJUqp1bJXe2ajfLdAor/YEhTlWYfyMSxyzALDwiuXuo RE9frFFjYhVP4FGRIR6zg4B01HHTmaZDVGNqw6bYQZdCSrRsUItOmkGR+pcSkEjYl8 6oqtPiideRdQZLeG1wMcgBd5UKBdagl4+OsvV+GV+G+tpUOXzHY3B1R02OtqHpcMD8 YnUtSMSFZLH8y5hzhOVQ6680YyQ0EhMf4PiJxXs0/2DpHn0Nw+n4N4e7k89NQgGWfq z/cTxrX8rzT+xqVeAcqtpGJOjia/xMKs95scpe1A+GQyXoyzLdGI/bXDNFiSr0qJcd R42czL4ZQj0mw== Original-Received: from alan by faroe.holly.idiocy.org with local (Exim 4.96) (envelope-from ) id 1qSM3g-000TNl-15; Sat, 05 Aug 2023 19:31:24 +0100 X-Soverin-Authenticated: true Mail-Followup-To: Alan Third , David Ponce , Eli Zaretskii , 64908@debbugs.gnu.org Content-Disposition: inline In-Reply-To: X-CMAE-Score: 0 X-CMAE-Analysis: v=2.4 cv=PfY5xAtd c=1 sm=1 tr=0 ts=64ce9580 a=UttIx32zK-AA:10 a=rdJW-LJBCQMDpFmvgFUA:9 a=CjuIK1q_8ugA:10 a=hIj89exaAAAA:8 a=MwwV5o0xpdQVIZlGDDkA:9 a=lS9wXHQM5UdnNJ4u63Ry:22 X-Cloudmark-Reporter: H1BfMDDIseXVAGznanf59hmP2F4= 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:266810 Archived-At: --JrMTmeQFchcuHU2K Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Aug 05, 2023 at 08:00:17PM +0200, David Ponce wrote: > On 05/08/2023 19:39, Alan Third wrote: > > On Sat, Aug 05, 2023 at 07:37:01PM +0200, David Ponce wrote: > > > > > > I just tried patch V3, and the result is the same: > > > insert-image produces the same black square of 22x22 pixels. > > > > Can you try changing the initialisation of zero_rect to {0, 0, 10, > > 10}? > > > > I remember a lot of trial and error with this originally, and it looks > > like they may have changed how it works. > > It is better :-) > > Before call to rsvg_handle_get_geometry_for_layer: > > (gdb) print zero_rect > $1 = {x = 0, y = 0, width = 10, height = 10} > (gdb) print viewbox > $2 = {x = 6.9533474147268633e-310, y = 2.3106462124703418e-319, width = 5.8283471538673388e-315, height = 9.8813129168249309e-323} > (gdb) print out_logical_rect > $3 = {x = 6.9533558057749482e-310, y = 6.9533473517748961e-310, width = 1.4821969375237396e-323, height = 3.0586981611317814e-317} > > After call: > > (gdb) print $eax > $4 = 1 > (gdb) print zero_rect > $5 = {x = 0, y = 0, width = 10, height = 10} > (gdb) print viewbox > $6 = {x = 7, y = 3, width = 8.70703125, height = 16} > (gdb) print out_logical_rect > $7 = {x = 7, y = 3, width = 8.70703125, height = 16} > > Now I see the image, aligned at bottom right on the line (see the screenshot). OK. I really don't understand how this works, and I'm sure some older version of librsvg required a viewport of zero size, but I don't know which, so this is all a bit of a stab in the dark. Anyway, patch attached with a viewport that is hopefully big enough for all the SVGs we'll ever see. :) -- Alan Third --JrMTmeQFchcuHU2K Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0001-Fix-percentage-sizes-in-SVG-display-bug-64908.patch" >From b37126c0c72b6949783a3044b44896e0ebbd9606 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sat, 5 Aug 2023 10:39:31 +0100 Subject: [PATCH v4] Fix percentage sizes in SVG display (bug#64908) * src/image.c (svg_css_length_to_pixels): Make percent units always return zero and handle font size based units better. (svg_load_image): Don't rely on the width and height values from the SVG actually having any useful data, even if they're explicitly set. --- src/image.c | 82 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/src/image.c b/src/image.c index c9420b48f4a..bc42f3c55f9 100644 --- a/src/image.c +++ b/src/image.c @@ -11137,6 +11137,12 @@ svg_css_length_to_pixels (RsvgLength length, double dpi, int font_size) { double value = length.length; +#if ! LIBRSVG_CHECK_VERSION (2, 48, 0) + /* librsvg 2.48 lets us define the font size, but earlier versions + default to 12 pixels. */ + font_size = 12; +#endif + switch (length.unit) { case RSVG_UNIT_PX: @@ -11161,16 +11167,31 @@ svg_css_length_to_pixels (RsvgLength length, double dpi, int font_size) case RSVG_UNIT_IN: value *= dpi; break; -#if LIBRSVG_CHECK_VERSION (2, 48, 0) - /* We don't know exactly what font size is used on older librsvg - versions. */ case RSVG_UNIT_EM: value *= font_size; break; -#endif + case RSVG_UNIT_EX: + /* librsvg uses an ex height of half the em height, so we match + that here. */ + value = value * font_size / 2.0; + break; + case RSVG_UNIT_PERCENT: + /* Percent is a ratio of the containing "viewport". We don't + have a viewport, as such, as we try to draw the image to it's + 'natural' size rather than dictate the size as if we were + drawing icons on a toolbar or similar. This means that + percent values are useless to us and we are best off just + drawing the image according to whatever other sizes we can + derive. + + If we do set explicit width and height values in the image + spec, this will work out correctly as librsvg will still + honour the percentage sizes in its final rendering no matter + what size we make the image. */ + value = 0; + break; default: - /* Probably ex or %. We can't know what the pixel value is - without more information. */ + /* We should never reach this. */ value = 0; } @@ -11301,7 +11322,8 @@ svg_load_image (struct frame *f, struct image *img, char *contents, } else { - RsvgRectangle zero_rect, viewbox, out_logical_rect; + RsvgRectangle viewbox; + double explicit_width = 0, explicit_height = 0; /* Try the intrinsic dimensions first. */ gboolean has_width, has_height; @@ -11313,34 +11335,27 @@ svg_load_image (struct frame *f, struct image *img, char *contents, &has_height, &iheight, &has_viewbox, &viewbox); - if (has_width && has_height) - { - /* Success! We can use these values directly. */ - viewbox_width = svg_css_length_to_pixels (iwidth, dpi, + if (has_width) + explicit_width = svg_css_length_to_pixels (iwidth, dpi, + img->face_font_size); + if (has_height) + explicit_height = svg_css_length_to_pixels (iheight, dpi, img->face_font_size); - viewbox_height = svg_css_length_to_pixels (iheight, dpi, - img->face_font_size); - /* Here one dimension could be zero because in percent unit. - So calculate this dimension with the other. */ - if (! (0 < viewbox_width) && (iwidth.unit == RSVG_UNIT_PERCENT)) - viewbox_width = (viewbox_height * viewbox.width / viewbox.height) - * iwidth.length; - else if (! (0 < viewbox_height) && (iheight.unit == RSVG_UNIT_PERCENT)) - viewbox_height = (viewbox_width * viewbox.height / viewbox.width) - * iheight.length; + if (explicit_width > 0 && explicit_height > 0) + { + viewbox_width = explicit_width; + viewbox_height = explicit_height; } - else if (has_width && has_viewbox) + else if (explicit_width > 0 && has_viewbox) { - viewbox_width = svg_css_length_to_pixels (iwidth, dpi, - img->face_font_size); - viewbox_height = viewbox_width * viewbox.height / viewbox.width; + viewbox_width = explicit_width; + viewbox_height = explicit_width * viewbox.height / viewbox.width; } - else if (has_height && has_viewbox) + else if (explicit_height > 0 && has_viewbox) { - viewbox_height = svg_css_length_to_pixels (iheight, dpi, - img->face_font_size); - viewbox_width = viewbox_height * viewbox.width / viewbox.height; + viewbox_height = explicit_height; + viewbox_width = explicit_height * viewbox.width / viewbox.height; } else if (has_viewbox) { @@ -11354,8 +11369,15 @@ svg_load_image (struct frame *f, struct image *img, char *contents, { /* We haven't found a usable set of sizes, so try working out the visible area. */ + + /* FIXME: I'm not sure exactly how librsvg uses this + viewport input here, so I'm not sure what values I should + set. */ + RsvgRectangle max_viewport_rect = {0, 0, UINT_MAX, UINT_MAX}; + RsvgRectangle out_logical_rect; + rsvg_handle_get_geometry_for_layer (rsvg_handle, NULL, - &zero_rect, &viewbox, + &max_viewport_rect, &viewbox, &out_logical_rect, NULL); viewbox_width = viewbox.x + viewbox.width; viewbox_height = viewbox.y + viewbox.height; -- 2.40.1 --JrMTmeQFchcuHU2K--