⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tkfont.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 5 页
字号:
    fontPtr->underlineHeight = fontPtr->fa.pointsize / 10;    if (fontPtr->underlineHeight == 0) {	fontPtr->underlineHeight = 1;    }    if (fontPtr->underlinePos + fontPtr->underlineHeight > descent) {	/*	 * If this set of values would cause the bottom of the underline	 * bar to stick below the descent of the font, jack the underline	 * up a bit higher.	 */	fontPtr->underlineHeight = descent - fontPtr->underlinePos;	if (fontPtr->underlineHeight == 0) {	    fontPtr->underlinePos--;	    fontPtr->underlineHeight = 1;	}    }        return (Tk_Font) fontPtr;}/* *--------------------------------------------------------------------------- * * Tk_NameOfFont -- * *	Given a font, return a textual string identifying it. * * Results: *	The return value is the description that was passed to *	Tk_GetFont() to create the font.  The storage for the returned *	string is only guaranteed to persist until the font is deleted. *	The caller should not modify this string. * * Side effects: *	None. * *--------------------------------------------------------------------------- */char *Tk_NameOfFont(tkfont)    Tk_Font tkfont;		/* Font whose name is desired. */{    TkFont *fontPtr;    Tcl_HashEntry *hPtr;    CachedFontKey *keyPtr;    fontPtr = (TkFont *) tkfont;    hPtr = fontPtr->cacheHashPtr;    keyPtr = (CachedFontKey *) Tcl_GetHashKey(hPtr->tablePtr, hPtr);    return (char *) keyPtr->string;    }/* *--------------------------------------------------------------------------- * * Tk_FreeFont --  * *	Called to release a font allocated by Tk_GetFont(). * * Results: *	None. * * Side effects: *	The reference count associated with font is decremented, and *	only deallocated when no one is using it. * *--------------------------------------------------------------------------- */voidTk_FreeFont(tkfont)    Tk_Font tkfont;		/* Font to be released. */{    TkFont *fontPtr;    NamedFont *nfPtr;    if (tkfont == NULL) {	return;    }    fontPtr = (TkFont *) tkfont;    fontPtr->refCount--;    if (fontPtr->refCount == 0) {	if (fontPtr->namedHashPtr != NULL) {	    /*	     * The font is being deleted.  Determine if the associated named	     * font definition should and/or can be deleted too.	     */	    nfPtr = (NamedFont *) Tcl_GetHashValue(fontPtr->namedHashPtr);	    nfPtr->refCount--;	    if ((nfPtr->refCount == 0) && (nfPtr->deletePending != 0)) {		Tcl_DeleteHashEntry(fontPtr->namedHashPtr);		ckfree((char *) nfPtr);	    }	}	Tcl_DeleteHashEntry(fontPtr->cacheHashPtr);	TkpDeleteFont(fontPtr);    }}/* *--------------------------------------------------------------------------- * * Tk_FontId -- * *	Given a font, return an opaque handle that should be selected *	into the XGCValues structure in order to get the constructed *	gc to use this font.  This procedure would go away if the *	XGCValues structure were replaced with a TkGCValues structure. * * Results: *	As above. * * Side effects: *	None. * *--------------------------------------------------------------------------- */FontTk_FontId(tkfont)    Tk_Font tkfont;	/* Font that is going to be selected into GC. */{    TkFont *fontPtr;    fontPtr = (TkFont *) tkfont;    return fontPtr->fid;}/* *--------------------------------------------------------------------------- * * Tk_GetFontMetrics -- * *	Returns overall ascent and descent metrics for the given font. *	These values can be used to space multiple lines of text and *	to align the baselines of text in different fonts. * * Results: *	If *heightPtr is non-NULL, it is filled with the overall height *	of the font, which is the sum of the ascent and descent. *	If *ascentPtr or *descentPtr is non-NULL, they are filled with *	the ascent and/or descent information for the font. * * Side effects: *	None. * *--------------------------------------------------------------------------- */voidTk_GetFontMetrics(tkfont, fmPtr)    Tk_Font tkfont;		/* Font in which metrics are calculated. */    Tk_FontMetrics *fmPtr;	/* Pointer to structure in which font				 * metrics for tkfont will be stored. */{    TkFont *fontPtr;    fontPtr = (TkFont *) tkfont;    fmPtr->ascent = fontPtr->fm.ascent;    fmPtr->descent = fontPtr->fm.descent;    fmPtr->linespace = fontPtr->fm.ascent + fontPtr->fm.descent;}/* *--------------------------------------------------------------------------- * * Tk_PostscriptFontName -- * *	Given a Tk_Font, return the name of the corresponding Postscript *	font. * * Results: *	The return value is the pointsize of the given Tk_Font. *	The name of the Postscript font is appended to dsPtr. * * Side effects: *	If the font does not exist on the printer, the print job will *	fail at print time.  Given a "reasonable" Postscript printer, *	the following Tk_Font font families should print correctly: * *	    Avant Garde, Arial, Bookman, Courier, Courier New, Geneva, *	    Helvetica, Monaco, New Century Schoolbook, New York, *	    Palatino, Symbol, Times, Times New Roman, Zapf Chancery, *	    and Zapf Dingbats. * *	Any other Tk_Font font families may not print correctly *	because the computed Postscript font name may be incorrect. * *--------------------------------------------------------------------------- */intTk_PostscriptFontName(tkfont, dsPtr)    Tk_Font tkfont;		/* Font in which text will be printed. */    Tcl_DString *dsPtr;		/* Pointer to an initialized Tcl_DString to				 * which the name of the Postscript font that				 * corresponds to tkfont will be appended. */{    TkFont *fontPtr;    char *family, *weightString, *slantString;    char *src, *dest;    int upper, len;    len = Tcl_DStringLength(dsPtr);    fontPtr = (TkFont *) tkfont;    /*     * Convert the case-insensitive Tk_Font family name to the     * case-sensitive Postscript family name.  Take out any spaces and     * capitalize the first letter of each word.     */    family = fontPtr->fa.family;    if (strncasecmp(family, "itc ", 4) == 0) {	family = family + 4;    }    if ((strcasecmp(family, "Arial") == 0)	    || (strcasecmp(family, "Geneva") == 0)) {	family = "Helvetica";    } else if ((strcasecmp(family, "Times New Roman") == 0)	    || (strcasecmp(family, "New York") == 0)) {	family = "Times";    } else if ((strcasecmp(family, "Courier New") == 0)	    || (strcasecmp(family, "Monaco") == 0)) {	family = "Courier";    } else if (strcasecmp(family, "AvantGarde") == 0) {	family = "AvantGarde";    } else if (strcasecmp(family, "ZapfChancery") == 0) {	family = "ZapfChancery";    } else if (strcasecmp(family, "ZapfDingbats") == 0) {	family = "ZapfDingbats";    } else {	/*	 * Inline, capitalize the first letter of each word, lowercase the	 * rest of the letters in each word, and then take out the spaces	 * between the words.  This may make the DString shorter, which is	 * safe to do.	 */	Tcl_DStringAppend(dsPtr, family, -1);	src = dest = Tcl_DStringValue(dsPtr) + len;	upper = 1;	for (; *src != '\0'; src++, dest++) {	    while (isspace(UCHAR(*src))) {		src++;		upper = 1;	    }	    *dest = *src;	    if ((upper != 0) && (islower(UCHAR(*src)))) {		*dest = toupper(UCHAR(*src));	    }	    upper = 0;	}	*dest = '\0';	Tcl_DStringSetLength(dsPtr, dest - Tcl_DStringValue(dsPtr));	family = Tcl_DStringValue(dsPtr) + len;    }    if (family != Tcl_DStringValue(dsPtr) + len) {	Tcl_DStringAppend(dsPtr, family, -1);	family = Tcl_DStringValue(dsPtr) + len;    }    if (strcasecmp(family, "NewCenturySchoolbook") == 0) {	Tcl_DStringSetLength(dsPtr, len);	Tcl_DStringAppend(dsPtr, "NewCenturySchlbk", -1);	family = Tcl_DStringValue(dsPtr) + len;    }    /*     * Get the string to use for the weight.     */    weightString = NULL;    if (fontPtr->fa.weight == TK_FW_NORMAL) {	if (strcmp(family, "Bookman") == 0) {	    weightString = "Light";	} else if (strcmp(family, "AvantGarde") == 0) {	    weightString = "Book";	} else if (strcmp(family, "ZapfChancery") == 0) {	    weightString = "Medium";	}    } else {	if ((strcmp(family, "Bookman") == 0)		|| (strcmp(family, "AvantGarde") == 0)) {	    weightString = "Demi";	} else {	    weightString = "Bold";	}    }    /*     * Get the string to use for the slant.     */    slantString = NULL;    if (fontPtr->fa.slant == TK_FS_ROMAN) {	;    } else {	if ((strcmp(family, "Helvetica") == 0)		|| (strcmp(family, "Courier") == 0)		|| (strcmp(family, "AvantGarde") == 0)) {	    slantString = "Oblique";	} else {	    slantString = "Italic";	}    }    /*     * The string "Roman" needs to be added to some fonts that are not bold     * and not italic.     */    if ((slantString == NULL) && (weightString == NULL)) {	if ((strcmp(family, "Times") == 0) 		|| (strcmp(family, "NewCenturySchlbk") == 0)		|| (strcmp(family, "Palatino") == 0)) {	    Tcl_DStringAppend(dsPtr, "-Roman", -1);	}    } else {	Tcl_DStringAppend(dsPtr, "-", -1);	if (weightString != NULL) {	    Tcl_DStringAppend(dsPtr, weightString, -1);	}	if (slantString != NULL) {	    Tcl_DStringAppend(dsPtr, slantString, -1);	}    }    return fontPtr->fa.pointsize;}/* *--------------------------------------------------------------------------- * * Tk_TextWidth -- * *	A wrapper function for the more complicated interface of *	Tk_MeasureChars.  Computes how much space the given *	simple string needs. * * Results: *	The return value is the width (in pixels) of the given string. * * Side effects: *	None. * *--------------------------------------------------------------------------- */intTk_TextWidth(tkfont, string, numChars)    Tk_Font tkfont;		/* Font in which text will be measured. */    CONST char *string;		/* String whose width will be computed. */    int numChars;		/* Number of characters to consider from				 * string, or < 0 for strlen(). */{    int width;    if (numChars < 0) {	numChars = strlen(string);    }    Tk_MeasureChars(tkfont, string, numChars, 0, 0, &width);    return width;}/* *--------------------------------------------------------------------------- * * Tk_UnderlineChars -- * *	This procedure draws an underline for a given range of characters *	in a given string.  It doesn't draw the characters (which are *	assumed to have been displayed previously); it just draws the *	underline.  This procedure would mainly be used to quickly *	underline a few characters without having to construct an *	underlined font.  To produce properly underlined text, the *	appropriate underlined font should be constructed and used.  * * Results: *	None. * * Side effects: *	Information gets displayed in "drawable". * *---------------------------------------------------------------------- */voidTk_UnderlineChars(display, drawable, gc, tkfont, string, x, y, firstChar,	lastChar)    Display *display;		/* Display on which to draw. */    Drawable drawable;		/* Window or pixmap in which to draw. */    GC gc;			/* Graphics context for actually drawing				 * line. */    Tk_Font tkfont;		/* Font used in GC;  must have been allocated				 * by Tk_GetFont().  Used for character				 * dimensions, etc. */    CONST char *string;		/* String containing characters to be				 * underlined or overstruck. */    int x, y;			/* Coordinates at which first character of				 * string is drawn. */    int firstChar;		/* Index of first character. */    int lastChar;		/* Index of one after the last character. */{    TkFont *fontPtr;    int startX, endX;    fontPtr = (TkFont *) tkfont;        Tk_MeasureChars(tkfont, string, firstChar, 0, 0, &startX);    Tk_MeasureChars(tkfont, string, lastChar, 0, 0, &endX);    XFillRectangle(display, drawable, gc, x + startX,	    y + fontPtr->underlinePos, (unsigned int) (endX - startX),	    (unsigned int) fontPtr->underlineHeight);}/* *--------------------------------------------------------------------------- * * Tk_ComputeTextLayout -- * *	Computes the amount of screen space needed to display a *	multi-line, justified string of text.  Records all the *	measurements that were done to determine to size and *	positioning of the individual lines of text; this information *	can be used by the Tk_DrawTextLayout() procedure to *	display the text quickly (without remeasuring it). * *	This procedure is useful for simple widgets that want to *	display single-font, multi-line text and want Tk to handle the *	details. * * Results: *	The return value is a Tk_TextLayout token that holds the *	measurement information for the given string.  The token is *	only valid for the given string.  If the string is freed, *	the token is no longer valid and must also be freed.  To free *	the token, call Tk_FreeTextLayout(). * *	The dimensions of the screen area needed to display the text *	are stored in *widthPtr and *heightPtr. * * Side effects: *	Memory is allocated to hold the measurement information.   * *--------------------------------------------------------------------------- */Tk_TextLayoutTk_ComputeTextLayout(tkfont, string, numChars, wrapLength, justify, flags,	widthPtr, heightPtr)    Tk_Font tkfont;		/* Font that will be used to display text. */    CONST char *string;		/* String whose dimensions are to be				 * computed. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -