Subject: bug#13164: [PATCH] View DjVu documents through doc-view-mode

From: Elias Pipping <[email-masked]>
Date: Thu, 10 Jan 2013 01:15:28 +0100

Stefan Monnier <[email-masked]> writes:

>> I sent a patch to this list last year that made it possible to use
>> mupdf's "mudraw" instead of ghostscript's "gs" to convert pdf documents
>> into png files within doc-view-mode.
>
> Thanks, I've just installed your mupdf patch with a few cosmetic
> changes, thank you.
> The djvu patch is still pending,

I see you've pushed the djvu patch as well. Thank you; also for the
modifications you've made.

I've attached three more tiny patches.

Best regards,

Elias Pipping

>From 887b136fa79c81422c3fddc858e446f26ac71ab7 Mon Sep 17 00:00:00 2001
From: Elias Pipping <[email-masked]>
Date: Thu, 10 Jan 2013 00:56:50 +0100
Subject: [PATCH 1/3] Enable doc-view for djvu files

---
 lisp/files.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/files.el b/lisp/files.el
index ca5a415..9fea670 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2357,7 +2357,7 @@ ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|7Z\\)\\'" . archive-mode)
      ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
      ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MSDOG
      ("\\.[eE]?[pP][sS]\\'" . ps-mode)
-     ("\\.\\(?:PDF\\|DVI\\|OD[FGPST]\\|DOCX?\\|XLSX?\\|PPTX?\\|pdf\\|dvi\\|od[fgpst]\\|docx?\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
+     ("\\.\\(?:PDF\\|DVI\\|DJVU\\|OD[FGPST]\\|DOCX?\\|XLSX?\\|PPTX?\\|pdf\\|djvu\\|dvi\\|od[fgpst]\\|docx?\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
      ("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
      ("\\.s\\(v\\|iv\\|ieve\\)\\'" . sieve-mode)
      ("BROWSE\\'" . ebrowse-tree-mode)
-- 
1.8.1

>From a8a298ab5b6a2c12e7cca16af81ba76fd54d1c9a Mon Sep 17 00:00:00 2001
From: Elias Pipping <[email-masked]>
Date: Thu, 10 Jan 2013 00:59:16 +0100
Subject: [PATCH 2/3] single-page-converter need not be passed

---
 lisp/doc-view.el | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 0658a11..5f2d70d 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -970,7 +970,7 @@ Call CALLBACK with no arguments when done."
 
 (declare-function clear-image-cache "image.c" (&optional filter))
 
-(defun doc-view-document->png (pdf png pages single-page-converter)
+(defun doc-view-document->png (pdf png pages)
   ;; FIXME: Fix docstring.
   "Convert a PDF file to PNG asynchronously.
 Start by converting PAGES, and then the rest."
@@ -981,7 +981,7 @@ Start by converting PAGES, and then the rest."
     ;; a single page anyway, and of the remaining 1%, few cases will have
     ;; consecutive pages, it's not worth the trouble.
     (let ((rest (cdr pages)))
-      (funcall single-page-converter
+      (funcall doc-view-single-page-converter-function
 	       pdf (format png (car pages)) (car pages)
        (lambda ()
          (if rest
@@ -1095,12 +1095,10 @@ Those files are saved in the directory given by the function
       (`pdf
        (let ((pages (doc-view-active-pages)))
          ;; Convert PDF to PNG images starting with the active pages.
-         (doc-view-document->png doc-view-buffer-file-name png-file pages
-				 'doc-view-pdf->png-1)))
+         (doc-view-document->png doc-view-buffer-file-name png-file pages)))
       (`djvu
        (let ((pages (doc-view-active-pages)))
-	 (doc-view-document->png doc-view-buffer-file-name png-file pages
-				 'doc-view-djvu->png-1)))
+	 (doc-view-document->png doc-view-buffer-file-name png-file pages)))
       (_
        ;; Convert to PNG images.
        (doc-view-pdf/ps->png doc-view-buffer-file-name png-file)))))
-- 
1.8.1

>From 31244c43ecf24945db95c823c020eccb68d3ef1d Mon Sep 17 00:00:00 2001
From: Elias Pipping <[email-masked]>
Date: Thu, 10 Jan 2013 01:12:45 +0100
Subject: [PATCH 3/3] Detect properly if PDFs can be handled

---
 lisp/doc-view.el | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 5f2d70d..8065b3e 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -708,11 +708,18 @@ OpenDocument format)."
 		       (executable-find doc-view-dvipdf-program))
 		  (and doc-view-dvipdfm-program
 		       (executable-find doc-view-dvipdfm-program)))))
-	((or (eq type 'postscript) (eq type 'ps) (eq type 'eps)
-	     (eq type 'pdf))
-	 ;; FIXME: allow mupdf here
+	((or (eq type 'postscript) (eq type 'ps) (eq type 'eps))
 	 (and doc-view-ghostscript-program
 	      (executable-find doc-view-ghostscript-program)))
+        ((eq type 'pdf)
+         (pcase doc-view-pdf->png-converter-function
+           (`doc-view-pdf->png-converter-ghostscript
+            (and doc-view-ghostscript-program
+                 (executable-find doc-view-ghostscript-program)))
+           (`doc-view-pdf->png-converter-mupdf
+            (and doc-view-pdfdraw-program
+                 (executable-find doc-view-pdfdraw-program)))
+           (_ t))) ;; Assume the user knows what he/she is doing
 	((eq type 'odf)
 	 (and doc-view-unoconv-program
 	      (executable-find doc-view-unoconv-program)
-- 
1.8.1