Tk_MeasureChars (3)
routines to measure and display simple single-line strings.
SYNOPSIS
#include <tk.h>
int
Tk_MeasureChars(tkfont, string, maxChars, maxPixels, flags, lengthPtr)
int
Tk_TextWidth(tkfont, string, numChars)
void
Tk_DrawChars(display, drawable, gc, tkfont, string, numChars, x, y)
void
Tk_UnderlineChars(display, drawable, gc, tkfont, string, x, y, firstChar, lastChar)
ARGUMENTS
"const char" firstChar
Tk_Font tkfont in
Token for font in which text is to be drawn or measured. Must have been
returned by a previous call to Tk_GetFont.
"const char" *string in
Text to be measured or displayed. Need not be null terminated. Any
non-printing meta-characters in the string (such as tabs, newlines, and
other control characters) will be measured or displayed in a
platform-dependent manner.
int maxChars in
The maximum number of characters to consider when measuring string.
Must be greater than or equal to 0.
int maxPixels in
If maxPixels is greater than 0, it specifies the longest permissible
line length in pixels. Characters from string are processed only
until this many pixels have been covered. If maxPixels is <= 0, then
the line length is unbounded and the flags argument is ignored.
int flags in
Various flag bits OR-ed together: TK_PARTIAL_OK means include a character
as long as any part of it fits in the length given by maxPixels;
otherwise, a character must fit completely to be considered.
TK_WHOLE_WORDS means stop on a word boundary, if possible. If
TK_AT_LEAST_ONE is set, it means return at least one character even if no
characters could fit in the length given by maxPixels. If
TK_AT_LEAST_ONE is set and TK_WHOLE_WORDS is also set, it means that if
not even one word fits on the line, return the first few letters of the
word that did fit; if not even one letter of the word fit, then the first
letter will still be returned.
int *lengthPtr out
Filled with the number of pixels occupied by the number of characters
returned as the result of Tk_MeasureChars.
int numChars in
The total number of characters to measure or draw from string. Must
be greater than or equal to 0.
Display *display in
Display on which to draw.
Drawable drawable in
Window or pixmap in which to draw.
GC gc in
Graphics context for drawing characters. The font selected into this GC
must be the same as the tkfont.
int "x, y" in
Coordinates at which to place the left edge of the baseline when displaying
string.
int firstChar in
The index of the first character to underline in the string.
Underlining begins at the left edge of this character.
int lastChar in
The index of the last character up to which the underline will
be drawn. The character specified by lastChar will not itself be
underlined.
DESCRIPTION
These routines are for measuring and displaying simple single-font,
single-line, strings. To measure and display single-font, multi-line,
justified text, refer to the documentation for Tk_ComputeTextLayout.
There is no programming interface in the core of Tk that supports
multi-font, multi-line text; support for that behavior must be built on
top of simpler layers.
A glyph is the displayable picture of a letter, number, or some other
symbol. Not all character codes in a given font have a glyph.
Characters such as tabs, newlines/returns, and control characters that
have no glyph are measured and displayed by these procedures in a
platform-dependent manner; under X, they are replaced with backslashed
escape sequences, while under Windows and Macintosh hollow or solid boxes
may be substituted. Refer to the documentation for
Tk_ComputeTextLayout for a programming interface that supports the
platform-independent expansion of tab characters into columns and
newlines/returns into multi-line text.
Tk_MeasureChars is used both to compute the length of a given
string and to compute how many characters from a string fit in a given
amount of space. The return value is the number of characters from
string that fit in the space specified by maxPixels subject to
the conditions described by flags. If all characters fit, the return
value will be maxChars. *lengthPtr is filled with the computed
width, in pixels, of the portion of the string that was measured. For
example, if the return value is 5, then *lengthPtr is filled with the
distance between the left edge of string[0] and the right edge of
string[4].
Tk_TextWidth is a wrapper function that provides a simpler interface
to the Tk_MeasureChars function. The return value is how much
space in pixels the given string needs.
Tk_DrawChars draws the string at the given location in the
given drawable.
Tk_UnderlineChars underlines the given range of characters in the
given string. It doesn't draw the characters (which are assumed to
have been displayed previously by Tk_DrawChars); it just draws the
underline. This procedure is used to underline a few characters without
having to construct an underlined font. To produce natively underlined
text, the appropriate underlined font should be constructed and used.
KEYWORDS
font
'\"
'\" Copyright (c) 1996 Sun Microsystems, Inc.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
'\" RCS: @(#) $Id: TextLayout.3,v 1.2 1998/09/14 18:22:54 stanton Exp $
'\"
'\" The definitions below are for supplemental macros used in Tcl/Tk
'\" manual entries.
'\"
'\" .AP type name in/out ?indent?
'\" Start paragraph describing an argument to a library procedure.
'\" type is type of argument (int, etc.), in/out is either "in", "out",
'\" or "in/out" to describe whether procedure reads or modifies arg,
'\" and indent is equivalent to second arg of .IP (shouldn't ever be
'\" needed; use .AS below instead)
'\"
'\" .AS ?type? ?name?
'\" Give maximum sizes of arguments for setting tab stops. Type and
'\" name are examples of largest possible arguments that will be passed
'\" to .AP later. If args are omitted, default tab stops are used.
'\"
'\" .BS
'\" Start box enclosure. From here until next .BE, everything will be
'\" enclosed in one large box.
'\"
'\" .BE
'\" End of box enclosure.
'\"
'\" .CS
'\" Begin code excerpt.
'\"
'\" .CE
'\" End code excerpt.
'\"
'\" .VS ?version? ?br?
'\" Begin vertical sidebar, for use in marking newly-changed parts
'\" of man pages. The first argument is ignored and used for recording
'\" the version when the .VS was added, so that the sidebars can be
'\" found and removed when they reach a certain age. If another argument
'\" is present, then a line break is forced before starting the sidebar.
'\"
'\" .VE
'\" End of vertical sidebar.
'\"
'\" .DS
'\" Begin an indented unfilled display.
'\"
'\" .DE
'\" End of indented unfilled display.
'\"
'\" .SO
'\" Start of list of standard options for a Tk widget. The
'\" options follow on successive lines, in four columns separated
'\" by tabs.
'\"
'\" .SE
'\" End of list of standard options for a Tk widget.
'\"
'\" .OP cmdName dbName dbClass
'\" Start of description of a specific option. cmdName gives the
'\" option's name as specified in the class command, dbName gives
'\" the option's name in the option database, and dbClass gives
'\" the option's class in the option database.
'\"
'\" .UL arg1 arg2
'\" Print arg1 underlined, then print arg2 normally.
'\"
'\" RCS: @(#) $Id: man.macros,v 1.2 1998/09/14 18:39:54 stanton Exp $
'\"
'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
t .wh -1.3i ^B
^l \n(.l
b
'\" # Start an argument description
AP
!"\\$4"" .TP \\$4
\{\
!"\\$2"" .TP \\n()Cu
.TP 15
|