diff options
| author | Tassilo Horn | 2012-09-28 12:05:46 +0200 |
|---|---|---|
| committer | Tassilo Horn | 2012-09-28 12:05:46 +0200 |
| commit | c00ebc9835590d94d2b2f241ffcad872a2f2ffd3 (patch) | |
| tree | 97ae23d64a314d6583a0ece1353643097ce58c1d | |
| parent | 704d3f455f837fd8881c72f82788a282ff093c82 (diff) | |
| download | emacs-c00ebc9835590d94d2b2f241ffcad872a2f2ffd3.tar.gz emacs-c00ebc9835590d94d2b2f241ffcad872a2f2ffd3.zip | |
* doc-view.el (doc-view-current-cache-doc-pdf): New function.
(doc-view-doc->txt, doc-view-convert-current-doc): Use it.
(doc-view-get-bounding-box): Make bounding box slicing work for
ODF and DVI documents.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/doc-view.el | 27 |
2 files changed, 22 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e13925e9b0f..cc884e9b1b5 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2012-09-28 Tassilo Horn <tsdh@gnu.org> | ||
| 2 | |||
| 3 | * doc-view.el (doc-view-current-cache-doc-pdf): New function. | ||
| 4 | (doc-view-doc->txt, doc-view-convert-current-doc): Use it. | ||
| 5 | (doc-view-get-bounding-box): Make bounding box slicing work for | ||
| 6 | ODF and DVI documents. | ||
| 7 | |||
| 1 | 2012-09-28 Glenn Morris <rgm@gnu.org> | 8 | 2012-09-28 Glenn Morris <rgm@gnu.org> |
| 2 | 9 | ||
| 3 | * type-break.el (type-break-mode, type-break-interval) | 10 | * type-break.el (type-break-mode, type-break-interval) |
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 37f58331a5d..f8975a57b7b 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -904,6 +904,11 @@ Start by converting PAGES, and then the rest." | |||
| 904 | (list "-raw" pdf txt) | 904 | (list "-raw" pdf txt) |
| 905 | callback)) | 905 | callback)) |
| 906 | 906 | ||
| 907 | (defun doc-view-current-cache-doc-pdf () | ||
| 908 | "Return the name of the doc.pdf in the current cache dir. | ||
| 909 | This file exists only if the current document isn't a PDF or PS file already." | ||
| 910 | (expand-file-name "doc.pdf" (doc-view-current-cache-dir))) | ||
| 911 | |||
| 907 | (defun doc-view-doc->txt (txt callback) | 912 | (defun doc-view-doc->txt (txt callback) |
| 908 | "Convert the current document to text and call CALLBACK when done." | 913 | "Convert the current document to text and call CALLBACK when done." |
| 909 | (make-directory (doc-view-current-cache-dir) t) | 914 | (make-directory (doc-view-current-cache-dir) t) |
| @@ -914,22 +919,17 @@ Start by converting PAGES, and then the rest." | |||
| 914 | (`ps | 919 | (`ps |
| 915 | ;; Doc is a PS, so convert it to PDF (which will be converted to | 920 | ;; Doc is a PS, so convert it to PDF (which will be converted to |
| 916 | ;; TXT thereafter). | 921 | ;; TXT thereafter). |
| 917 | (let ((pdf (expand-file-name "doc.pdf" | 922 | (let ((pdf (doc-view-current-cache-doc-pdf))) |
| 918 | (doc-view-current-cache-dir)))) | ||
| 919 | (doc-view-ps->pdf doc-view-buffer-file-name pdf | 923 | (doc-view-ps->pdf doc-view-buffer-file-name pdf |
| 920 | (lambda () (doc-view-pdf->txt pdf txt callback))))) | 924 | (lambda () (doc-view-pdf->txt pdf txt callback))))) |
| 921 | (`dvi | 925 | (`dvi |
| 922 | ;; Doc is a DVI. This means that a doc.pdf already exists in its | 926 | ;; Doc is a DVI. This means that a doc.pdf already exists in its |
| 923 | ;; cache subdirectory. | 927 | ;; cache subdirectory. |
| 924 | (doc-view-pdf->txt (expand-file-name "doc.pdf" | 928 | (doc-view-pdf->txt (doc-view-current-cache-doc-pdf) txt callback)) |
| 925 | (doc-view-current-cache-dir)) | ||
| 926 | txt callback)) | ||
| 927 | (`odf | 929 | (`odf |
| 928 | ;; Doc is some ODF (or MS Office) doc. This means that a doc.pdf | 930 | ;; Doc is some ODF (or MS Office) doc. This means that a doc.pdf |
| 929 | ;; already exists in its cache subdirectory. | 931 | ;; already exists in its cache subdirectory. |
| 930 | (doc-view-pdf->txt (expand-file-name "doc.pdf" | 932 | (doc-view-pdf->txt (doc-view-current-cache-doc-pdf) txt callback)) |
| 931 | (doc-view-current-cache-dir)) | ||
| 932 | txt callback)) | ||
| 933 | (_ (error "DocView doesn't know what to do")))) | 933 | (_ (error "DocView doesn't know what to do")))) |
| 934 | 934 | ||
| 935 | (defun doc-view-ps->pdf (ps pdf callback) | 935 | (defun doc-view-ps->pdf (ps pdf callback) |
| @@ -969,13 +969,13 @@ Those files are saved in the directory given by the function | |||
| 969 | (`dvi | 969 | (`dvi |
| 970 | ;; DVI files have to be converted to PDF before Ghostscript can process | 970 | ;; DVI files have to be converted to PDF before Ghostscript can process |
| 971 | ;; it. | 971 | ;; it. |
| 972 | (let ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))) | 972 | (let ((pdf (doc-view-current-cache-doc-pdf))) |
| 973 | (doc-view-dvi->pdf doc-view-buffer-file-name pdf | 973 | (doc-view-dvi->pdf doc-view-buffer-file-name pdf |
| 974 | (lambda () (doc-view-pdf/ps->png pdf png-file))))) | 974 | (lambda () (doc-view-pdf/ps->png pdf png-file))))) |
| 975 | (`odf | 975 | (`odf |
| 976 | ;; ODF files have to be converted to PDF before Ghostscript can | 976 | ;; ODF files have to be converted to PDF before Ghostscript can |
| 977 | ;; process it. | 977 | ;; process it. |
| 978 | (let ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir)) | 978 | (let ((pdf (doc-view-current-cache-doc-pdf)) |
| 979 | (opdf (expand-file-name (concat (file-name-base doc-view-buffer-file-name) | 979 | (opdf (expand-file-name (concat (file-name-base doc-view-buffer-file-name) |
| 980 | ".pdf") | 980 | ".pdf") |
| 981 | doc-view-current-cache-dir)) | 981 | doc-view-current-cache-dir)) |
| @@ -1042,12 +1042,15 @@ dragging it to its bottom-right corner. See also | |||
| 1042 | (defun doc-view-get-bounding-box () | 1042 | (defun doc-view-get-bounding-box () |
| 1043 | "Get the BoundingBox information of the current page." | 1043 | "Get the BoundingBox information of the current page." |
| 1044 | (let* ((page (doc-view-current-page)) | 1044 | (let* ((page (doc-view-current-page)) |
| 1045 | (doc (let ((cache-doc (doc-view-current-cache-doc-pdf))) | ||
| 1046 | (if (file-exists-p cache-doc) | ||
| 1047 | cache-doc | ||
| 1048 | doc-view-buffer-file-name))) | ||
| 1045 | (o (shell-command-to-string | 1049 | (o (shell-command-to-string |
| 1046 | (concat doc-view-ghostscript-program | 1050 | (concat doc-view-ghostscript-program |
| 1047 | " -dSAFER -dBATCH -dNOPAUSE -q -sDEVICE=bbox " | 1051 | " -dSAFER -dBATCH -dNOPAUSE -q -sDEVICE=bbox " |
| 1048 | (format "-dFirstPage=%s -dLastPage=%s %s" | 1052 | (format "-dFirstPage=%s -dLastPage=%s %s" |
| 1049 | page page | 1053 | page page doc))))) |
| 1050 | doc-view-buffer-file-name))))) | ||
| 1051 | (save-match-data | 1054 | (save-match-data |
| 1052 | (when (string-match (concat "%%BoundingBox: " | 1055 | (when (string-match (concat "%%BoundingBox: " |
| 1053 | "\\([[:digit:]]+\\) \\([[:digit:]]+\\) " | 1056 | "\\([[:digit:]]+\\) \\([[:digit:]]+\\) " |