Fred Drake | 3a0351c | 1998-04-04 07:23:21 +0000 | [diff] [blame] | 1 | \section{Standard Module \module{formatter}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-formatter} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 3 | \stmodindex{formatter} |
| 4 | |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 5 | |
| 6 | This module supports two interface definitions, each with mulitple |
| 7 | implementations. The \emph{formatter} interface is used by the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 8 | \class{HTMLParser} class of the \module{htmllib} module, and the |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 9 | \emph{writer} interface is required by the formatter interface. |
Fred Drake | 858f787 | 1998-04-04 06:25:27 +0000 | [diff] [blame] | 10 | \withsubitem{(class in htmllib)}{\ttindex{HTMLParser}} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 11 | |
| 12 | Formatter objects transform an abstract flow of formatting events into |
| 13 | specific output events on writer objects. Formatters manage several |
| 14 | stack structures to allow various properties of a writer object to be |
| 15 | changed and restored; writers need not be able to handle relative |
| 16 | changes nor any sort of ``change back'' operation. Specific writer |
| 17 | properties which may be controlled via formatter objects are |
| 18 | horizontal alignment, font, and left margin indentations. A mechanism |
| 19 | is provided which supports providing arbitrary, non-exclusive style |
| 20 | settings to a writer as well. Additional interfaces facilitate |
| 21 | formatting events which are not reversible, such as paragraph |
| 22 | separation. |
| 23 | |
| 24 | Writer objects encapsulate device interfaces. Abstract devices, such |
| 25 | as file formats, are supported as well as physical devices. The |
| 26 | provided implementations all work with abstract devices. The |
| 27 | interface makes available mechanisms for setting the properties which |
| 28 | formatter objects manage and inserting data into the output. |
| 29 | |
| 30 | |
| 31 | \subsection{The Formatter Interface} |
| 32 | |
| 33 | Interfaces to create formatters are dependent on the specific |
| 34 | formatter class being instantiated. The interfaces described below |
| 35 | are the required interfaces which all formatters must support once |
| 36 | initialized. |
| 37 | |
| 38 | One data element is defined at the module level: |
| 39 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 40 | |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 41 | \begin{datadesc}{AS_IS} |
| 42 | Value which can be used in the font specification passed to the |
| 43 | \code{push_font()} method described below, or as the new value to any |
| 44 | other \code{push_\var{property}()} method. Pushing the \code{AS_IS} |
| 45 | value allows the corresponding \code{pop_\var{property}()} method to |
| 46 | be called without having to track whether the property was changed. |
| 47 | \end{datadesc} |
| 48 | |
| 49 | The following attributes are defined for formatter instance objects: |
| 50 | |
Fred Drake | 8f92595 | 1996-10-09 16:13:22 +0000 | [diff] [blame] | 51 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 52 | \begin{memberdesc}[formatter]{writer} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 53 | The writer instance with which the formatter interacts. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 54 | \end{memberdesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 55 | |
| 56 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 57 | \begin{methoddesc}[formatter]{end_paragraph}{blanklines} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 58 | Close any open paragraphs and insert at least \var{blanklines} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 59 | before the next paragraph. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 60 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 61 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 62 | \begin{methoddesc}[formatter]{add_line_break}{} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 63 | Add a hard line break if one does not already exist. This does not |
| 64 | break the logical paragraph. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 65 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 66 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 67 | \begin{methoddesc}[formatter]{add_hor_rule}{*args, **kw} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 68 | Insert a horizontal rule in the output. A hard break is inserted if |
| 69 | there is data in the current paragraph, but the logical paragraph is |
| 70 | not broken. The arguments and keywords are passed on to the writer's |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 71 | \method{send_line_break()} method. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 72 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 73 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 74 | \begin{methoddesc}[formatter]{add_flowing_data}{data} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 75 | Provide data which should be formatted with collapsed whitespaces. |
| 76 | Whitespace from preceeding and successive calls to |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 77 | \method{add_flowing_data()} is considered as well when the whitespace |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 78 | collapse is performed. The data which is passed to this method is |
| 79 | expected to be word-wrapped by the output device. Note that any |
| 80 | word-wrapping still must be performed by the writer object due to the |
| 81 | need to rely on device and font information. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 82 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 83 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 84 | \begin{methoddesc}[formatter]{add_literal_data}{data} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 85 | Provide data which should be passed to the writer unchanged. |
| 86 | Whitespace, including newline and tab characters, are considered legal |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 87 | in the value of \var{data}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 88 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 89 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 90 | \begin{methoddesc}[formatter]{add_label_data}{format, counter} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 91 | Insert a label which should be placed to the left of the current left |
| 92 | margin. This should be used for constructing bulleted or numbered |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 93 | lists. If the \var{format} value is a string, it is interpreted as a |
| 94 | format specification for \var{counter}, which should be an integer. |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 95 | The result of this formatting becomes the value of the label; if |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 96 | \var{format} is not a string it is used as the label value directly. |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 97 | The label value is passed as the only argument to the writer's |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 98 | \method{send_label_data()} method. Interpretation of non-string label |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 99 | values is dependent on the associated writer. |
| 100 | |
| 101 | Format specifications are strings which, in combination with a counter |
| 102 | value, are used to compute label values. Each character in the format |
| 103 | string is copied to the label value, with some characters recognized |
| 104 | to indicate a transform on the counter value. Specifically, the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 105 | character \character{1} represents the counter value formatter as an |
| 106 | arabic number, the characters \character{A} and \character{a} |
| 107 | represent alphabetic representations of the counter value in upper and |
| 108 | lower case, respectively, and \character{I} and \character{i} |
| 109 | represent the counter value in Roman numerals, in upper and lower |
| 110 | case. Note that the alphabetic and roman transforms require that the |
| 111 | counter value be greater than zero. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 112 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 113 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 114 | \begin{methoddesc}[formatter]{flush_softspace}{} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 115 | Send any pending whitespace buffered from a previous call to |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 116 | \method{add_flowing_data()} to the associated writer object. This |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 117 | should be called before any direct manipulation of the writer object. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 118 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 119 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 120 | \begin{methoddesc}[formatter]{push_alignment}{align} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 121 | Push a new alignment setting onto the alignment stack. This may be |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 122 | \constant{AS_IS} if no change is desired. If the alignment value is |
| 123 | changed from the previous setting, the writer's \method{new_alignment()} |
| 124 | method is called with the \var{align} value. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 125 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 126 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 127 | \begin{methoddesc}[formatter]{pop_alignment}{} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 128 | Restore the previous alignment. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 129 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 130 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 131 | \begin{methoddesc}[formatter]{push_font}{\code{(}size, italic, bold, teletype\code{)}} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 132 | Change some or all font properties of the writer object. Properties |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 133 | which are not set to \constant{AS_IS} are set to the values passed in |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 134 | while others are maintained at their current settings. The writer's |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 135 | \method{new_font()} method is called with the fully resolved font |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 136 | specification. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 137 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 138 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 139 | \begin{methoddesc}[formatter]{pop_font}{} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 140 | Restore the previous font. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 141 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 142 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 143 | \begin{methoddesc}[formatter]{push_margin}{margin} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 144 | Increase the number of left margin indentations by one, associating |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 145 | the logical tag \var{margin} with the new indentation. The initial |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 146 | margin level is \code{0}. Changed values of the logical tag must be |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 147 | true values; false values other than \constant{AS_IS} are not |
| 148 | sufficient to change the margin. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 149 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 150 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 151 | \begin{methoddesc}[formatter]{pop_margin}{} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 152 | Restore the previous margin. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 153 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 154 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 155 | \begin{methoddesc}[formatter]{push_style}{*styles} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 156 | Push any number of arbitrary style specifications. All styles are |
| 157 | pushed onto the styles stack in order. A tuple representing the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 158 | entire stack, including \constant{AS_IS} values, is passed to the |
| 159 | writer's \method{new_styles()} method. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 160 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 161 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 162 | \begin{methoddesc}[formatter]{pop_style}{\optional{n\code{ = 1}}} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 163 | Pop the last \var{n} style specifications passed to |
| 164 | \method{push_style()}. A tuple representing the revised stack, |
| 165 | including \constant{AS_IS} values, is passed to the writer's |
| 166 | \method{new_styles()} method. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 167 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 168 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 169 | \begin{methoddesc}[formatter]{set_spacing}{spacing} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 170 | Set the spacing style for the writer. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 171 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 172 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 173 | \begin{methoddesc}[formatter]{assert_line_data}{\optional{flag\code{ = 1}}} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 174 | Inform the formatter that data has been added to the current paragraph |
| 175 | out-of-band. This should be used when the writer has been manipulated |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 176 | directly. The optional \var{flag} argument can be set to false if |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 177 | the writer manipulations produced a hard line break at the end of the |
| 178 | output. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 179 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 180 | |
| 181 | |
| 182 | \subsection{Formatter Implementations} |
| 183 | |
Fred Drake | 8f92595 | 1996-10-09 16:13:22 +0000 | [diff] [blame] | 184 | Two implementations of formatter objects are provided by this module. |
| 185 | Most applications may use one of these classes without modification or |
| 186 | subclassing. |
| 187 | |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 188 | \begin{classdesc}{NullFormatter}{\optional{writer}} |
| 189 | A formatter which does nothing. If \var{writer} is omitted, a |
| 190 | \class{NullWriter} instance is created. No methods of the writer are |
| 191 | called by \class{NullFormatter} instances. Implementations should |
| 192 | inherit from this class if implementing a writer interface but don't |
| 193 | need to inherit any implementation. |
| 194 | \end{classdesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 195 | |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 196 | \begin{classdesc}{AbstractFormatter}{writer} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 197 | The standard formatter. This implementation has demonstrated wide |
| 198 | applicability to many writers, and may be used directly in most |
Fred Drake | 8f92595 | 1996-10-09 16:13:22 +0000 | [diff] [blame] | 199 | circumstances. It has been used to implement a full-featured |
| 200 | world-wide web browser. |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 201 | \end{classdesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 202 | |
| 203 | |
| 204 | |
| 205 | \subsection{The Writer Interface} |
| 206 | |
| 207 | Interfaces to create writers are dependent on the specific writer |
| 208 | class being instantiated. The interfaces described below are the |
| 209 | required interfaces which all writers must support once initialized. |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 210 | Note that while most applications can use the |
| 211 | \class{AbstractFormatter} class as a formatter, the writer must |
| 212 | typically be provided by the application. |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 213 | |
Fred Drake | 8f92595 | 1996-10-09 16:13:22 +0000 | [diff] [blame] | 214 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 215 | \begin{methoddesc}[writer]{flush}{} |
Fred Drake | 591bbb1 | 1996-12-31 20:51:42 +0000 | [diff] [blame] | 216 | Flush any buffered output or device control events. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 217 | \end{methoddesc} |
Fred Drake | 591bbb1 | 1996-12-31 20:51:42 +0000 | [diff] [blame] | 218 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 219 | \begin{methoddesc}[writer]{new_alignment}{align} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 220 | Set the alignment style. The \var{align} value can be any object, |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 221 | but by convention is a string or \code{None}, where \code{None} |
| 222 | indicates that the writer's ``preferred'' alignment should be used. |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 223 | Conventional \var{align} values are \code{'left'}, \code{'center'}, |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 224 | \code{'right'}, and \code{'justify'}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 225 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 226 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 227 | \begin{methoddesc}[writer]{new_font}{font} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 228 | Set the font style. The value of \var{font} will be \code{None}, |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 229 | indicating that the device's default font should be used, or a tuple |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 230 | of the form \code{(}\var{size}, \var{italic}, \var{bold}, |
| 231 | \var{teletype}\code{)}. Size will be a string indicating the size of |
| 232 | font that should be used; specific strings and their interpretation |
| 233 | must be defined by the application. The \var{italic}, \var{bold}, and |
| 234 | \var{teletype} values are boolean indicators specifying which of those |
| 235 | font attributes should be used. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 236 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 237 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 238 | \begin{methoddesc}[writer]{new_margin}{margin, level} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 239 | Set the margin level to the integer \var{level} and the logical tag |
| 240 | to \var{margin}. Interpretation of the logical tag is at the |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 241 | writer's discretion; the only restriction on the value of the logical |
| 242 | tag is that it not be a false value for non-zero values of |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 243 | \var{level}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 244 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 245 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 246 | \begin{methoddesc}[writer]{new_spacing}{spacing} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 247 | Set the spacing style to \var{spacing}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 248 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 249 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 250 | \begin{methoddesc}[writer]{new_styles}{styles} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 251 | Set additional styles. The \var{styles} value is a tuple of |
| 252 | arbitrary values; the value \constant{AS_IS} should be ignored. The |
| 253 | \var{styles} tuple may be interpreted either as a set or as a stack |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 254 | depending on the requirements of the application and writer |
| 255 | implementation. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 256 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 257 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 258 | \begin{methoddesc}[writer]{send_line_break}{} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 259 | Break the current line. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 260 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 261 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 262 | \begin{methoddesc}[writer]{send_paragraph}{blankline} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 263 | Produce a paragraph separation of at least \var{blankline} blank |
| 264 | lines, or the equivelent. The \var{blankline} value will be an |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 265 | integer. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 266 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 267 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 268 | \begin{methoddesc}[writer]{send_hor_rule}{*args, **kw} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 269 | Display a horizontal rule on the output device. The arguments to this |
| 270 | method are entirely application- and writer-specific, and should be |
| 271 | interpreted with care. The method implementation may assume that a |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 272 | line break has already been issued via \method{send_line_break()}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 273 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 274 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 275 | \begin{methoddesc}[writer]{send_flowing_data}{data} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 276 | Output character data which may be word-wrapped and re-flowed as |
| 277 | needed. Within any sequence of calls to this method, the writer may |
| 278 | assume that spans of multiple whitespace characters have been |
| 279 | collapsed to single space characters. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 280 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 281 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 282 | \begin{methoddesc}[writer]{send_literal_data}{data} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 283 | Output character data which has already been formatted |
| 284 | for display. Generally, this should be interpreted to mean that line |
| 285 | breaks indicated by newline characters should be preserved and no new |
| 286 | line breaks should be introduced. The data may contain embedded |
| 287 | newline and tab characters, unlike data provided to the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 288 | \method{send_formatted_data()} interface. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 289 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 290 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 291 | \begin{methoddesc}[writer]{send_label_data}{data} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 292 | Set \var{data} to the left of the current left margin, if possible. |
| 293 | The value of \var{data} is not restricted; treatment of non-string |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 294 | values is entirely application- and writer-dependent. This method |
| 295 | will only be called at the beginning of a line. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 296 | \end{methoddesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 297 | |
| 298 | |
| 299 | \subsection{Writer Implementations} |
| 300 | |
Fred Drake | 8f92595 | 1996-10-09 16:13:22 +0000 | [diff] [blame] | 301 | Three implementations of the writer object interface are provided as |
| 302 | examples by this module. Most applications will need to derive new |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 303 | writer classes from the \class{NullWriter} class. |
Fred Drake | 8f92595 | 1996-10-09 16:13:22 +0000 | [diff] [blame] | 304 | |
Fred Drake | 7bf5e08 | 1998-03-16 05:07:04 +0000 | [diff] [blame] | 305 | \begin{classdesc}{NullWriter}{} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 306 | A writer which only provides the interface definition; no actions are |
| 307 | taken on any methods. This should be the base class for all writers |
| 308 | which do not need to inherit any implementation methods. |
Fred Drake | 7bf5e08 | 1998-03-16 05:07:04 +0000 | [diff] [blame] | 309 | \end{classdesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 310 | |
Fred Drake | 7bf5e08 | 1998-03-16 05:07:04 +0000 | [diff] [blame] | 311 | \begin{classdesc}{AbstractWriter}{} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 312 | A writer which can be used in debugging formatters, but not much |
Fred Drake | 5081b22 | 1998-01-15 05:49:00 +0000 | [diff] [blame] | 313 | else. Each method simply announces itself by printing its name and |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 314 | arguments on standard output. |
Fred Drake | 7bf5e08 | 1998-03-16 05:07:04 +0000 | [diff] [blame] | 315 | \end{classdesc} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 316 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 317 | \begin{classdesc}{DumbWriter}{\optional{file\optional{, maxcol\code{ = 72}}}} |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 318 | Simple writer class which writes output on the file object passed in |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 319 | as \var{file} or, if \var{file} is omitted, on standard output. The |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 320 | output is simply word-wrapped to the number of columns specified by |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 321 | \var{maxcol}. This class is suitable for reflowing a sequence of |
Fred Drake | e83b30d | 1996-10-08 21:53:33 +0000 | [diff] [blame] | 322 | paragraphs. |
Fred Drake | 7bf5e08 | 1998-03-16 05:07:04 +0000 | [diff] [blame] | 323 | \end{classdesc} |