Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / Tk_CharBbox.3
CommitLineData
920dae64
AT
1'\"
2'\" Copyright (c) 1996 Sun Microsystems, Inc.
3'\"
4'\" See the file "license.terms" for information on usage and redistribution
5'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6'\"
7'\" RCS: @(#) $Id: TextLayout.3,v 1.5 1999/04/21 21:53:22 rjohnson Exp $
8'\"
9'\" The definitions below are for supplemental macros used in Tcl/Tk
10'\" manual entries.
11'\"
12'\" .AP type name in/out ?indent?
13'\" Start paragraph describing an argument to a library procedure.
14'\" type is type of argument (int, etc.), in/out is either "in", "out",
15'\" or "in/out" to describe whether procedure reads or modifies arg,
16'\" and indent is equivalent to second arg of .IP (shouldn't ever be
17'\" needed; use .AS below instead)
18'\"
19'\" .AS ?type? ?name?
20'\" Give maximum sizes of arguments for setting tab stops. Type and
21'\" name are examples of largest possible arguments that will be passed
22'\" to .AP later. If args are omitted, default tab stops are used.
23'\"
24'\" .BS
25'\" Start box enclosure. From here until next .BE, everything will be
26'\" enclosed in one large box.
27'\"
28'\" .BE
29'\" End of box enclosure.
30'\"
31'\" .CS
32'\" Begin code excerpt.
33'\"
34'\" .CE
35'\" End code excerpt.
36'\"
37'\" .VS ?version? ?br?
38'\" Begin vertical sidebar, for use in marking newly-changed parts
39'\" of man pages. The first argument is ignored and used for recording
40'\" the version when the .VS was added, so that the sidebars can be
41'\" found and removed when they reach a certain age. If another argument
42'\" is present, then a line break is forced before starting the sidebar.
43'\"
44'\" .VE
45'\" End of vertical sidebar.
46'\"
47'\" .DS
48'\" Begin an indented unfilled display.
49'\"
50'\" .DE
51'\" End of indented unfilled display.
52'\"
53'\" .SO
54'\" Start of list of standard options for a Tk widget. The
55'\" options follow on successive lines, in four columns separated
56'\" by tabs.
57'\"
58'\" .SE
59'\" End of list of standard options for a Tk widget.
60'\"
61'\" .OP cmdName dbName dbClass
62'\" Start of description of a specific option. cmdName gives the
63'\" option's name as specified in the class command, dbName gives
64'\" the option's name in the option database, and dbClass gives
65'\" the option's class in the option database.
66'\"
67'\" .UL arg1 arg2
68'\" Print arg1 underlined, then print arg2 normally.
69'\"
70'\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $
71'\"
72'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
73.if t .wh -1.3i ^B
74.nr ^l \n(.l
75.ad b
76'\" # Start an argument description
77.de AP
78.ie !"\\$4"" .TP \\$4
79.el \{\
80. ie !"\\$2"" .TP \\n()Cu
81. el .TP 15
82.\}
83.ta \\n()Au \\n()Bu
84.ie !"\\$3"" \{\
85\&\\$1 \\fI\\$2\\fP (\\$3)
86.\".b
87.\}
88.el \{\
89.br
90.ie !"\\$2"" \{\
91\&\\$1 \\fI\\$2\\fP
92.\}
93.el \{\
94\&\\fI\\$1\\fP
95.\}
96.\}
97..
98'\" # define tabbing values for .AP
99.de AS
100.nr )A 10n
101.if !"\\$1"" .nr )A \\w'\\$1'u+3n
102.nr )B \\n()Au+15n
103.\"
104.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
105.nr )C \\n()Bu+\\w'(in/out)'u+2n
106..
107.AS Tcl_Interp Tcl_CreateInterp in/out
108'\" # BS - start boxed text
109'\" # ^y = starting y location
110'\" # ^b = 1
111.de BS
112.br
113.mk ^y
114.nr ^b 1u
115.if n .nf
116.if n .ti 0
117.if n \l'\\n(.lu\(ul'
118.if n .fi
119..
120'\" # BE - end boxed text (draw box now)
121.de BE
122.nf
123.ti 0
124.mk ^t
125.ie n \l'\\n(^lu\(ul'
126.el \{\
127.\" Draw four-sided box normally, but don't draw top of
128.\" box if the box started on an earlier page.
129.ie !\\n(^b-1 \{\
130\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
131.\}
132.el \}\
133\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
134.\}
135.\}
136.fi
137.br
138.nr ^b 0
139..
140'\" # VS - start vertical sidebar
141'\" # ^Y = starting y location
142'\" # ^v = 1 (for troff; for nroff this doesn't matter)
143.de VS
144.if !"\\$2"" .br
145.mk ^Y
146.ie n 'mc \s12\(br\s0
147.el .nr ^v 1u
148..
149'\" # VE - end of vertical sidebar
150.de VE
151.ie n 'mc
152.el \{\
153.ev 2
154.nf
155.ti 0
156.mk ^t
157\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
158.sp -1
159.fi
160.ev
161.\}
162.nr ^v 0
163..
164'\" # Special macro to handle page bottom: finish off current
165'\" # box/sidebar if in box/sidebar mode, then invoked standard
166'\" # page bottom macro.
167.de ^B
168.ev 2
169'ti 0
170'nf
171.mk ^t
172.if \\n(^b \{\
173.\" Draw three-sided box if this is the box's first page,
174.\" draw two sides but no top otherwise.
175.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
176.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177.\}
178.if \\n(^v \{\
179.nr ^x \\n(^tu+1v-\\n(^Yu
180\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
181.\}
182.bp
183'fi
184.ev
185.if \\n(^b \{\
186.mk ^y
187.nr ^b 2
188.\}
189.if \\n(^v \{\
190.mk ^Y
191.\}
192..
193'\" # DS - begin display
194.de DS
195.RS
196.nf
197.sp
198..
199'\" # DE - end display
200.de DE
201.fi
202.RE
203.sp
204..
205'\" # SO - start of list of standard options
206.de SO
207.SH "STANDARD OPTIONS"
208.LP
209.nf
210.ta 5.5c 11c
211.ft B
212..
213'\" # SE - end of list of standard options
214.de SE
215.fi
216.ft R
217.LP
218See the \\fBoptions\\fR manual entry for details on the standard options.
219..
220'\" # OP - start of full description for a single option
221.de OP
222.LP
223.nf
224.ta 4c
225Command-Line Name: \\fB\\$1\\fR
226Database Name: \\fB\\$2\\fR
227Database Class: \\fB\\$3\\fR
228.fi
229.IP
230..
231'\" # CS - begin code excerpt
232.de CS
233.RS
234.nf
235.ta .25i .5i .75i 1i
236..
237'\" # CE - end code excerpt
238.de CE
239.fi
240.RE
241..
242.de UL
243\\$1\l'|0\(ul'\\$2
244..
245.TH Tk_ComputeTextLayout 3 8.1 Tk "Tk Library Procedures"
246.BS
247.SH NAME
248Tk_ComputeTextLayout, Tk_FreeTextLayout, Tk_DrawTextLayout, Tk_UnderlineTextLayout, Tk_PointToChar, Tk_CharBbox, Tk_DistanceToTextLayout, Tk_IntersectTextLayout, Tk_TextLayoutToPostscript \- routines to measure and display single-font, multi-line, justified text.
249.SH SYNOPSIS
250.nf
251\fB#include <tk.h>\fR
252.sp
253Tk_TextLayout
254\fBTk_ComputeTextLayout(\fItkfont, string, numChars, wrapLength, justify, flags, widthPtr, heightPtr\fB)\fR
255.sp
256void
257\fBTk_FreeTextLayout(\fIlayout\fB)\fR
258.sp
259void
260\fBTk_DrawTextLayout(\fIdisplay, drawable, gc, layout, x, y, firstChar, lastChar\fB)\fR
261.sp
262void
263\fBTk_UnderlineTextLayout(\fIdisplay, drawable, gc, layout, x, y, underline\fB)\fR
264.sp
265int
266\fBTk_PointToChar(\fIlayout, x, y\fB)\fR
267.sp
268int
269\fBTk_CharBbox(\fIlayout, index, xPtr, yPtr, widthPtr, heightPtr\fB)\fR
270.sp
271int
272\fBTk_DistanceToTextLayout(\fIlayout, x, y\fB)\fR
273.sp
274int
275\fBTk_IntersectTextLayout(\fIlayout, x, y, width, height\fB)\fR
276.sp
277void
278\fBTk_TextLayoutToPostscript(\fIinterp, layout\fB)\fR
279
280.SH ARGUMENTS
281.AS Tk_TextLayout "*xPtr, *yPtr"
282.AP Tk_Font tkfont in
283Font to use when constructing and displaying a text layout. The
284\fItkfont\fR must remain valid for the lifetime of the text layout. Must
285have been returned by a previous call to \fBTk_GetFont\fR.
286.AP "const char" *string in
287Potentially multi-line string whose dimensions are to be computed and
288stored in the text layout. The \fIstring\fR must remain valid for the
289lifetime of the text layout.
290.AP int numChars in
291The number of characters to consider from \fIstring\fR. If
292\fInumChars\fR is less than 0, then assumes \fIstring\fR is null
293.VS 8.1
294terminated and uses \fBTcl_NumUtfChars\fR to determine the length of
295\fIstring\fR.
296.VE
297.AP int wrapLength in
298Longest permissible line length, in pixels. Lines in \fIstring\fR will
299automatically be broken at word boundaries and wrapped when they reach
300this length. If \fIwrapLength\fR is too small for even a single
301character to fit on a line, it will be expanded to allow one character to
302fit on each line. If \fIwrapLength\fR is <= 0, there is no automatic
303wrapping; lines will get as long as they need to be and only wrap if a
304newline/return character is encountered.
305.AP Tk_Justify justify in
306How to justify the lines in a multi-line text layout. Possible values
307are TK_JUSTIFY_LEFT, TK_JUSTIFY_CENTER, or TK_JUSTIFY_RIGHT. If the text
308layout only occupies a single line, then \fIjustify\fR is irrelevant.
309.AP int flags in
310Various flag bits OR-ed together. TK_IGNORE_TABS means that tab characters
311should not be expanded to the next tab stop. TK_IGNORE_NEWLINES means that
312newline/return characters should not cause a line break. If either tabs or
313newlines/returns are ignored, then they will be treated as regular
314characters, being measured and displayed in a platform-dependent manner as
315described in \fBTk_MeasureChars\fR, and will not have any special behaviors.
316.AP int *widthPtr out
317If non-NULL, filled with either the width, in pixels, of the widest
318line in the text layout, or the width, in pixels, of the bounding box for the
319character specified by \fIindex\fR.
320.AP int *heightPtr out
321If non-NULL, filled with either the total height, in pixels, of all
322the lines in the text layout, or the height, in pixels, of the bounding
323box for the character specified by \fIindex\fR.
324.AP Tk_TextLayout layout in
325A token that represents the cached layout information about the single-font,
326multi-line, justified piece of text. This token is returned by
327\fBTk_ComputeTextLayout\fR.
328.AP Display *display in
329Display on which to draw.
330.AP Drawable drawable in
331Window or pixmap in which to draw.
332.AP GC gc in
333Graphics context to use for drawing text layout. The font selected in
334this GC must correspond to the \fItkfont\fR used when constructing the
335text layout.
336.AP int "x, y" in
337Point, in pixels, at which to place the upper-left hand corner of the
338text layout when it is being drawn, or the coordinates of a point (with
339respect to the upper-left hand corner of the text layout) to check
340against the text layout.
341.AP int firstChar in
342The index of the first character to draw from the given text layout.
343The number 0 means to draw from the beginning.
344.AP int lastChar in
345The index of the last character up to which to draw. The character
346specified by \fIlastChar\fR itself will not be drawn. A number less
347than 0 means to draw all characters in the text layout.
348.AP int underline in
349Index of the single character to underline in the text layout, or a number
350less than 0 for no underline.
351.AP int index in
352The index of the character whose bounding box is desired. The bounding
353box is computed with respect to the upper-left hand corner of the text layout.
354.AP int "*xPtr, *yPtr" out
355Filled with the upper-left hand corner, in pixels, of the bounding box
356for the character specified by \fIindex\fR. Either or both \fIxPtr\fR
357and \fIyPtr\fR may be NULL, in which case the corresponding value
358is not calculated.
359.AP int "width, height" in
360Specifies the width and height, in pixels, of the rectangular area to
361compare for intersection against the text layout.
362.AP Tcl_Interp *interp out
363Postscript code that will print the text layout is appended to
364\fIinterp->result\fR.
365.BE
366
367.SH DESCRIPTION
368.PP
369These routines are for measuring and displaying single-font, multi-line,
370justified text. To measure and display simple single-font, single-line
371strings, refer to the documentation for \fBTk_MeasureChars\fR. There is
372no programming interface in the core of Tk that supports multi-font,
373multi-line text; support for that behavior must be built on top of
374simpler layers.
375.VS 8.1
376Note that unlike the lower level text display routines, the functions
377described here all operate on character-oriented lengths and indices
378rather than byte-oriented values. See the description of
379\fBTcl_UtfAtIndex\fR for more details on converting between character
380and byte offsets.
381.VE 8.1
382.PP
383The routines described here are built on top of the programming interface
384described in the \fBTk_MeasureChars\fR documentation. Tab characters and
385newline/return characters may be treated specially by these procedures,
386but all other characters are passed through to the lower level.
387.PP
388\fBTk_ComputeTextLayout\fR computes the layout information needed to
389display a single-font, multi-line, justified \fIstring\fR of text and
390returns a Tk_TextLayout token that holds this information. This token is
391used in subsequent calls to procedures such as \fBTk_DrawTextLayout\fR,
392\fBTk_DistanceToTextLayout\fR, and \fBTk_FreeTextLayout\fR. The
393\fIstring\fR and \fItkfont\fR used when computing the layout must remain
394valid for the lifetime of this token.
395.PP
396\fBTk_FreeTextLayout\fR is called to release the storage associated with
397\fIlayout\fR when it is no longer needed. A \fIlayout\fR should not be used
398in any other text layout procedures once it has been released.
399.PP
400\fBTk_DrawTextLayout\fR uses the information in \fIlayout\fR to display a
401single-font, multi-line, justified string of text at the specified location.
402.PP
403\fBTk_UnderlineTextLayout\fR uses the information in \fIlayout\fR to
404display an underline below an individual character. This procedure does
405not draw the text, just the underline. To produce natively underlined
406text, an underlined font should be constructed and used. All characters,
407including tabs, newline/return characters, and spaces at the ends of
408lines, can be underlined using this method. However, the underline will
409never be drawn outside of the computed width of \fIlayout\fR; the
410underline will stop at the edge for any character that would extend
411partially outside of \fIlayout\fR, and the underline will not be visible
412at all for any character that would be located completely outside of the
413layout.
414.PP
415\fBTk_PointToChar\fR uses the information in \fIlayout\fR to determine the
416character closest to the given point. The point is specified with respect
417to the upper-left hand corner of the \fIlayout\fR, which is considered to be
418located at (0, 0). Any point whose \fIy\fR-value is less that 0 will be
419considered closest to the first character in the text layout; any point
420whose \fIy\fR-value is greater than the height of the text layout will be
421considered closest to the last character in the text layout. Any point
422whose \fIx\fR-value is less than 0 will be considered closest to the first
423character on that line; any point whose \fIx\fR-value is greater than the
424width of the text layout will be considered closest to the last character on
425that line. The return value is the index of the character that was closest
426to the point. Given a \fIlayout\fR with no characters, the value 0 will
427always be returned, referring to a hypothetical zero-width placeholder
428character.
429.PP
430\fBTk_CharBbox\fR uses the information in \fIlayout\fR to return the
431bounding box for the character specified by \fIindex\fR. The width of the
432bounding box is the advance width of the character, and does not include any
433left or right bearing. Any character that extends partially outside of
434\fIlayout\fR is considered to be truncated at the edge. Any character
435that would be located completely outside of \fIlayout\fR is considered to
436be zero-width and pegged against the edge. The height of the bounding
437box is the line height for this font, extending from the top of the
438ascent to the bottom of the descent; information about the actual height
439of individual letters is not available. For measurement purposes, a
440\fIlayout\fR that contains no characters is considered to contain a
441single zero-width placeholder character at index 0. If \fIindex\fR was
442not a valid character index, the return value is 0 and \fI*xPtr\fR,
443\fI*yPtr\fR, \fI*widthPtr\fR, and \fI*heightPtr\fR are unmodified.
444Otherwise, if \fIindex\fR did specify a valid, the return value is
445non-zero, and \fI*xPtr\fR, \fI*yPtr\fR, \fI*widthPtr\fR, and
446\fI*heightPtr\fR are filled with the bounding box information for the
447character. If any of \fIxPtr\fR, \fIyPtr\fR, \fIwidthPtr\fR, or
448\fIheightPtr\fR are NULL, the corresponding value is not calculated or
449stored.
450.PP
451\fBTk_DistanceToTextLayout\fR computes the shortest distance in pixels from
452the given point (\fIx, y\fR) to the characters in \fIlayout\fR.
453Newline/return characters and non-displaying space characters that occur at
454the end of individual lines in the text layout are ignored for hit detection
455purposes, but tab characters are not. The return value is 0 if the point
456actually hits the \fIlayout\fR. If the point didn't hit the \fIlayout\fR
457then the return value is the distance in pixels from the point to the
458\fIlayout\fR.
459.PP
460\fBTk_IntersectTextLayout\fR determines whether a \fIlayout\fR lies
461entirely inside, entirely outside, or overlaps a given rectangle.
462Newline/return characters and non-displaying space characters that occur
463at the end of individual lines in the \fIlayout\fR are ignored for
464intersection calculations. The return value is \-1 if the \fIlayout\fR is
465entirely outside of the rectangle, 0 if it overlaps, and 1 if it is
466entirely inside of the rectangle.
467.PP
468\fBTk_TextLayoutToPostscript\fR outputs code consisting of a Postscript
469array of strings that represent the individual lines in \fIlayout\fR. It
470is the responsibility of the caller to take the Postscript array of
471strings and add some Postscript function operate on the array to render
472each of the lines. The code that represents the Postscript array of
473strings is appended to \fIinterp->result\fR.
474.PP
475.SH DISPLAY MODEL
476When measuring a text layout, space characters that occur at the end of a
477line are ignored. The space characters still exist and the insertion point
478can be positioned amongst them, but their additional width is ignored when
479justifying lines or returning the total width of a text layout. All
480end-of-line space characters are considered to be attached to the right edge
481of the line; this behavior is logical for left-justified text and reasonable
482for center-justified text, but not very useful when editing right-justified
483text. Spaces are considered variable width characters; the first space that
484extends past the edge of the text layout is clipped to the edge, and any
485subsequent spaces on the line are considered zero width and pegged against
486the edge. Space characters that occur in the middle of a line of text are
487not suppressed and occupy their normal space width.
488.PP
489Tab characters are not ignored for measurement calculations. If wrapping
490is turned on and there are enough tabs on a line, the next tab will wrap
491to the beginning of the next line. There are some possible strange
492interactions between tabs and justification; tab positions are calculated
493and the line length computed in a left-justified world, and then the
494whole resulting line is shifted so it is centered or right-justified,
495causing the tab columns not to align any more.
496.PP
497When wrapping is turned on, lines may wrap at word breaks (space or tab
498characters) or newline/returns. A dash or hyphen character in the middle
499of a word is not considered a word break. \fBTk_ComputeTextLayout\fR
500always attempts to place at least one word on each line. If it cannot
501because the \fIwrapLength\fR is too small, the word will be broken and as
502much as fits placed on the line and the rest on subsequent line(s). If
503\fIwrapLength\fR is so small that not even one character can fit on a
504given line, the \fIwrapLength\fR is ignored for that line and one
505character will be placed on the line anyhow. When wrapping is turned
506off, only newline/return characters may cause a line break.
507.PP
508When a text layout has been created using an underlined \fItkfont\fR,
509then any space characters that occur at the end of individual lines,
510newlines/returns, and tabs will not be displayed underlined when
511\fBTk_DrawTextLayout\fR is called, because those characters are never
512actually drawn \- they are merely placeholders maintained in the
513\fIlayout\fR.
514.SH KEYWORDS
515font