[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: clip-region interaction with princ



On Wed, 29 Dec 1993, Pete Szolovits writes:
  I need to clip text to a region (really a rect) in a window, but it seems that
  the standard princ function applied to a window does not obey the clip region.
  E.g., if you evaluate the following code, the paint-rect is properly clipped,
  but the princ is not.
In the code, Pete includes the princ function to print a string.
The problem is that princ is not a QuickDraw function, while paintRect
is. Actually, paintRect calls the appropriate trap #_PaintRect.

Replace the call to princ by using the #_drawText trap call to call
on QuickDraw.
 
You'll just need to define the following macro:
;; The with-font-spec macro appears in Michael Engebers oodles-of-utils
   (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)))))
 
Now, replace the call to princ by the following code fragment,
ensuring that "view" refers the current view of interest:
 
(let ((the-text "A very long sample of text to be displayed in the window that
is too long"))
     (with-focused-view view
        (with-font-spec (slot-value menu 'menu-font)
          (with-returned-pstrs ((text-buff the-text))
            (#_MoveTo :long new-point)
            (#_DrawText :ptr text-buff :integer 1 :integer (length the-text))))


mark