Subject: Re: bug#73846: [PATCH] Make djvused emit UTF-8 encoded text

From: Visuwesh <[email-masked]>
Date: Thu, 17 Oct 2024 14:01:56 +0530

[வியாழன் அக்டோபர் 17, 2024] Eli Zaretskii wrote:

>> Cc: "Tassilo Horn" <[email-masked]>
>> From: Visuwesh <[email-masked]>
>> Date: Thu, 17 Oct 2024 09:42:30 +0530
>> 
>> This is a small patch to make djvused emit UTF-8 encoded text.  In the
>> djvu test file that I sent you, outline in the appendix have non-ASCII
>> characters which are written as octal escapes.  Rather than unescaping
>> them on Emacs side, we can request djvused to use UTF-8 directly which
>> this patch does.  The attached patch does just that.
>
> If you force djvused to emit UTF-8 encoded text, you need to bind
> coding-system-for-read to 'utf-8, to make sure Emacs decodes that
> correctly.  I'm guessing your locale uses UTF-8 by default, which is
> why it worked for you.

My locale is a UTF-8 one indeed.  I've now let bound
coding-system-for-read around everything inside with-temp-buffer.

> Please also add a comment there explaining what the -u switch does and
> why we use it there.

Done in attached patch, I hope it is clear.

> Thanks.

>From a39e50a504c9c24f51c7c646f3cfffcec2f34b85 Mon Sep 17 00:00:00 2001
From: Visuwesh <[email-masked]>
Date: Thu, 17 Oct 2024 09:40:34 +0530
Subject: [PATCH] Make djvused emit UTF-8 encoded text

* lisp/doc-view.el (doc-view--djvu-outline): Pass -u to djvused
to make it emit UTF-8 encoded text rather than using octal
escapes for non-ASCII string.  (bug#73846)
---
 lisp/doc-view.el | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index bbfbbdec925..4d7d36c8a16 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -2026,13 +2026,16 @@ doc-view--djvu-outline
 For the format, see `doc-view--pdf-outline'."
   (unless file-name (setq file-name (buffer-file-name)))
   (with-temp-buffer
-    (call-process doc-view-djvused-program nil (current-buffer) nil
-                  "-e" "print-outline" file-name)
-    (goto-char (point-min))
-    (when (eobp)
-      (setq doc-view--outline 'unavailable)
-      (imenu-unavailable-error "Unable to create imenu index using `djvused'"))
-    (nreverse (doc-view--parse-djvu-outline (read (current-buffer))))))
+    (let ((coding-system-for-read 'utf-8))
+      ;; Pass "-u" to make `djvused' emit UTF-8 encoded text to avoid
+      ;; unescaping octal escapes for non-ASCII text.
+      (call-process doc-view-djvused-program nil (current-buffer) nil
+                    "-u" "-e" "print-outline" file-name)
+      (goto-char (point-min))
+      (when (eobp)
+        (setq doc-view--outline 'unavailable)
+        (imenu-unavailable-error "Unable to create imenu index using `djvused'"))
+      (nreverse (doc-view--parse-djvu-outline (read (current-buffer)))))))
 
 (defun doc-view--parse-djvu-outline (bookmark &optional level)
   "Return a list describing the djvu outline from BOOKMARK.
-- 
2.45.2