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

Re: Setting the printer page orientation



On Mon. Dec 20, Denis Howlett writes:
> I'd like to be able to set the printer page orientation from vertical to
> horizontal programmatically.
 
> I've had a look in print-u.lisp at cambridge.apple.com, but it isn't
> something that is exported.

I thought I could help since I wrote print-u.lisp with some help
from Bill St. Clair and suggestions from others.

The code for changing the orientation appears in a comment.

> Since I don't want to do it for a particular fred file but for all printing
> on a particular application, saving the whole thing as a resource attached
> to a file doesn't quite work either.

If you want to change the default, then modify the default-prec method
to change the orientation field, using the commented code 
for the set-print-orientation method to change the orientation.
You'll need to use the code to change the printer orientation I've
included in this message

> I had a delve around the actual printer style structure and it appears that
> there is a particular field that has the orientation, but when you change
> this from the dialog, the height and width of the page  (as well as loads
> of other values) change too (i.e., it doesn't just use the orientation to
> interpret the two values as either width or height).

Here's a sample piece of code that returns the basic printer parameters
and changes from :landscape to :portrait.

It's a start. Try it, then I'll incorporate the changes in print-u.

Thanks

mark

(in-package ccl)
;;  assume that print-u.lisp has been loaded

;; routines for changing some of the page setup attributes
 
(defmethod set-print-reduction ((self t) reduction)
  (with-open-printer (print-record :view self)
    (if (integerp reduction)
      (if (macptrp print-record)
        (let ((min (rref print-record :tprint.izoommin))
              (max (rref print-record :tprint.izoommax)))
          (if (<= min reduction max)
            (rset print-record :tprint.prxinfo.ibandh reduction)
            (error "~s must be between ~d and ~d" reduction min max)))
        (error "~s is not a macintosh pointer" print-record))
      (error "~s must be an integer" reduction)
      )))
 
(defmethod set-print-orientation ((self t) orientation)
  ;; orientation is either :portrait or landscape
  ;; changes the page dimensions appropriately
  (with-open-printer (print-record :view self)
    (if (macptrp print-record)
      (let* ((old (rref print-record :tprint.prstl.wdev))
             (old-orientation (ldb (byte 1 1) old))
             (bit (case orientation
                    (:landscape 0)
                    (:portrait 1)))
             ;; experimentally determined that bit one controls orientation
             ;; is this always true?
             new)
        (when bit
          (setq new (dpb bit (byte 1 1) old)))
        (unless (= old-orientation bit)
          (reverse-page-dimensions print-record)
          (rset print-record :tprint.prstl.wdev new)))
      (error "~s is not a macintosh pointer" print-record)
      )))

(defun reverse-point (point)
  (make-point (point-v point) (point-h point)))

(defmacro reverse-a-page-field (print-record field)
  `(rset ,print-record ,field
         (reverse-point (href ,print-record ,field))))

(defun reverse-page-dimensions (print-record)
  (reverse-a-page-field print-record :tprint.prinfo.rpage.topLeft)
  (reverse-a-page-field print-record :tprint.prinfo.rpage.bottomRight)
  (reverse-a-page-field print-record :tprint.rpaper.topLeft)
  (reverse-a-page-field print-record :tprint.rpaper.bottomRight)
  (reverse-a-page-field print-record :tprint.prinfopt.rpage.topLeft)
  (reverse-a-page-field print-record :tprint.prinfopt.rpage.bottomRight))

(defmethod get-page-dimensions ((self t))
  (with-open-printer (print-record :view self)
    (values
     (ldb (byte 1 1) (rref print-record :tprint.prstl.wdev))
     (point-string (href print-record :tprint.prinfo.rpage.topLeft))
     (point-string (href print-record :tprint.prinfo.rpage.bottomRight))
     (point-string (href print-record :tprint.rpaper.topLeft))
     (point-string (href print-record :tprint.rpaper.bottomRight))
     (point-string (href print-record :tprint.prinfopt.rpage.topLeft))
     (point-string (href print-record :tprint.prinfopt.rpage.bottomRight))
     )))

;; try using the code by creating a window, loading the
;; print-u code, then change the page-setup attributes
;; call get-page-dimensions to display them.
;; Also try to set-print-orientation, changing it from
;; portrait -> landscappe -> landscape -> portrait -> portrait
;; and call the get-page-dimensions method each time.