home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!apple!cambridge.apple.com!@explorer-en.dgp.toronto.edu:markt@dgp.toronto.edu
- From: markt@dgp.toronto.edu ("Mark A. Tapia")
- Newsgroups: comp.lang.lisp.mcl
- Subject: Re: view-font/set-view-font
- Message-ID: <92Dec22.100708est.144049@explorer-en.dgp.toronto.edu>
- Date: 22 Dec 92 15:06:57 GMT
- Sender: info-mcl-request@cambridge.apple.com
- Lines: 91
- Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
-
- Rich Lynch@ils.nwu.edu writes:
-
- I've been having trouble with fonts.
-
- I have some fancy windows that have 2 different fonts mixed.
-
- ...
-
- All that said, I am still at a loss to explain how :italic creeps in and
- stays there in the following code:
-
- ... code ommitted ...
- B: I really don't think it's good style [pun intended] to have code that
- goes:
- (set-view-font-codes view XXXX XXXX XXXX XXXX) when
- (set-view-font view '("Helvetica" 30 :bold)) is an option that should work.
- Any idiot can read and maintain the latter; the former is gibberish.
-
- If you want to ensure that the font is correct, then specify one
- font, one font size, a font style and one of the transfer modes
- and use the with-font-spec macro from Michael Engber in
- oodles-of-utils:brutal-utils:quickdraw.lisp. This will eliminate
- the gibberish of font codes.
-
- ;; Copyright 1992 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- (defmacro with-font-spec (font-spec &body body)
- (if (and (listp font-spec) (every #'constantp font-spec))
- (multiple-value-bind (ff ms) (font-codes font-spec)
- `(with-font-codes ,ff ,ms ,@body))
- (let ((ff (gensym))
- (ms (gensym)))
- `(multiple-value-bind (,ff ,ms) (font-codes ,font-spec)
- (with-font-codes ,ff ,ms ,@body)))))
-
- to change the font spec temporarily.
-
- Instead of
- (defmethod view-draw-contents :after ((view sample))
- (let ((font '("Helvetica" 18 :italic))
- (old-font (view-font view)))
- (set-view-font view font)
- (with-pstrs ((str (format nil "~A" font)))
- (#_MoveTo 4 50)
- (#_DrawString str))
- (set-view-font view old-font)))
-
-
- to recode the fragment to the following:
- (defmethod view-draw-contents :after ((view sample))
- (with-font-spec '("Helvetica" 18 :bold :italic)
- (with-pstrs ((str (format nil "~A" (view-font view))))
- (#_MoveTo 4 50)
- (#_DrawString str))))
-
-
- Here is your complete example recoded using the with-font-spec macro
- with font specs specified using the conventions above. The four lines
- are printed in order in the following font codes:
- Helvetica 18 :italic
- New York 18 :bold
- New York 18 :bold :italic :underline
- Helvetica 30 :bold
- all using the :SRCOR transfer mode
-
- (defclass sample (dialog)
- ()
- (:default-initargs
- :view-font '("Helvetica" 30 :bold)
- :view-size #@(600 400)))
-
- (defmethod view-draw-contents :after ((view sample))
- (with-font-spec '("Helvetica" 18 :italic)
- (with-pstrs ((str (format nil "~A" '("Helvetica" 18 :italic))))
- (#_MoveTo 4 50)
- (#_DrawString str)))
- (with-font-spec '("New York" 18 :bold)
- (with-pstrs ((str (format nil "~A" '("New York" 18 :bold))))
- (#_MoveTo 4 100)
- (#_DrawString str)))
- (with-font-spec '("New York" 18 :bold :italic :underline)
- (with-pstrs ((str (format nil "~A" '("New York" 18 :bold :italic :underline))))
- (#_MoveTo 4 150)
- (#_DrawString str)))
- (with-pstrs ((str (format nil "~A" (view-font view))))
- (#_MoveTo 4 200)
- (#_DrawString str)))
-
- (make-instance 'sample)
-