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

📄 tkmacfont.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * tkMacFont.c -- * *	Contains the Macintosh implementation of the platform-independant *	font package interface. * * Copyright (c) 1990-1994 The Regents of the University of California. * Copyright (c) 1994-1997 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:@(#) tkMacFont.c 1.52 97/11/20 18:29:51  */ #include <Windows.h>#include <Strings.h>#include <Fonts.h>#include <Resources.h>#include "tkMacInt.h"#include "tkFont.h"#include "tkPort.h"/* * The following structure represents the Macintosh's' implementation of a * font. */typedef struct MacFont {    TkFont font;		/* Stuff used by generic font package.  Must				 * be first in structure. */    short family;    short size;    short style;} MacFont;static GWorldPtr gWorld = NULL;static TkFont *		AllocMacFont _ANSI_ARGS_((TkFont *tkfont, 			    Tk_Window tkwin, int family, int size, int style));/* *--------------------------------------------------------------------------- * * TkpGetNativeFont -- * *	Map a platform-specific native font name to a TkFont. * * Results: * 	The return value is a pointer to a TkFont that represents the *	native font.  If a native font by the given name could not be *	found, the return value is NULL.   * *	Every call to this procedure returns a new TkFont structure, *	even if the name has already been seen before.  The caller should *	call TkpDeleteFont() when the font is no longer needed. * *	The caller is responsible for initializing the memory associated *	with the generic TkFont when this function returns and releasing *	the contents of the generics TkFont before calling TkpDeleteFont(). * * Side effects: *	None. * *--------------------------------------------------------------------------- */TkFont *TkpGetNativeFont(    Tk_Window tkwin,	/* For display where font will be used. */    CONST char *name)	/* Platform-specific font name. */{    short family;        if (strcmp(name, "system") == 0) {	family = GetSysFont();    } else if (strcmp(name, "application") == 0) {	family = GetAppFont();    } else {	return NULL;    }    return AllocMacFont(NULL, tkwin, family, 0, 0);}/* *--------------------------------------------------------------------------- * * TkpGetFontFromAttributes --  * *	Given a desired set of attributes for a font, find a font with *	the closest matching attributes. * * Results: * 	The return value is a pointer to a TkFont that represents the *	font with the desired attributes.  If a font with the desired *	attributes could not be constructed, some other font will be *	substituted automatically. * *	Every call to this procedure returns a new TkFont structure, *	even if the specified attributes have already been seen before. *	The caller should call TkpDeleteFont() to free the platform- *	specific data when the font is no longer needed.   * *	The caller is responsible for initializing the memory associated *	with the generic TkFont when this function returns and releasing *	the contents of the generic TkFont before calling TkpDeleteFont(). * * Side effects: *	None. * *--------------------------------------------------------------------------- */TkFont *TkpGetFontFromAttributes(    TkFont *tkFontPtr,		/* If non-NULL, store the information in				 * this existing TkFont structure, rather than				 * allocating a new structure to hold the				 * font; the existing contents of the font				 * will be released.  If NULL, a new TkFont				 * structure is allocated. */    Tk_Window tkwin,		/* For display where font will be used. */    CONST TkFontAttributes *faPtr)  /* Set of attributes to match. */{    char buf[257];    size_t len;    short family, size, style;    if (faPtr->family == NULL) {	family = 0;    } else {	CONST char *familyName;	familyName = faPtr->family;	if (strcasecmp(familyName, "Times New Roman") == 0) {	    familyName = "Times";	} else if (strcasecmp(familyName, "Courier New") == 0) {	    familyName = "Courier";	} else if (strcasecmp(familyName, "Arial") == 0) {	    familyName = "Helvetica";	}	    	len = strlen(familyName);	if (len > 255) {	    len = 255;	}	buf[0] = (char) len;	memcpy(buf + 1, familyName, len);	buf[len + 1] = '\0';	GetFNum((StringPtr) buf, &family);    }    size = faPtr->pointsize;    if (size <= 0) {	size = GetDefFontSize();    }    style = 0;    if (faPtr->weight != TK_FW_NORMAL) {	style |= bold;    }    if (faPtr->slant != TK_FS_ROMAN) {	style |= italic;    }    if (faPtr->underline) {	style |= underline;    }    return AllocMacFont(tkFontPtr, tkwin, family, size, style);}/* *--------------------------------------------------------------------------- * * TkpDeleteFont -- * *	Called to release a font allocated by TkpGetNativeFont() or *	TkpGetFontFromAttributes().  The caller should have already *	released the fields of the TkFont that are used exclusively by *	the generic TkFont code. * * Results: *	None. * * Side effects: *	TkFont is deallocated. * *--------------------------------------------------------------------------- */voidTkpDeleteFont(    TkFont *tkFontPtr)		/* Token of font to be deleted. */{    ckfree((char *) tkFontPtr);}/* *--------------------------------------------------------------------------- * * TkpGetFontFamilies -- * *	Return information about the font families that are available *	on the display of the given window. * * Results: *	interp->result is modified to hold a list of all the available *	font families. * * Side effects: *	None. * *--------------------------------------------------------------------------- */ voidTkpGetFontFamilies(    Tcl_Interp *interp,		/* Interp to hold result. */    Tk_Window tkwin)		/* For display to query. */{        MenuHandle fontMenu;    int i;    char itemText[257];        fontMenu = NewMenu(1, "\px");    AddResMenu(fontMenu, 'FONT');        for (i = 1; i < CountMItems(fontMenu); i++) {    	/*    	 * Each item is a pascal string. Convert it to C and append.    	 */    	GetMenuItemText(fontMenu, i, (unsigned char *) itemText);    	itemText[itemText[0] + 1] = '\0';    	Tcl_AppendElement(interp, &itemText[1]);    }    DisposeMenu(fontMenu);}/* *--------------------------------------------------------------------------- * * TkMacIsCharacterMissing -- * *	Given a tkFont and a character determines whether the character has *	a glyph defined in the font or not. Note that this is potentially *	not compatible with Mac OS 8 as it looks at the font handle *	structure directly. Looks into the character array of the font *	handle to determine whether the glyph is defined or not. * * Results: *	Returns a 1 if the character is missing, a 0 if it is not. * * Side effects: *	None. * *--------------------------------------------------------------------------- */intTkMacIsCharacterMissing(    Tk_Font tkfont,		/* The font we are looking in. */    unsigned int searchChar)	/* The character we are looking for. */{    MacFont *fontPtr = (MacFont *) tkfont;    FMInput fm;    FontRec **fontRecHandle;        fm.family = fontPtr->family;    fm.size = fontPtr->size;    fm.face = fontPtr->style;    fm.needBits = 0;    fm.device = 0;    fm.numer.h = fm.numer.v = fm.denom.h = fm.denom.v = 1;    /*     * This element of the FMOutput structure was changed between the 2.0 & 3.0     * versions of the Universal Headers.     */        #if !defined(UNIVERSAL_INTERFACES_VERSION) || (UNIVERSAL_INTERFACES_VERSION < 0x0300)    fontRecHandle = (FontRec **) FMSwapFont(&fm)->fontResult;#else    fontRecHandle = (FontRec **) FMSwapFont(&fm)->fontHandle;#endif    return *(short *) ((long) &(*fontRecHandle)->owTLoc     	    + ((long)((*fontRecHandle)->owTLoc + searchChar     	    - (*fontRecHandle)->firstChar) * sizeof(short))) == -1;}/* *--------------------------------------------------------------------------- * *  Tk_MeasureChars -- * *	Determine the number of characters from the string that will fit *	in the given horizontal span.  The measurement is done under the *	assumption that Tk_DrawChars() will be used to actually display *	the characters. * * Results: *	The return value is the number of characters from source that *	fit into the span that extends from 0 to maxLength.  *lengthPtr is *	filled with the x-coordinate of the right edge of the last *	character that did fit. * * Side effects: *	None. * *--------------------------------------------------------------------------- */intTk_MeasureChars(    Tk_Font tkfont,		/* Font in which characters will be drawn. */    CONST char *source,		/* Characters to be displayed.  Need not be				 * '\0' terminated. */    int numChars,		/* Maximum number of characters to consider				 * from source string. */    int maxLength,		/* If > 0, maxLength specifies the longest				 * permissible line length; don't consider any				 * character that would cross this				 * x-position.  If <= 0, then line length is				 * unbounded and the flags argument is				 * ignored. */    int flags,			/* Various flag bits OR-ed together:				 * TK_PARTIAL_OK means include the last char				 * which only partially fit on this line.				 * TK_WHOLE_WORDS means stop on a word				 * boundary, if possible.				 * TK_AT_LEAST_ONE means return at least one				 * character even if no characters fit. */    int *lengthPtr)		/* Filled with x-location just after the				 * terminating character. */{    short staticWidths[128];    short *widths;

⌨️ 快捷键说明

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