home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / fontutils-0.6-base.tgz / fontutils-0.6-base.tar / fsf / fontutils / bzrto / bzredit.el < prev    next >
Lisp/Scheme  |  1992-08-04  |  6KB  |  199 lines

  1. ;; bzredit.el: a simple-minded editor for outline fonts.
  2. ;; 
  3. ;; Copyright (C) 1992 Free Software Foundation, Inc.
  4. ;; 
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation; either version 2, or (at your option)
  8. ;; any later version.
  9. ;; 
  10. ;; This program is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;; GNU General Public License for more details.
  14. ;; 
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program; if not, write to the Free Software
  17. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ;;
  19.  
  20. (defvar bzr-gs-proc nil "The Ghostscript process used for display.
  21. Initialized by bzredit.")
  22.  
  23. (defun bzredit (fontname)
  24.   "Edit the BZR font FONTNAME."
  25.   (interactive "FBZR font: ")
  26.   
  27.   ;; Edit the file in the buffer `FONTNAME', tossing the old contents.
  28.   (let ((bzrbufname fontname))
  29.     (if (not (get-buffer bzrbufname)) (get-buffer-create bzrbufname))
  30.     (set-buffer bzrbufname)
  31.     (erase-buffer)
  32.     
  33.     ;; Get the human- and Emacs-readable text.
  34.     (call-process "bzrto" nil (current-buffer) nil "-text" fontname)
  35.     
  36.     ;; Set up the editing features.
  37.     (bpl-mode)
  38.     
  39.     ;; Make this buffer visible.
  40.     (if (get-buffer-window bzrbufname)
  41.       (select-window (get-buffer-window bzrbufname))
  42.       (switch-to-buffer bzrbufname)
  43.     )
  44.   )
  45. )
  46.  
  47. (defvar bzr-gs-width 300
  48.   "Width of the X window started by Ghostscript in bzredit.")
  49. (defvar bzr-gs-height 300
  50.   "Width of the X window started by Ghostscript in bzredit.")
  51. (defvar bzr-gs-dpi 300
  52.   "Resolution in pixels per inch at which Ghostscript renders images.")
  53.  
  54. ;; If we wanted to edit more than one font simultaneously,
  55. ;; we'd have to change this, to start up a new GS process for each.
  56. (defun bzr-start-ghostscript ()
  57.   "Start a Ghostscript process to display the modified characters.  Set
  58. bzr-gs-proc to this process."
  59.  
  60.   (let ((process-connection-type nil))  ; Use a pipe.
  61.     (setq bzr-gs-proc 
  62.       (start-process "bzredit-gs" "*bzredit output: gs*"
  63.                      "gs" "-q" "-dNOPAUSE" 
  64.                      (concat "-g" bzr-gs-width "x" bzr-gs-height)
  65.                      "-")
  66.     )
  67.     ;; Have to have GS do the division, since Elisp doesn't have
  68.     ;; floating-point.
  69.     (bzr-gs-send (concat "["
  70.                          bzr-gs-dpi "72.27 div"
  71.                          " 0 0 "
  72.                          bzr-gs-dpi "72.27 div neg"
  73.                          " 0 "
  74.                          bzr-gs-height 
  75.                          "] setmatrix\n")
  76.     
  77.     ;; Establish a current point.
  78.     (bzr-gs-send "10 10 moveto\n")
  79.   )
  80. )
  81.  
  82. (defun bzr-gs-send (str)
  83.   "Send the string STR to bzr-gs-proc."
  84.   
  85.   (if (eq (process-status bzr-gs-proc) 'exit)
  86.     (bzr-start-ghostscript)
  87.   )
  88.   (process-send-string bzr-gs-proc str)
  89. )
  90.  
  91. (defun bpl-mode ()
  92.   "Major mode for editing outline fonts in BZR property list (BPL) format.
  93.  
  94. It has these extra commands:
  95. \\{bpl-mode-map}
  96.  
  97. Entering bpl mode calls the value of bpl-mode-hook."
  98.   (interactive)
  99.   
  100.   (setq major-mode 'bpl-mode)
  101.   (setq mode-name "BPL")
  102.   (use-local-map bpl-mode-map)
  103.  
  104.   (bzr-start-ghostscript)
  105.  
  106.   (run-hooks 'bpl-mode-hook)
  107. )
  108.  
  109. (defvar bpl-mode-map nil)
  110. (if bpl-mode-map
  111.   nil
  112.   (setq bpl-mode-map (make-sparse-keymap))
  113.   (define-key bpl-mode-map "\C-cc" 'bpl-show-char)
  114.   (define-key bpl-mode-map "\C-c\C-c" 'bpl-show-char)
  115.   (define-key bpl-mode-map "\C-ce" 'bpl-erasepage)
  116.   (define-key bpl-mode-map "\C-c\C-e" 'bpl-erasepage)
  117.   (define-key bpl-mode-map "\C-cq" 'bpl-quit)
  118.   (define-key bpl-mode-map "\C-c\C-q" 'bpl-quit)
  119. )
  120.  
  121. (defun bpl-show-char ()
  122.   "Pass the current character to Ghostscript for display."
  123.   (interactive)
  124.   
  125.   ;; Send Ghostscript the commands for this character.
  126.   (eval-defun nil)
  127. )
  128.  
  129. (defun bpl-quit ()
  130.   "Kill the Ghostscript process and call bury-buffer."
  131.   (interactive)
  132.   
  133.   ;; Stop Ghostscript.
  134.   (process-send-eof bzr-gs-proc)
  135.   
  136.   ;; Should convert back to BZR?
  137. )
  138.  
  139. (defun bpl-erasepage ()
  140.   "Erase the Ghostscript window."
  141.   (interactive)
  142.   
  143.   (bzr-gs-send "erasepage showpage\n")
  144. )
  145.  
  146. ;;; If we had packages, we could make each of these functions local.  But
  147. ;;; I don't know how to do that as things stand.
  148.  
  149. ;;; When we do something about hints we will have to construct a font
  150. ;;; and show characters from it.
  151.  
  152. ;; This must be a macro so we do not evaluate CHARDEF first.
  153. (defmacro char (charcode &rest chardef)
  154.   "Ignore the CHARCODE argument.  Evaluate all additional arguments (the
  155.   CHARDEF)."
  156.   
  157.   (mapcar 'eval chardef)
  158.   (bzr-gs-send "fill\n")
  159.  
  160.   ;; Be sure it is displayed.
  161.   (bzr-gs-send "copypage\n")
  162. )
  163.  
  164. (defmacro comment (&rest args)
  165.   "Ignore all arguments."
  166. )
  167.  
  168. ;; Nothing to do for the width or bounding box.
  169. (defun width (n)
  170.   "The set width is realstr N."
  171. )
  172.  
  173. (defun bb (llx lly urx ury)
  174.   "The bounding box is a four-element vector of realstrs: LLX LLY URX URY."
  175. )
  176.  
  177. ;; This must be a macro so we do not evaluate CMDS first.
  178. (defmacro outline (sx sy &rest cmds)
  179.   "A single outline is the starting point (SX,SY) plus an arbitrary
  180. number of additional commands."
  181.  
  182.   (bzr-gs-send (format "%s %s moveto\n" sx sy))
  183.   (mapcar 'eval cmds)
  184.   (bzr-gs-send "closepath\n")
  185. )
  186.  
  187. (defun line (px py)
  188.   "Draw a line from the current point to (PX,PY)."
  189.  
  190.   (bzr-gs-send (format "%s %s lineto\n" px py))
  191. )
  192.  
  193. (defun spline (c1x c1y c2x c2y ex ey)
  194.   "Draw a spline from the current point with controls (C1X,C1Y) and (C2X,C2Y)
  195. to (EX,EY)."
  196.   
  197.   (bzr-gs-send (format "%s %s %s %s %s %s curveto\n" c1x c1y c2x c2y ex ey))
  198. )
  199.