OSDN Git Service

* cgen-asm.in: Update copyright year.
[pf3gnuchains/pf3gnuchains3x.git] / tk / doc / MeasureChar.3
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$
8 '\" 
9 .so man.macros
10 .TH Tk_MeasureChars 3 8.1 Tk "Tk Library Procedures"
11 .BS
12 .SH NAME
13 Tk_MeasureChars, Tk_TextWidth, Tk_DrawChars, Tk_UnderlineChars \- routines to measure and display simple single-line strings.
14 .SH SYNOPSIS
15 .nf
16 \fB#include <tk.h>\fR
17 .sp
18 int
19 \fBTk_MeasureChars(\fItkfont, string, numBytes, maxPixels, flags, lengthPtr\fB)\fR
20 .sp
21 int
22 \fBTk_TextWidth(\fItkfont, string, numBytes\fB)\fR
23 .sp
24 void
25 \fBTk_DrawChars(\fIdisplay, drawable, gc, tkfont, string, numBytes, x, y\fB)\fR
26 .sp
27 void
28 \fBTk_UnderlineChars(\fIdisplay, drawable, gc, tkfont, string, x, y, firstByte, lastByte\fB)\fR
29 .sp
30 .SH ARGUMENTS
31 .AS "const char" firstChar
32 .AP Tk_Font tkfont in
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.  
40 .VS 8.1
41 .AP int numBytes in
42 The maximum number of bytes to consider when measuring or drawing
43 \fIstring\fR.  Must be greater than or equal to 0.
44 .VE 8.1
45 .AP int maxPixels in
46 If \fImaxPixels\fR is >= 0, it specifies the longest permissible
47 line length in pixels.  Characters from \fIstring\fR are processed only
48 until this many pixels have been covered.  If \fImaxPixels\fR is < 0, then
49 the line length is unbounded and the \fIflags\fR argument is ignored.
50 .AP int flags in
51 Various flag bits OR-ed together: TK_PARTIAL_OK means include a character
52 as long as any part of it fits in the length given by \fImaxPixels\fR;
53 otherwise, a character must fit completely to be considered.
54 TK_WHOLE_WORDS means stop on a word boundary, if possible.  If
55 TK_AT_LEAST_ONE is set, it means return at least one character even if no
56 characters could fit in the length given by \fImaxPixels\fR.  If
57 TK_AT_LEAST_ONE is set and TK_WHOLE_WORDS is also set, it means that if
58 not even one word fits on the line, return the first few letters of the
59 word that did fit; if not even one letter of the word fit, then the first
60 letter will still be returned.
61 .AP int *lengthPtr out
62 Filled with the number of pixels occupied by the number of characters
63 returned as the result of \fBTk_MeasureChars\fR.
64 .AP Display *display in
65 Display on which to draw.
66 .AP Drawable drawable in
67 Window or pixmap in which to draw.
68 .AP GC gc in
69 Graphics context for drawing characters.  The font selected into this GC 
70 must be the same as the \fItkfont\fR.
71 .AP int "x, y" in
72 Coordinates at which to place the left edge of the baseline when displaying
73 \fIstring\fR.  
74 .VS 8.1
75 .AP int firstByte in
76 The index of the first byte of the first character to underline in the
77 \fIstring\fR.  Underlining begins at the left edge of this character.
78 .AP int lastByte in
79 The index of the first byte of the last character up to which the
80 underline will be drawn.  The character specified by \fIlastByte\fR
81 will not itself be underlined.
82 .VE 8.1
83 .BE
84
85 .SH DESCRIPTION
86 .PP
87 These routines are for measuring and displaying simple single-font,
88 single-line, strings.  To measure and display single-font, multi-line,
89 justified text, refer to the documentation for \fBTk_ComputeTextLayout\fR.
90 There is no programming interface in the core of Tk that supports
91 multi-font, multi-line text; support for that behavior must be built on
92 top of simpler layers.  
93 .VS 8.1
94 Note that the interfaces described here are
95 byte-oriented not character-oriented, so index values coming from Tcl
96 scripts need to be converted to byte offsets using the
97 \fBTcl_UtfAtIndex\fR and related routines.
98 .VE 8.1
99 .PP
100 A glyph is the displayable picture of a letter, number, or some other
101 symbol.  Not all character codes in a given font have a glyph.
102 Characters such as tabs, newlines/returns, and control characters that
103 have no glyph are measured and displayed by these procedures in a
104 platform-dependent manner; under X, they are replaced with backslashed
105 escape sequences, while under Windows and Macintosh hollow or solid boxes
106 may be substituted.  Refer to the documentation for
107 \fBTk_ComputeTextLayout\fR for a programming interface that supports the
108 platform-independent expansion of tab characters into columns and
109 newlines/returns into multi-line text.  
110 .PP
111 \fBTk_MeasureChars\fR is used both to compute the length of a given
112 string and to compute how many characters from a string fit in a given
113 amount of space.  The return value is the number of bytes from
114 \fIstring\fR that fit in the space specified by \fImaxPixels\fR subject to
115 the conditions described by \fIflags\fR.  If all characters fit, the return
116 value will be \fInumBytes\fR.  \fI*lengthPtr\fR is filled with the computed
117 width, in pixels, of the portion of the string that was measured.  For
118 example, if the return value is 5, then \fI*lengthPtr\fR is filled with the
119 distance between the left edge of \fIstring\fR[0] and the right edge of
120 \fIstring\fR[4]. 
121 .PP
122 \fBTk_TextWidth\fR is a wrapper function that provides a simpler interface
123 to the \fBTk_MeasureChars\fR function.  The return value is how much
124 space in pixels the given \fIstring\fR needs.
125 .PP 
126 \fBTk_DrawChars\fR draws the \fIstring\fR at the given location in the
127 given \fIdrawable\fR.
128 .PP
129 \fBTk_UnderlineChars\fR underlines the given range of characters in the
130 given \fIstring\fR.  It doesn't draw the characters (which are assumed to
131 have been displayed previously by \fBTk_DrawChars\fR); it just draws the
132 underline.  This procedure is used to underline a few characters without
133 having to construct an underlined font.  To produce natively underlined
134 text, the appropriate underlined font should be constructed and used. 
135
136 .SH KEYWORDS
137 font