📄 measurechar.3
字号:
'\"'\" 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.'\" '\" SCCS: @(#) MeasureChar.3 1.5 97/06/10 17:33:36'\" .so man.macros.TH Tk_MeasureChars 3 "" Tk "Tk Library Procedures".BS.SH NAMETk_MeasureChars, Tk_TextWidth, Tk_DrawChars, Tk_UnderlineChars \- routines to measure and display simple single-line strings..SH SYNOPSIS.nf\fB#include <tk.h>\fR.spint\fBTk_MeasureChars(\fItkfont, string, maxChars, maxPixels, flags, lengthPtr\fB)\fR.spint\fBTk_TextWidth(\fItkfont, string, numChars\fB)\fR.spvoid\fBTk_DrawChars(\fIdisplay, drawable, gc, tkfont, string, numChars, x, y\fB)\fR.spvoid\fBTk_UnderlineChars(\fIdisplay, drawable, gc, tkfont, string, x, y, firstChar, lastChar\fB)\fR.sp.SH ARGUMENTS.AS "const char" firstChar.AP Tk_Font tkfont inToken for font in which text is to be drawn or measured. Must have beenreturned by a previous call to \fBTk_GetFont\fR..AP "const char" *string inText to be measured or displayed. Need not be null terminated. Anynon-printing meta-characters in the string (such as tabs, newlines, andother control characters) will be measured or displayed in aplatform-dependent manner. .AP int maxChars inThe maximum number of characters to consider when measuring \fIstring\fR.Must be greater than or equal to 0..AP int maxPixels inIf \fImaxPixels\fR is greater than 0, it specifies the longest permissibleline length in pixels. Characters from \fIstring\fR are processed onlyuntil this many pixels have been covered. If \fImaxPixels\fR is <= 0, thenthe line length is unbounded and the \fIflags\fR argument is ignored..AP int flags inVarious flag bits OR-ed together: TK_PARTIAL_OK means include a characteras long as any part of it fits in the length given by \fImaxPixels\fR;otherwise, a character must fit completely to be considered.TK_WHOLE_WORDS means stop on a word boundary, if possible. IfTK_AT_LEAST_ONE is set, it means return at least one character even if nocharacters could fit in the length given by \fImaxPixels\fR. IfTK_AT_LEAST_ONE is set and TK_WHOLE_WORDS is also set, it means that ifnot even one word fits on the line, return the first few letters of theword that did fit; if not even one letter of the word fit, then the firstletter will still be returned..AP int *lengthPtr outFilled with the number of pixels occupied by the number of charactersreturned as the result of \fBTk_MeasureChars\fR..AP int numChars inThe total number of characters to measure or draw from \fIstring\fR. Mustbe greater than or equal to 0..AP Display *display inDisplay on which to draw..AP Drawable drawable inWindow or pixmap in which to draw..AP GC gc inGraphics context for drawing characters. The font selected into this GC must be the same as the \fItkfont\fR..AP int "x, y" inCoordinates at which to place the left edge of the baseline when displaying\fIstring\fR. .AP int firstChar inThe index of the first character to underline in the \fIstring\fR. Underlining begins at the left edge of this character..AP int lastChar inThe index of the last character up to which the underline will be drawn. The character specified by \fIlastChar\fR will not itself beunderlined..BE.SH DESCRIPTION.PPThese 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 \fBTk_ComputeTextLayout\fR.There is no programming interface in the core of Tk that supportsmulti-font, multi-line text; support for that behavior must be built ontop of simpler layers..PPA glyph is the displayable picture of a letter, number, or some othersymbol. Not all character codes in a given font have a glyph.Characters such as tabs, newlines/returns, and control characters thathave no glyph are measured and displayed by these procedures in aplatform-dependent manner; under X, they are replaced with backslashedescape sequences, while under Windows and Macintosh hollow or solid boxesmay be substituted. Refer to the documentation for\fBTk_ComputeTextLayout\fR for a programming interface that supports theplatform-independent expansion of tab characters into columns andnewlines/returns into multi-line text. .PP\fBTk_MeasureChars\fR is used both to compute the length of a givenstring and to compute how many characters from a string fit in a givenamount of space. The return value is the number of characters from\fIstring\fR that fit in the space specified by \fImaxPixels\fR subject tothe conditions described by \fIflags\fR. If all characters fit, the returnvalue will be \fImaxChars\fR. \fI*lengthPtr\fR is filled with the computedwidth, in pixels, of the portion of the string that was measured. Forexample, if the return value is 5, then \fI*lengthPtr\fR is filled with thedistance between the left edge of \fIstring\fR[0] and the right edge of\fIstring\fR[4]. .PP\fBTk_TextWidth\fR is a wrapper function that provides a simpler interfaceto the \fBTk_MeasureChars\fR function. The return value is how muchspace in pixels the given \fIstring\fR needs..PP \fBTk_DrawChars\fR draws the \fIstring\fR at the given location in thegiven \fIdrawable\fR..PP\fBTk_UnderlineChars\fR underlines the given range of characters in thegiven \fIstring\fR. It doesn't draw the characters (which are assumed tohave been displayed previously by \fBTk_DrawChars\fR); it just draws theunderline. This procedure is used to underline a few characters withouthaving to construct an underlined font. To produce natively underlinedtext, the appropriate underlined font should be constructed and used. .SH KEYWORDSfont
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -