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 11:24:19 +0100 Message-ID: References: <83o7jnwfd3.fsf@gnu.org> <835y5vw1ay.fsf@gnu.org> <83350yvd5f.fsf@gnu.org> <83wmy9ssyd.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="s8yiTjsDIjmfJbU3" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2426"; mail-complaints-to="usenet@ciao.gmane.io" Cc: da_vid@orange.fr, 64908@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 05 12:25:23 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 1qSETK-0000QO-Ri for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Aug 2023 12:25:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSET9-0006AC-VA; Sat, 05 Aug 2023 06:25:12 -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 1qSET3-000692-5U for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2023 06:25:05 -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 1qSET0-0006zR-Qd for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2023 06:25:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qSET0-0001bw-FE for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2023 06:25:02 -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 10:25:02 +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.16912310686129 (code B ref 64908); Sat, 05 Aug 2023 10:25:02 +0000 Original-Received: (at 64908) by debbugs.gnu.org; 5 Aug 2023 10:24:28 +0000 Original-Received: from localhost ([127.0.0.1]:55738 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qSESR-0001an-Vp for submit@debbugs.gnu.org; Sat, 05 Aug 2023 06:24:28 -0400 Original-Received: from dane.soverin.net ([2a10:de80:1:4091:b9e9:2219:0:1]:35235) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qSESQ-0001aa-7j for 64908@debbugs.gnu.org; Sat, 05 Aug 2023 06:24:27 -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 4RHzGD6c0fzyQC; Sat, 5 Aug 2023 10:24:20 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4RHzGD2ZjmzJT; Sat, 5 Aug 2023 10:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1691231060; bh=sRjvqA/PHfpQXkGTCop9VVp07/j4Auru6O4ccoY/hzE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I2VX2YpKqWI4Rr5qP7DifM54MvDLemIxLpev53cuoJBdBNcTndqD5Me+vJLrOSOgC euW2vhCH+9XGVy0wuU90VgSZPdklXPjR/M44+wxTienGAhHiN3Mx7rzXhu/C4b1BiI USvIynrjZ/cM0GViK5QQgFih4ZouxWVYE3yrBB1BaBxugW22oVPhy11lIXosHSA0IM EUDd3MDT8Z8OJSwPWoqQv8Cik7uxUThh7jPlIZkr17TknxwmBOm4JFyRXQcRBCic8r dVgDIKTQFPQWaCgw6w7qMarHLzGYMn+VKrB6XZcaB6eL8HOSGVwOu/MYP+fcWmHCT6 mhQ81h/R65RJg== Original-Received: from alan by faroe.holly.idiocy.org with local (Exim 4.96) (envelope-from ) id 1qSESJ-000P9l-05; Sat, 05 Aug 2023 11:24:19 +0100 X-Soverin-Authenticated: true Mail-Followup-To: Alan Third , Eli Zaretskii , da_vid@orange.fr, 64908@debbugs.gnu.org Content-Disposition: inline In-Reply-To: <83wmy9ssyd.fsf@gnu.org> X-CMAE-Score: 0 X-CMAE-Analysis: v=2.4 cv=Mfmq+bzf c=1 sm=1 tr=0 ts=64ce2354 a=UttIx32zK-AA:10 a=hIj89exaAAAA:8 a=mDV3o1hIAAAA:8 a=wYmSQw2n_bR_1DciA3gA:9 a=CjuIK1q_8ugA:10 a=K_NZgCzpMwcbTuDISQcA:9 a=lS9wXHQM5UdnNJ4u63Ry:22 a=_FVE-zBwftR9WsbkzFJk:22 X-Cloudmark-Reporter: s5ciLm55FWviqoq+smPSwz0CTew= 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:266760 Archived-At: --s8yiTjsDIjmfJbU3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Aug 05, 2023 at 01:07:38PM +0300, Eli Zaretskii wrote: > > Date: Sat, 5 Aug 2023 10:58:26 +0100 > > From: Alan Third > > Cc: Eli Zaretskii , 64908@debbugs.gnu.org > > > > diff --git a/src/image.c b/src/image.c > > index c9420b48f4a..96e0f2a7225 100644 > > --- a/src/image.c > > +++ b/src/image.c > > @@ -11161,6 +11161,21 @@ svg_css_length_to_pixels (RsvgLength length, double dpi, int font_size) > > case RSVG_UNIT_IN: > > value *= dpi; > > 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 > > + own desired 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; > > I don't see RSVG_UNIT_PERCENT anywhere in the librsvg headers on my > system, so perhaps this was introduced by some later version, and > should be guarded by LIBRSVG_CHECK_VERSION? Hmm, I can't find any reference to when it was introduced, so it's probably easier just to remove it and put the comment in the default case. (Interestingly while searching for the version I discovered this code has been used, almost verbatim, in libvips. The main difference is they're defining "ex" as half of "em", so perhaps we should copy that change back over...) -- Alan Third --s8yiTjsDIjmfJbU3 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Fix-percentage-sizes-in-SVG-display-bug-64908.patch" >From 126ee4b2dffc183e48a47a562a05a142f420ea4d Mon Sep 17 00:00:00 2001 From: Alan Third Date: Sat, 5 Aug 2023 10:39:31 +0100 Subject: [PATCH v2] Fix percentage sizes in SVG display (bug#64908) * src/image.c (svg_css_length_to_pixels): Make percent units always return zero. (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 | 60 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/image.c b/src/image.c index c9420b48f4a..4e07ea8268d 100644 --- a/src/image.c +++ b/src/image.c @@ -11169,8 +11169,26 @@ svg_css_length_to_pixels (RsvgLength length, double dpi, int font_size) break; #endif default: - /* Probably ex or %. We can't know what the pixel value is - without more information. */ + /* If it's ex then we can't know what the pixel value is without + more information. + + FIXME: perhaps ex should be 1/2 of an em? I imagine we + should try to match what librsvg does. + + If it's percent then we don't want to do anything with it. + + 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 + own desired 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; } @@ -11302,6 +11320,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents, else { RsvgRectangle zero_rect, viewbox, out_logical_rect; + double explicit_width = 0, explicit_height = 0; /* Try the intrinsic dimensions first. */ gboolean has_width, has_height; @@ -11313,34 +11332,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) { -- 2.40.1 --s8yiTjsDIjmfJbU3--