All Manuals > CLIM 2.0 User Guide > 13 Extended Stream Output Facilities

13.4 Text

This section addresses text as it relates to output streams.

13.4.1 The Text Protocol

The following generic functions comprise the text protocol. Any extended output stream class must implement methods for these generic functions.

stream-character-width Generic Function

stream-character-width stream character &key text-style

Summary: Returns a rational number corresponding to the amount of horizontal motion of the cursor position that would occur if the character character were output to the extended output stream stream in the text style text-style (which defaults to the current text style for the stream). This ignores the stream's text margin.

stream-string-width Generic Function

stream-string-width stream string &key start end text-style

Summary: Computes how the cursor position would move horizontally if the string string were output to the extended output stream stream in the text style text-style (which defaults to the current text style for the stream) starting at the left margin. This ignores the stream's text margin.

The first returned value is the x coordinate that the cursor position would move to. The second returned value is the maximum x coordinate the cursor would visit during the output. (This is the same as the first value unless the string contains a #\Newline character.)

start and end are integers that default to 0 and the string length, respectively.

stream-text-margin Generic Function

stream-text-margin stream

(setf stream-text-margin) Generic Function

(setf stream-text-margin) margin stream

Summary: Returns the x coordinate at which text wraps around on the extended output stream stream (see stream-end-of-line-action). The default setting is the width of the viewport, which is the right-hand edge of the viewport when it is horizontally scrolled to the "initial position".

You can use setf with stream-text-margin to establish a new text margin. If margin is nil, then the width of the viewport will be used. If the width of the viewport is later changed, the text margin will change, too.

stream-line-height Generic Function

stream-line-height stream &key text-style

Summary: Returns what the line height of a line on the extended output stream stream containing text in the text style text-style would be, as a rational number. text-style defaults to the current text style for the stream.

stream-vertical-spacing Generic Function

stream-vertical-spacing stream

Summary: Returns the current inter-line spacing (as a rational number) for the extended output stream stream.

stream-baseline Generic Function

stream-baseline stream

Summary: Returns the current text baseline (as a rational number) for the extended output stream stream.

13.4.2 Mixing Text and Graphics

The following macro provides a convenient way to mix text and graphics on the same output stream.

with-room-for-graphics Macro

with-room-for-graphics (&optional stream &key (move-cursor t) height record-type) &body body

Summary: Binds the dynamic environment to establish a local Cartesian coordinate system for doing graphics output onto the extended output stream designated by stream. The origin (0, 0) of the local coordinate system is placed at the current cursor position, and is in the lower left corner of the area created. If the boolean move-cursor is t (the default), then after the graphic output is completed, the cursor is positioned past (immediately below) this origin. The bottom of the vertical block allocated is at this location, that is just below point (0, 0), not necessarily at the bottom of the output done.

The stream argument is not evaluated, and must be a symbol that is bound to a stream. If stream is t (the default), *standard-output* is used. body may have zero or more declarations as its first forms.

If height is supplied, it must be a rational number that specifies the amount of vertical space to allocate for the output, in device units. If it is not supplied, the height is computed from the output.

record-type specifies the class of output record to create to hold the graphical output. The default is standard-sequence-output-record.

13.4.3 Wrapping Text Lines

stream-end-of-line-action Generic Function

stream-end-of-line-action stream

(setf stream-end-of-line-action) Generic Function

(setf stream-end-of-line-action) action stream

Summary: The end-of-line action controls what happens if the text cursor position moves horizontally out of the viewport or if text output reaches the text margin. (By default the text margin is the width of the viewport, so these often coincide.)

stream-end-of-line-action returns the end-of-line action for the extended output stream stream. It can be changed by using setf on stream-end-of-line-action.

The end-of-line action is one of:

with-end-of-line-action Macro

with-end-of-line-action (stream action) &body body

Summary: Temporarily changes stream's end-of-line action for the duration of execution of body. action must be one of the actions described in stream-end-of-line-action.

The stream argument is not evaluated, and must be a symbol that is bound to a stream. If stream is t, *standard-output* is used. body may have zero or more declarations as its first forms.

stream-end-of-page-action Generic Function

stream-end-of-page-action stream

(setf stream-end-of-page-action) Generic Function

(setf stream-end-of-page-action) action stream

Summary: The end-of-page action controls what happens if the text cursor position moves vertically out of the viewport.

stream-end-of-page-action returns the end-of-page action for the extended output stream stream. Change it by using setf on stream-end-of-page-action.

The end-of-page action is one of:

with-end-of-page-action Macro

with-end-of-page-action (stream action) &body body

Summary: Temporarily changes stream's end-of-page action for the duration of execution of body. action must be one of the actions described in stream-end-of-page-action.

The stream argument is not evaluated, and must be a symbol that is bound to a stream. If stream is t, *standard-output* is used. body may have zero or more declarations as its first forms.


CLIM 2.0 User Guide - 01 Dec 2021 19:38:59