Commit | Line | Data |
---|---|---|
504737d5 | 1 | ;;; handwrite.el --- turns your emacs buffer into a handwritten document -*- coding: iso-latin-1; -*- |
1a44ec7a | 2 | |
43f36b80 | 3 | ;; (C) Copyright 1996 Free Software Foundation, Inc. |
1a44ec7a | 4 | |
9781053a | 5 | ;; Author: Danny Roozendaal (was: <danny@tvs.kun.nl>) |
43f36b80 | 6 | ;; Created: October 21 1996 |
0465b759 | 7 | ;; Keywords: wp, print, postscript, cursive writing |
1a44ec7a | 8 | |
43f36b80 | 9 | ;; This file is part of GNU Emacs. |
1a44ec7a | 10 | |
43f36b80 RS |
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation; either version 2, or (at your option) | |
14 | ;; any later version. | |
1a44ec7a | 15 | |
43f36b80 RS |
16 | ;; GNU Emacs is distributed in the hope that it will be useful, |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
1a44ec7a | 20 | |
43f36b80 | 21 | ;; You should have received a copy of the GNU General Public License |
1a44ec7a RS |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
25 | ||
43f36b80 RS |
26 | ;;; Commentary: |
27 | ;; | |
28 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
29 | ;; The function handwrite creates PostScript output containing a | |
30 | ;; handwritten version of the current buffer.. | |
31 | ;; Other functions that may be useful are | |
32 | ;; | |
33 | ;; handwrite-10pt: sets the font size to 10 and finds corresponding | |
34 | ;; values for the line spacing and the number of lines | |
35 | ;; on a page. | |
36 | ;; handwrite-11pt: which is similar | |
37 | ;; handwrite-12pt: which is also similar | |
38 | ;; handwrite-13pt: which is similar, too | |
39 | ;; | |
40 | ;; handwrite-set-pagenumber: set and unset page numbering | |
41 | ;; | |
42 | ;; | |
43 | ;; If you are not satisfied with the type page there are a number of | |
44 | ;; variables you may want to set. | |
45 | ;; | |
46 | ;; | |
47 | ;; Installation | |
48 | ;; | |
49 | ;; type at your prompt "emacs -l handwrite.el" or put this file on your | |
50 | ;; Emacs-Lisp load path, add the following into your ~/.emacs startup file | |
51 | ;; | |
52 | ;; (require 'handwrite) | |
53 | ;; | |
54 | ;; "M-x handwrite" or "Write by hand" in the edit menu should work now. | |
55 | ;; | |
56 | ;; | |
57 | ;; I tried to make it `iso_8859_1'-friendly, but there are some exotic | |
58 | ;; characters missing. | |
59 | ;; | |
60 | ;; | |
61 | ;; Known bugs: -Page feeds do not do their work, but are ignored instead. | |
62 | ;; -Tabs are not always properly displayed. | |
63 | ;; -Handwrite may create corrupt PostScript if it encounters | |
64 | ;; unknown characters. | |
65 | ;; | |
66 | ;; Thanks to anyone who emailed me suggestions! | |
67 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
68 | ||
69 | ||
70 | ;;; Code: | |
71 | ||
72 | ||
73 | ;; Variables | |
74 | ||
323f7c49 SE |
75 | (defgroup handwrite nil |
76 | "Turns your emacs buffer into a handwritten document." | |
77 | :prefix "handwrite-" | |
78 | :group 'games) | |
79 | ||
43f36b80 | 80 | (defvar handwrite-psindex 0 |
a2b80428 | 81 | "The index of the PostScript buffer.") |
43f36b80 RS |
82 | (defvar menu-bar-handwrite-map (make-sparse-keymap "Handwrite functions.")) |
83 | (fset 'menu-bar-handwrite-map (symbol-value 'menu-bar-handwrite-map)) | |
84 | ||
85 | ||
86 | ;; User definable variables | |
87 | ||
323f7c49 SE |
88 | (defcustom handwrite-numlines 60 |
89 | "*The number of lines on a page of the PostScript output from `handwrite'." | |
90 | :type 'integer | |
91 | :group 'handwrite) | |
92 | (defcustom handwrite-fontsize 11 | |
93 | "*The size of the font for the PostScript output from `handwrite'." | |
94 | :type 'integer | |
95 | :group 'handwrite) | |
96 | (defcustom handwrite-linespace 12 | |
97 | "*The spacing for the PostScript output from `handwrite'." | |
98 | :type 'integer | |
99 | :group 'handwrite) | |
100 | (defcustom handwrite-xstart 30 | |
101 | "*X-axis translation in the PostScript output from `handwrite'." | |
102 | :type 'integer | |
103 | :group 'handwrite) | |
104 | (defcustom handwrite-ystart 810 | |
105 | "*Y-axis translation in the PostScript output from `handwrite'." | |
106 | :type 'integer | |
107 | :group 'handwrite) | |
108 | (defcustom handwrite-pagenumbering nil | |
109 | "*If non-nil, number each page of the PostScript output from `handwrite'." | |
110 | :type 'boolean | |
111 | :group 'handwrite) | |
112 | (defcustom handwrite-10pt-numlines 65 | |
113 | "*The number of lines on a page for the function `handwrite-10pt'." | |
114 | :type 'integer | |
115 | :group 'handwrite) | |
116 | (defcustom handwrite-11pt-numlines 60 | |
117 | "*The number of lines on a page for the function `handwrite-11pt'." | |
118 | :type 'integer | |
119 | :group 'handwrite) | |
120 | (defcustom handwrite-12pt-numlines 55 | |
121 | "*The number of lines on a page for the function `handwrite-12pt'." | |
122 | :type 'integer | |
123 | :group 'handwrite) | |
124 | (defcustom handwrite-13pt-numlines 50 | |
125 | "*The number of lines on a page for the function `handwrite-13pt'." | |
126 | :type 'integer | |
127 | :group 'handwrite) | |
43f36b80 RS |
128 | |
129 | ;; Interactive functions | |
130 | ||
a2b80428 RS |
131 | ;;;###autoload |
132 | (defun handwrite () | |
133 | "Turns the buffer into a \"handwritten\" document. | |
134 | The functions `handwrite-10pt', `handwrite-11pt', `handwrite-12pt' | |
135 | and `handwrite-13pt' set up for various sizes of output. | |
136 | ||
43f36b80 RS |
137 | Variables: handwrite-linespace (default 12) |
138 | handwrite-fontsize (default 11) | |
139 | handwrite-numlines (default 60) | |
140 | handwrite-pagenumbering (default nil)" | |
141 | (interactive) | |
142 | (let | |
143 | ((pmin) ; thanks, Havard | |
144 | (lastp) | |
145 | (cur-buf (current-buffer)) | |
a1506d29 | 146 | (tpoint (point)) |
43f36b80 RS |
147 | (ps-ypos 63) |
148 | (lcount 0) | |
149 | (ipage 1) | |
150 | (nlan next-line-add-newlines) ;remember the old value | |
151 | (buf-name (buffer-name) ) | |
152 | (textp) | |
153 | (ps-buf-name) ;name of the PostScript buffer | |
154 | ) | |
155 | (goto-char (point-min)) ;start at beginning | |
156 | (setq handwrite-psindex (1+ handwrite-psindex)) | |
157 | (setq ps-buf-name | |
158 | (format "*handwritten%d.ps*" handwrite-psindex)) | |
159 | (setq next-line-add-newlines t) | |
160 | (switch-to-buffer ps-buf-name) | |
161 | (handwrite-insert-header buf-name) | |
6e44da43 | 162 | (insert "\n(\\nCreated by GNU Emacs' handwrite version " |
83410c23 | 163 | emacs-version "\\n\\n)=print flush\n") |
43f36b80 RS |
164 | (handwrite-insert-preamble) |
165 | (handwrite-insert-info) | |
166 | (handwrite-insert-font) | |
167 | (setq textp (point)) | |
168 | (insert "%%Page: 1 1\n") | |
169 | (insert "Hwjst\n") | |
170 | (insert "/Hwsave save def\n") | |
171 | (if handwrite-pagenumbering (insert "20 30 m\nxym(page 1)a\n")) | |
172 | (insert "44 63 m\n") | |
173 | (insert "xym( )a") | |
174 | (backward-char 3) | |
175 | (switch-to-buffer cur-buf) | |
176 | (goto-char (point-min)) ;start at beginning | |
177 | (save-excursion | |
a1506d29 | 178 | ;;as long as we see a newline the document is not ended. |
43f36b80 RS |
179 | (while (re-search-forward "\n" nil t) |
180 | (previous-line 1) | |
181 | (beginning-of-line) | |
182 | (setq pmin (point)) | |
183 | (search-forward "\n" nil t) | |
184 | (backward-char 1) | |
185 | (copy-region-as-kill (point) pmin) | |
186 | (forward-char 1) | |
187 | (switch-to-buffer ps-buf-name) | |
188 | (yank) | |
189 | (message "write write write...") | |
190 | (search-forward ")a" nil t) | |
191 | (backward-char 2) | |
192 | (setq lastp (point)) | |
193 | (beginning-of-line) | |
194 | (search-forward "(" nil t) | |
195 | (while (re-search-forward "[()\\]" lastp t) | |
196 | (save-excursion | |
197 | (setq lastp (+ lastp 1)) | |
198 | (forward-char -1) | |
199 | (insert "\\"))) | |
200 | (setq ps-ypos (+ ps-ypos handwrite-linespace)) | |
201 | (end-of-line) | |
202 | (insert "\n") | |
203 | (setq lcount (+ lcount 1)) | |
204 | (cond ( (eq lcount handwrite-numlines) | |
205 | (setq ipage (+ ipage 1)) | |
206 | (insert "0 0 m\n") | |
207 | (insert "showpage exec Hwsave restore\n") | |
208 | (insert "%%Page: " (number-to-string ipage) " " | |
209 | (number-to-string ipage) "\n") | |
210 | (insert "Hwjst\n") | |
211 | (insert "/Hwsave save def\n") | |
212 | (if handwrite-pagenumbering | |
213 | (insert "20 30 m\nxym(page " | |
214 | (number-to-string ipage) ")a\n")) | |
215 | (setq ps-ypos 63) | |
216 | (setq lcount 0) | |
217 | )) | |
218 | (insert "44 "(number-to-string ps-ypos) " m\n") | |
219 | (insert "xym( )a") | |
220 | (backward-char 3) | |
221 | (switch-to-buffer cur-buf) | |
222 | )) | |
223 | (switch-to-buffer ps-buf-name) | |
224 | (next-line 1) | |
225 | (insert "showpage exec Hwsave restore\n\n") | |
226 | (insert "%%Pages " (number-to-string ipage) " 0\n") | |
227 | (insert "%%EOF\n") | |
228 | (goto-char textp) ;start where the inserted text begins | |
229 |