/[defdoc]/DefDoc/src/layout/output-destinations.lisp
ViewVC logotype

Contents of /DefDoc/src/layout/output-destinations.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sun Dec 7 23:27:07 2003 UTC (10 years, 4 months ago) by rjain
Branch: MAIN, defdoc
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
initial import

1 (in-package :defdoc.layout)
2
3 (defclass output-destination ()
4 ((output-filename :type string
5 :initform ""
6 :initarg output-filename
7 :accessor output-filename
8 :documentation "The filename to send the output to (or possibly some
9 identifier, like a URI, if it is not actually going to a file).")
10 (open-file-args :initform nil
11 :initarg open-file-args
12 :accessor open-file-args
13 :documentation "Any additional arguments to pass when opening the
14 output file or stream.")
15 (output-stream :type (or null stream (function (output-destination) stream))
16 :initform nil
17 :initarg output-stream
18 :accessor output-stream
19 :documentation "If this is non-nil, it is a stream or function to create
20 a stream, given the output-destination object, to which the output for the layout goes,
21 and the output-filename is simply a token to identify it.")
22 (auxiliary-outputs :type list
23 :initform ()
24 :initarg auxiliary-outputs
25 :accessor auxiliary-outputs))
26 (:documentation "A destination for output of the layout engine."))
27
28 ;;;
29 ;;; Mixins to give specific layout methods to target formats
30 ;;;
31
32 (defclass fixed-layout ()
33 ((page-width :type length
34 :initarg page-width
35 :accessor page-width)
36 (page-height :type length
37 :initarg page-height
38 :accessor page-height))
39 (:documentation "Formats which have fixed layout parameters. This means that the exact
40 visual layout must be computed to use this format and the target medium is a set of
41 fixed-sized regions. Usually these are physical media."))
42
43 (defclass fixed-width-layout ()
44 ((page-width :type length
45 :initarg page-width
46 :accessor page-width)
47 (page-height :type spring
48 :initarg page-height
49 :accessor page-height))
50 (:documentation "Formats which have a fixed width but flexible length. Usually these are
51 virtual media without any intrinsic layout capabilities."))
52
53 (defclass fixed-height-layout ()
54 ((page-height :type length
55 :initarg page-height
56 :accessor page-height)
57 (page-width :type spring
58 :initarg page-width
59 :accessor page-width))
60 (:documentation "Formats which have a fixed length but flexible width. Usually these are
61 virtual media without any intrinsic layout capabilities. Added for completeness."))
62
63 (defclass flexible-layout ()
64 ((page-size :initform (make-spring 0 words + 1 inf)
65 :type spring
66 :initarg page-size
67 :accessor page-size))
68 (:documentation "Formats which have flexible layout parameters. The target medium's
69 regions will grow or shrink (and reflow) in all dimensions in order to accomodate the
70 layout choices made. Usually these are virtual media with some basic intrinsic layout
71 capabilities."))
72
73 (defclass no-layout ()
74 ()
75 (:documentation "Formats which need no layout in order to be used. Usually some other
76 application does the actual layout."))
77
78 ;;;
79 ;;; Physical output destinations (files, streams, etc)
80 ;;;
81
82 (defclass output-pages-are-files ()
83 ((output-filename :documentation "The filename prefix for the files of the output.")
84 (output-file-suffix :type string
85 :initform ""
86 :initarg output-file-suffix
87 :accessor output-file-suffix
88 :documentation "The filename suffix for the files of the output.")
89 (file-number-counter :type unsigned-byte
90 :accessor file-number-counter
91 :initform 0)
92 (file-number-base :type unsigned-byte
93 :initarg file-number-base
94 :accessor file-number-base
95 :initform 10))
96 (:documentation "Formats whose pages exist in separate files."))
97
98 (defgeneric get-next-filename (output)
99 (:documentation "Gets the filename for the next (or only) page of an
100 output-destination."))
101
102 (defmethod get-next-filename ((output output-destination))
103 (output-filename output))
104
105 (defmethod get-next-filename :around ((output output-pages-are-files))
106 (with-output-to-string (out)
107 (write-string (call-next-method) out)
108 (write (incf (file-number-counter output))
109 :stream out
110 :radix nil
111 :base (file-number-base output))
112 (write-string (output-file-suffix output) out)))
113
114 (defgeneric get-next-output-stream (output)
115 (:documentation "Gets the stream for the next (or only) page of an
116 output-destination."))
117
118 (defmethod get-next-output-stream ((output output-destination))
119 (or (output-stream output)
120 (apply 'open (get-next-filename output) :direction :output
121 (open-file-args output))))
122
123 (defmacro with-next-output-stream ((var output) &body body)
124 `(with-open-stream (,var (get-next-output-stream ,output))
125 ,@body))

  ViewVC Help
Powered by ViewVC 1.1.5