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