2
'\" Copyright (c) 1996 Sun Microsystems, Inc.
4
'\" See the file "license.terms" for information on usage and redistribution
5
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7
'\" RCS: @(#) $Id: MeasureChar.3,v 1.2 1998/09/14 18:22:52 stanton Exp $
10
.TH Tk_MeasureChars 3 "" Tk "Tk Library Procedures"
13
Tk_MeasureChars, Tk_TextWidth, Tk_DrawChars, Tk_UnderlineChars \- routines to measure and display simple single-line strings.
19
\fBTk_MeasureChars(\fItkfont, string, maxChars, maxPixels, flags, lengthPtr\fB)\fR
22
\fBTk_TextWidth(\fItkfont, string, numChars\fB)\fR
25
\fBTk_DrawChars(\fIdisplay, drawable, gc, tkfont, string, numChars, x, y\fB)\fR
28
\fBTk_UnderlineChars(\fIdisplay, drawable, gc, tkfont, string, x, y, firstChar, lastChar\fB)\fR
31
.AS "const char" firstChar
33
Token for font in which text is to be drawn or measured. Must have been
34
returned by a previous call to \fBTk_GetFont\fR.
35
.AP "const char" *string in
36
Text to be measured or displayed. Need not be null terminated. Any
37
non-printing meta-characters in the string (such as tabs, newlines, and
38
other control characters) will be measured or displayed in a
39
platform-dependent manner.
41
The maximum number of characters to consider when measuring \fIstring\fR.
42
Must be greater than or equal to 0.
44
If \fImaxPixels\fR is greater than 0, it specifies the longest permissible
45
line length in pixels. Characters from \fIstring\fR are processed only
46
until this many pixels have been covered. If \fImaxPixels\fR is <= 0, then
47
the line length is unbounded and the \fIflags\fR argument is ignored.
49
Various flag bits OR-ed together: TK_PARTIAL_OK means include a character
50
as long as any part of it fits in the length given by \fImaxPixels\fR;
51
otherwise, a character must fit completely to be considered.
52
TK_WHOLE_WORDS means stop on a word boundary, if possible. If
53
TK_AT_LEAST_ONE is set, it means return at least one character even if no
54
characters could fit in the length given by \fImaxPixels\fR. If
55
TK_AT_LEAST_ONE is set and TK_WHOLE_WORDS is also set, it means that if
56
not even one word fits on the line, return the first few letters of the
57
word that did fit; if not even one letter of the word fit, then the first
58
letter will still be returned.
59
.AP int *lengthPtr out
60
Filled with the number of pixels occupied by the number of characters
61
returned as the result of \fBTk_MeasureChars\fR.
63
The total number of characters to measure or draw from \fIstring\fR. Must
64
be greater than or equal to 0.
65
.AP Display *display in
66
Display on which to draw.
67
.AP Drawable drawable in
68
Window or pixmap in which to draw.
70
Graphics context for drawing characters. The font selected into this GC
71
must be the same as the \fItkfont\fR.
73
Coordinates at which to place the left edge of the baseline when displaying
76
The index of the first character to underline in the \fIstring\fR.
77
Underlining begins at the left edge of this character.
79
The index of the last character up to which the underline will
80
be drawn. The character specified by \fIlastChar\fR will not itself be
86
These routines are for measuring and displaying simple single-font,
87
single-line, strings. To measure and display single-font, multi-line,
88
justified text, refer to the documentation for \fBTk_ComputeTextLayout\fR.
89
There is no programming interface in the core of Tk that supports
90
multi-font, multi-line text; support for that behavior must be built on
91
top of simpler layers.
93
A glyph is the displayable picture of a letter, number, or some other
94
symbol. Not all character codes in a given font have a glyph.
95
Characters such as tabs, newlines/returns, and control characters that
96
have no glyph are measured and displayed by these procedures in a
97
platform-dependent manner; under X, they are replaced with backslashed
98
escape sequences, while under Windows and Macintosh hollow or solid boxes
99
may be substituted. Refer to the documentation for
100
\fBTk_ComputeTextLayout\fR for a programming interface that supports the
101
platform-independent expansion of tab characters into columns and
102
newlines/returns into multi-line text.
104
\fBTk_MeasureChars\fR is used both to compute the length of a given
105
string and to compute how many characters from a string fit in a given
106
amount of space. The return value is the number of characters from
107
\fIstring\fR that fit in the space specified by \fImaxPixels\fR subject to
108
the conditions described by \fIflags\fR. If all characters fit, the return
109
value will be \fImaxChars\fR. \fI*lengthPtr\fR is filled with the computed
110
width, in pixels, of the portion of the string that was measured. For
111
example, if the return value is 5, then \fI*lengthPtr\fR is filled with the
112
distance between the left edge of \fIstring\fR[0] and the right edge of
115
\fBTk_TextWidth\fR is a wrapper function that provides a simpler interface
116
to the \fBTk_MeasureChars\fR function. The return value is how much
117
space in pixels the given \fIstring\fR needs.
119
\fBTk_DrawChars\fR draws the \fIstring\fR at the given location in the
120
given \fIdrawable\fR.
122
\fBTk_UnderlineChars\fR underlines the given range of characters in the
123
given \fIstring\fR. It doesn't draw the characters (which are assumed to
124
have been displayed previously by \fBTk_DrawChars\fR); it just draws the
125
underline. This procedure is used to underline a few characters without
126
having to construct an underlined font. To produce natively underlined
127
text, the appropriate underlined font should be constructed and used.