unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation.
@ 2024-07-19 14:10 David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-07-27  7:19 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-07-19 14:10 UTC (permalink / raw)
  To: 72198

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

Hello,

While working on generating SVG images from text, I discovered that the
"svg-print" function adds extra space in front of the XML
representation of each child node. This is usually not a problem
because, by default, extra spaces are ignored. But this becomes a
problem, especially for text nodes, when the `xml:space' attribute is
set to "preserve" to indicate that spaces in texts are not
ignored. Because, in this case, the XML representation of the text node
no longer corresponds to the original definition, including unwanted
additional spaces.

Here are two examples which illustrate the problem to be evaluated in
the *scratch* buffer (emacs -Q):

(require 'svg)

;; Simple text with extra spaces between words.
(let* ((text "This buffer is   for text that   is not saved.")
        (w (* (length text) (default-font-width)))
        (h (* 1.5 (default-font-height)))
        (xmlspace "preserve") ;; Rendering preserves spaces.
        (svg (svg-create w h :xml:space xmlspace :stroke-width 0)))
   (svg-rectangle svg 0 0 w h :fill "blue")
   (svg-text svg text :y "1em" :fill "white")
   (insert-image (svg-image svg :scale 1)))

;; Aggregate texts separated by 1 space.
(let* ((texts '("This buffer is "
                 "for text that "
                 "is not saved."))
        (w (* (apply #'+ (mapcar #'length texts))
              (default-font-width)))
        (h (* 1.5 (default-font-height)))
        (xmlspace "preserve") ;; Rendering preserves spaces.
        (svg (svg-create w h :xml:space xmlspace :stroke-width 0)))
   (svg-rectangle svg 0 0 w h :fill "blue")
   (dom-append-child
    svg
    (apply #'dom-node
     'text
     '((y . "1em") (fill . "white"))
     texts))
   (insert-image (svg-image svg :scale 1)))


Since the extra space in front of the XML representation of each child
node is unnecessary according to the SVG 1.1 specification, the attached
V0 patch resolves this issue by removing the offending statement.

The attached V1 patch is a proposal to go a step further by improving
the documentation and using the DOM API to access parts of dom node.

Thanks.

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
  3.24.42, cairo version 1.18.0) of 2024-07-17
Repository revision: 3a790abd869ddadc343710deb0c4368227ba6611
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
System Description: Fedora Linux 40 (KDE Plasma)

Configured using:
  'configure --with-x-toolkit=gtk3 --with-cairo-xcb
  --with-native-compilation=no
  PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
   value of $LC_TIME: fr_FR.utf8
   value of $LANG: fr_FR.UTF-8
   locale-coding-system: utf-8-unix

[-- Attachment #2: svg-print-V1.patch --]
[-- Type: text/x-patch, Size: 1521 bytes --]

2024-07-19  David Ponce  <da_vid@orange.fr>

	* svg.el (svg-print): Remove useless extra space from the XML
	representation of SVG node.  Use the dom API to access parts of
	dom node. Improve doc string.

diff --git a/lisp/svg.el b/lisp/svg.el
index f2eb2ec66dd..1fed6c6b3b8 100644
--- a/lisp/svg.el
+++ b/lisp/svg.el
@@ -321,19 +321,19 @@ svg-possibly-update-image
 	(put-text-property marker (1+ marker) 'display (svg-image svg))))))
 
 (defun svg-print (dom)
-  "Convert DOM into a string containing the xml representation."
+  "Print the XML representation of DOM at point in current buffer."
   (if (stringp dom)
       (insert dom)
-    (insert (format "<%s" (car dom)))
-    (dolist (attr (nth 1 dom))
-      ;; Ignore attributes that start with a colon.
-      (unless (= (aref (format "%s" (car attr)) 0) ?:)
-        (insert (format " %s=\"%s\"" (car attr) (cdr attr)))))
-    (insert ">")
-    (dolist (elem (nthcdr 2 dom))
-      (insert " ")
-      (svg-print elem))
-    (insert (format "</%s>" (car dom)))))
+    (let ((tag (dom-tag dom)))
+      (insert (format "<%s" tag))
+      (dolist (attr (dom-attributes dom))
+        ;; Ignore attributes that start with a colon.
+        (unless (= (aref (format "%s" (car attr)) 0) ?:)
+          (insert (format " %s=\"%s\"" (car attr) (cdr attr)))))
+      (insert ">")
+      (dolist (elem (dom-children dom))
+        (svg-print elem))
+      (insert (format "</%s>" tag)))))
 
 (defun svg-remove (svg id)
   "Remove the element identified by ID from SVG."

[-- Attachment #3: svg-print-V0.patch --]
[-- Type: text/x-patch, Size: 490 bytes --]

2024-07-19  David Ponce  <da_vid@orange.fr>

	* svg.el (svg-print): Remove useless extra space from the XML
	representation of child node.

diff --git a/lisp/svg.el b/lisp/svg.el
index f2eb2ec66dd..f5c76145136 100644
--- a/lisp/svg.el
+++ b/lisp/svg.el
@@ -331,7 +331,6 @@ svg-print
         (insert (format " %s=\"%s\"" (car attr) (cdr attr)))))
     (insert ">")
     (dolist (elem (nthcdr 2 dom))
-      (insert " ")
       (svg-print elem))
     (insert (format "</%s>" (car dom)))))
 

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

* bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation.
  2024-07-19 14:10 bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-07-27  7:19 ` Eli Zaretskii
  2024-07-27 14:45   ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2024-07-27  7:19 UTC (permalink / raw)
  To: David Ponce; +Cc: 72198

> Date: Fri, 19 Jul 2024 16:10:00 +0200
> From:  David Ponce via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> Since the extra space in front of the XML representation of each child
> node is unnecessary according to the SVG 1.1 specification, the attached
> V0 patch resolves this issue by removing the offending statement.
> 
> The attached V1 patch is a proposal to go a step further by improving
> the documentation and using the DOM API to access parts of dom node.

Thanks.  Can you elaborate on what should we consider in order to
decide whether to install V0 or V1?





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

* bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation.
  2024-07-27  7:19 ` Eli Zaretskii
@ 2024-07-27 14:45   ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-08-03 15:08     ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-08-04  7:20     ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-07-27 14:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 72198

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

Le 27 juillet 2024 09:19:36 GMT+02:00, Eli Zaretskii <eliz@gnu.org> a écrit :
>> Date: Fri, 19 Jul 2024 16:10:00 +0200
>> From:  David Ponce via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>> 
>> Since the extra space in front of the XML representation of each child
>> node is unnecessary according to the SVG 1.1 specification, the attached
>> V0 patch resolves this issue by removing the offending statement.
>> 
>> The attached V1 patch is a proposal to go a step further by improving
>> the documentation and using the DOM API to access parts of dom node.
>
>Thanks.  Can you elaborate on what should we consider in order to
>decide whether to install V0 or V1?

The V0 patch is the only one required to fix the reported bug.

V1 is just a proposal to improve the doc string and avoid to access dom data using knowledge of the internal representation instead of the dom api.
V1 also include the fix in V0.

I hope it's clearer now.
Thanks 

[-- Attachment #2: Type: text/html, Size: 1505 bytes --]

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

* bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation.
  2024-07-27 14:45   ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-08-03 15:08     ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-08-03 15:46       ` Eli Zaretskii
  2024-08-04  7:20     ` Eli Zaretskii
  1 sibling, 1 reply; 7+ messages in thread
From: Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-08-03 15:08 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 72198

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

Le 27 juillet 2024 16:45:12 GMT+02:00, Da_vid <da_vid@orange.fr> a écrit :
>Le 27 juillet 2024 09:19:36 GMT+02:00, Eli Zaretskii <eliz@gnu.org> a écrit :
>>> Date: Fri, 19 Jul 2024 16:10:00 +0200
>>> From:  David Ponce via "Bug reports for GNU Emacs,
>>>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>>> 
>>> Since the extra space in front of the XML representation of each child
>>> node is unnecessary according to the SVG 1.1 specification, the attached
>>> V0 patch resolves this issue by removing the offending statement.
>>> 
>>> The attached V1 patch is a proposal to go a step further by improving
>>> the documentation and using the DOM API to access parts of dom node.
>>
>>Thanks.  Can you elaborate on what should we consider in order to
>>decide whether to install V0 or V1?
>
>The V0 patch is the only one required to fix the reported bug.
>
>V1 is just a proposal to improve the doc string and avoid to access dom data using knowledge of the internal representation instead of the dom api.
>V1 also include the fix in V0.
>
>I hope it's clearer now.
>Thanks
Hello Eli,
Do you need more details from me to progress in resolving this bug?
Thanks

[-- Attachment #2: Type: text/html, Size: 1921 bytes --]

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

* bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation.
  2024-08-03 15:08     ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-08-03 15:46       ` Eli Zaretskii
  2024-08-03 22:38         ` David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2024-08-03 15:46 UTC (permalink / raw)
  To: Da_vid; +Cc: 72198

> Date: Sat, 03 Aug 2024 17:08:25 +0200
> From: Da_vid <da_vid@orange.fr>
> CC: 72198@debbugs.gnu.org
> 
> Le 27 juillet 2024 16:45:12 GMT+02:00, Da_vid <da_vid@orange.fr> a écrit :
> 
>  Le 27 juillet 2024 09:19:36 GMT+02:00, Eli Zaretskii <eliz@gnu.org> a écrit :
> 
> Thanks.  Can you elaborate on what should we consider in order to
> decide whether to install V0 or V1?
> 
>  The V0 patch is the only one required to fix the reported bug.
> 
>  V1 is just a proposal to improve the doc string and avoid to access dom data using knowledge of the
>  internal representation instead of the dom api.
>  V1 also include the fix in V0.
> 
>  I hope it's clearer now.
>  Thanks 
> 
> Hello Eli,
> Do you need more details from me to progress in resolving this bug?

No, I need more hours in a day.





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

* bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation.
  2024-08-03 15:46       ` Eli Zaretskii
@ 2024-08-03 22:38         ` David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 7+ messages in thread
From: David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-08-03 22:38 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 72198

On 03/08/2024 5:46 PM, Eli Zaretskii wrote:
>> Date: Sat, 03 Aug 2024 17:08:25 +0200
>> From: Da_vid <da_vid@orange.fr>
>> CC: 72198@debbugs.gnu.org
>>
>> Le 27 juillet 2024 16:45:12 GMT+02:00, Da_vid <da_vid@orange.fr> a écrit :
>>
>>   Le 27 juillet 2024 09:19:36 GMT+02:00, Eli Zaretskii <eliz@gnu.org> a écrit :
>>
>> Thanks.  Can you elaborate on what should we consider in order to
>> decide whether to install V0 or V1?
>>
>>   The V0 patch is the only one required to fix the reported bug.
>>
>>   V1 is just a proposal to improve the doc string and avoid to access dom data using knowledge of the
>>   internal representation instead of the dom api.
>>   V1 also include the fix in V0.
>>
>>   I hope it's clearer now.
>>   Thanks
>>
>> Hello Eli,
>> Do you need more details from me to progress in resolving this bug?
> 
> No, I need more hours in a day.

I can understand that. There is no rush. I just wanted to make sure everything was clear.
Thank you very much for your time and great work!





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

* bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation.
  2024-07-27 14:45   ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-08-03 15:08     ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-08-04  7:20     ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2024-08-04  7:20 UTC (permalink / raw)
  To: Da_vid; +Cc: 72198-done

> Date: Sat, 27 Jul 2024 16:45:12 +0200
> From: Da_vid <da_vid@orange.fr>
> CC: 72198@debbugs.gnu.org
> 
> The V0 patch is the only one required to fix the reported bug.
> 
> V1 is just a proposal to improve the doc string and avoid to access dom data using knowledge of the internal
> representation instead of the dom api.
> V1 also include the fix in V0.

Thanks, I've now installed V0 on the emacs-30 release branch, and I'm
therefore closing the bug.





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

end of thread, other threads:[~2024-08-04  7:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-19 14:10 bug#72198: 31.0.50; `svg-print' add useless and possibly wrong space in XML representation David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-27  7:19 ` Eli Zaretskii
2024-07-27 14:45   ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-03 15:08     ` Da_vid via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-03 15:46       ` Eli Zaretskii
2024-08-03 22:38         ` David Ponce via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-04  7:20     ` Eli Zaretskii

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).