;;; rcd-paps.el --- RCD PAPS Emacs Bindings to PAPS printing utilities ;; Copyright (C) 2021-2022 by Jean Louis ;; Author: Jean Louis ;; Version: 0.1 ;; Package-Requires: (rcd-utilities) ;; Keywords: tools ;; URL: ;; This file is not part of GNU Emacs. ;; This program is free software: you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;;; Change Log: ;;; Code: (require 'rcd-utilities) (defcustom rcd-paps-orientation nil "Page orientation. By default it is portrait, if TRUE, it will be landscape" :group 'rcd-paps :type 'boolean) (defcustom rcd-paps-columns 1 "Number of columns output" :group 'rcd-paps :type 'integer) (defcustom rcd-paps-pdf-viewer "evince" "PDF Viewer" :group 'rcd-paps :type 'string) ;; (defcustom rcd-paps-paper "evince" ;; "PDF Viewer" ;; :group 'rcd-paps ;; :type 'string) (defcustom rcd-paps-output-directory (file-name-as-directory (getenv "HOME")) "Default PAPS output directory." :group 'rcd-paps :type 'string) ;; Application Options: ;; --landscape Landscape output. (Default: portrait) ;; --columns=NUM Number of columns output. (Default: 1) ;; --font=DESC Set font. (Default: Monospace 12) ;; -o, --output=DESC Output file. (Default: stdout) ;; -v, --version Current version. ;; --rtl Do right-to-left text layout. ;; --justify Justify the layout. ;; --hyphens Show hyphens when wrapping. ;; --wrap=WRAP Text wrapping mode [word, char, word-char]. (Default: word-char) ;; --show-wrap Show characters for wrapping. ;; --paper=PAPER Set paper size [legal, letter, a3, a4]. (Default: a4) ;; --gravity=GRAVITY Base glyph rotation [south, west, north, east, auto]. (Defaut: auto) ;; --gravity-hint=HINT Base glyph orientation [natural, strong, line]. (Default: natural) ;; --format=FORMAT Set output format [pdf, svg, ps]. (Default: ps) ;; --bottom-margin=NUM Set bottom margin in postscript point units (1/72 inch). (Default: 36) ;; --top-margin=NUM Set top margin. (Default: 36) ;; --right-margin=NUM Set right margin. (Default: 36) ;; --left-margin=NUM Set left margin. (Default: 36) ;; --gutter-width=NUM Set gutter width. (Default: 40) ;; --header Draw page header for each page. ;; --footer Draw page footer for each page. ;; --title=TITLE Title string for page header (Default: filename/stdin). ;; --header-left=HEADER_LEFT Left side of the header. Default is localized date. ;; --header-center=HEADER_CENTER Center side of the header. Default is localized date. ;; --header-right=HEADER_RIGHT Right side of the header. Default is localized date. ;; --markup Interpret input text as pango markup. ;; --encoding=ENCODING Assume encoding of input text. (Default: UTF-8) ;; --lpi=REAL Set the amount of lines per inch. ;; --cpi=REAL Set the amount of characters per inch. ;; --g-fatal-warnings=REAL Make all glib warnings fatal. (defun rcd-paps-process (text &optional format title &rest args) (let* ((format (or format "pdf")) (title (cond (title title) (current-prefix-arg (rcd-ask-get "Title: ")) (t (buffer-name)))) (length (length title)) (orientation (cond (rcd-paps-orientation "--landscape") (current-prefix-arg (when (y-or-n-p "Do you wish to use landscape? ") "--landscape")))) (max 45) (title (if (> length max) (substring title 0 max) title))) (apply 'rcd-command-output-from-input "paps" text "--format" format "--title" title "--header" (format "--columns=%d" (cond (current-prefix-arg (rcd-ask-number "Columns: ")) (t rcd-paps-columns))) (cond (orientation (append (list "--landscape") args)) (t args))))) (defun rcd-paps-text-to-pdf (text &optional file-name title) (let* ((output (rcd-paps-process text "pdf" title)) (file-name (or file-name (concat (file-name-as-directory (getenv "HOME")) (rcd-ask "File name without .pdf extension: ") ".pdf")))) (string-to-file-force output file-name))) (defun rcd-paps-buffer-to-pdf () (interactive) (let ((output (rcd-paps-process-buffer)) (file-name (rcd-temp-file-name nil "pdf"))) (prog1 (string-to-file-force output file-name) (rcd-message "PDF: %s" file-name)))) (defun rcd-paps-buffer-to-pdf-view () (interactive) (start-process rcd-paps-pdf-viewer rcd-paps-pdf-viewer rcd-paps-pdf-viewer (rcd-paps-buffer-to-pdf))) (defun rcd-paps-region-to-pdf () (interactive) (let ((output (rcd-paps-process-region)) (file-name (rcd-temp-file-name nil "pdf"))) (prog1 (string-to-file-force output file-name) (rcd-message "PDF: %s" file-name)))) (defun rcd-paps-region-to-pdf-view () (interactive) (start-process rcd-paps-pdf-viewer rcd-paps-pdf-viewer rcd-paps-pdf-viewer (rcd-paps-region-to-pdf))) (defun rcd-paps-process-region (&rest args) (let ((text (rcd-region-string))) (when text (apply 'rcd-paps-process text args)))) (defun rcd-paps-process-buffer (&rest args) (let ((text (buffer-substring-no-properties (point-min) (point-max)))) (apply 'rcd-paps-process text args))) (defun rcd-paps-print-buffer () (interactive) (let* ((file-name (concat (buffer-name) ".pdf")) (file (read-file-name "File name: " rcd-paps-output-directory nil nil file-name)) (output (rcd-paps-process-buffer))) (string-to-file-force output file) (message "Buffer printed to `%s'" file))) (defun rcd-export-pdf () (interactive) (let* ((type "pdf") (file (concat rcd-paps-output-directory (buffer-name) "." type)) (output (x-export-frames nil (intern type)))) (string-to-file-force output file) (message "Buffer printed to `%s'" file))) (defun rcd-paps-config-paper () (interactive) (let ((paper (rcd-choose '("legal" "letter" "a3" "a4") "Configure `paps' paper size: " nil "a4"))) (customize-set-value rcd-paps-paper paper))) (provide 'rcd-paps) ;;; rcd-paps.el ends here