home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / lisp / mcl / 1869 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  3.4 KB

  1. Path: sparky!uunet!olivea!apple!cambridge.apple.com!@explorer-en.dgp.toronto.edu:markt@dgp.toronto.edu
  2. From: markt@dgp.toronto.edu ("Mark A. Tapia")
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re:  view-font/set-view-font
  5. Message-ID: <92Dec22.100708est.144049@explorer-en.dgp.toronto.edu>
  6. Date: 22 Dec 92 15:06:57 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 91
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. Rich Lynch@ils.nwu.edu writes:
  12.  
  13.   I've been having trouble with fonts.
  14.  
  15.   I have some fancy windows that have 2 different fonts mixed.
  16.  
  17.   ...
  18.  
  19.   All that said, I am still at a loss to explain how :italic creeps in and
  20.   stays there in the following code:
  21.  
  22.   ... code ommitted ...
  23.   B:  I really don't think it's good style [pun intended] to have code that
  24.   goes:
  25.   (set-view-font-codes view XXXX XXXX XXXX XXXX) when
  26.   (set-view-font view '("Helvetica" 30 :bold)) is an option that should work.
  27.   Any idiot can read and maintain the latter; the former is gibberish.
  28.  
  29. If you want to ensure that the font is correct, then specify one
  30. font, one font size, a font style and one of the transfer modes
  31. and use the with-font-spec macro from Michael Engber  in 
  32. oodles-of-utils:brutal-utils:quickdraw.lisp.  This will eliminate
  33. the gibberish of font codes.
  34.  
  35. ;; Copyright  1992 Northwestern University Institute for the Learning Sciences
  36. ;; All Rights Reserved
  37. ;;
  38. ;; author: Michael S. Engber
  39. (defmacro with-font-spec (font-spec &body body)
  40.     (if (and (listp font-spec) (every #'constantp font-spec))
  41.       (multiple-value-bind (ff ms) (font-codes font-spec)
  42.         `(with-font-codes ,ff ,ms ,@body))
  43.       (let ((ff (gensym))
  44.             (ms (gensym)))
  45.         `(multiple-value-bind (,ff ,ms) (font-codes ,font-spec)
  46.            (with-font-codes ,ff ,ms ,@body)))))
  47.  
  48. to change the font spec temporarily.
  49.  
  50. Instead of
  51. (defmethod view-draw-contents :after ((view sample))
  52.   (let ((font '("Helvetica" 18  :italic))
  53.         (old-font (view-font view)))
  54.     (set-view-font view font)
  55.     (with-pstrs ((str (format nil "~A" font)))
  56.       (#_MoveTo 4 50)
  57.       (#_DrawString str))
  58.     (set-view-font view old-font)))
  59.  
  60.  
  61. to recode the fragment to the following:
  62. (defmethod view-draw-contents :after ((view sample))
  63.   (with-font-spec '("Helvetica" 18 :bold :italic)
  64.     (with-pstrs ((str (format nil "~A" (view-font view))))
  65.       (#_MoveTo 4 50)
  66.       (#_DrawString str))))
  67.  
  68.  
  69. Here is your complete example recoded using the with-font-spec macro
  70. with font specs specified using the conventions above. The four lines
  71. are printed in order in the following font codes:
  72.   Helvetica 18 :italic
  73.   New York 18 :bold
  74.   New York 18 :bold :italic :underline
  75.   Helvetica 30 :bold
  76. all using the :SRCOR transfer mode
  77.  
  78. (defclass sample (dialog)
  79.   ()
  80.   (:default-initargs
  81.     :view-font '("Helvetica" 30 :bold)
  82.     :view-size #@(600 400)))
  83.  
  84. (defmethod view-draw-contents :after ((view sample))
  85.   (with-font-spec '("Helvetica" 18 :italic)
  86.     (with-pstrs ((str (format nil "~A" '("Helvetica" 18 :italic))))
  87.       (#_MoveTo 4 50)
  88.       (#_DrawString str)))
  89.   (with-font-spec '("New York" 18 :bold)
  90.     (with-pstrs ((str (format nil "~A" '("New York" 18 :bold))))
  91.       (#_MoveTo 4 100)
  92.       (#_DrawString str)))
  93.   (with-font-spec '("New York" 18 :bold :italic :underline)
  94.     (with-pstrs ((str (format nil "~A" '("New York" 18 :bold :italic :underline))))
  95.       (#_MoveTo 4 150)
  96.       (#_DrawString str)))
  97.   (with-pstrs ((str (format nil "~A" (view-font view))))
  98.     (#_MoveTo 4 200)
  99.     (#_DrawString str)))
  100.  
  101. (make-instance 'sample)
  102.