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

📄 tkwinfont.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * tkWinFont.c -- * *	Contains the Windows implementation of the platform-independant *	font package interface. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright (c) 1994 Software Research Associates, Inc.  * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * * SCCS: @(#) tkWinFont.c 1.20 97/05/14 15:45:30 */#include "tkWinInt.h"#include "tkFont.h"/* * The following structure represents Windows' implementation of a font. */typedef struct WinFont {    TkFont font;		/* Stuff used by generic font package.  Must				 * be first in structure. */    HFONT hFont;		/* Windows information about font. */    HWND hwnd;			/* Toplevel window of application that owns				 * this font, used for getting HDC. */} WinFont;/* * The following structure is used as to map between the Tcl strings * that represent the system fonts and the numbers used by Windows. */static TkStateMap systemMap[] = {    {ANSI_FIXED_FONT,	    "ansifixed"},    {ANSI_VAR_FONT,	    "ansi"},    {DEVICE_DEFAULT_FONT,   "device"},    {OEM_FIXED_FONT,	    "oemfixed"},    {SYSTEM_FIXED_FONT,	    "systemfixed"},    {SYSTEM_FONT,	    "system"},    {-1,		    NULL}};#define ABS(x)          (((x) < 0) ? -(x) : (x))static TkFont *		AllocFont _ANSI_ARGS_((TkFont *tkFontPtr,                             Tk_Window tkwin, HFONT hFont));static char *		GetProperty _ANSI_ARGS_((CONST TkFontAttributes *faPtr,			    CONST char *option));static int CALLBACK	WinFontFamilyEnumProc _ANSI_ARGS_((ENUMLOGFONT *elfPtr,			    NEWTEXTMETRIC *ntmPtr, int fontType,			    LPARAM lParam));/* *--------------------------------------------------------------------------- * * 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 generic TkFont before calling TkpDeleteFont(). * * Side effects: *	None. * *--------------------------------------------------------------------------- */TkFont *TkpGetNativeFont(tkwin, name)    Tk_Window tkwin;		/* For display where font will be used. */    CONST char *name;		/* Platform-specific font name. */{    int object;    HFONT hFont;        object = TkFindStateNum(NULL, NULL, systemMap, name);    if (object < 0) {	return NULL;    }    hFont = CkGetStockObject(object);    if (hFont == NULL) {	panic("TkpGetNativeFont: can't allocate stock font");    }    return AllocFont(NULL, tkwin, hFont);}/* *--------------------------------------------------------------------------- * * 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.  NULL is never returned. * *	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(tkFontPtr, tkwin, faPtr)    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. */{    LOGFONT lf;    HFONT hFont;    int result=0;    //not necessary , leo    //Window window;    //HWND hwnd;    //HDC hdc;    //window = Tk_WindowId(((TkWindow *) tkwin)->mainPtr->winPtr);    //hwnd = (window == None) ? NULL : TkWinGetHWND(window);    //hdc = CkGetDC(hwnd);    lf.lfHeight		= -faPtr->pointsize;    if (lf.lfHeight < 0) {	lf.lfHeight = MulDiv(lf.lfHeight, 	        254 * WidthOfScreen(Tk_Screen(tkwin)),		720 * WidthMMOfScreen(Tk_Screen(tkwin)));    }    lf.lfWidth		= 0;    lf.lfEscapement	= 0;    lf.lfOrientation	= 0;    lf.lfWeight		= (faPtr->weight == TK_FW_NORMAL) ? FW_NORMAL : FW_BOLD;    lf.lfItalic		= faPtr->slant;    lf.lfUnderline	= faPtr->underline;    lf.lfStrikeOut	= faPtr->overstrike;	/* try and match font with character set - KH */	result=strlen(faPtr->family);    if (strcmp(faPtr->family+result-3, "Cyr")==0) {        lf.lfCharSet	= RUSSIAN_CHARSET;    } else if (strcmp(faPtr->family+result-2, "CE")==0) {        lf.lfCharSet	= EASTEUROPE_CHARSET;    	} else if (strcmp(faPtr->family+result-6, "Baltic")==0) {        lf.lfCharSet	= BALTIC_CHARSET;    	} else if (strcmp(faPtr->family+result-3, "Tur")==0) {        lf.lfCharSet	= TURKISH_CHARSET;    	} else if (strcmp(faPtr->family+result-5, "Greek")==0) {        lf.lfCharSet	= GREEK_CHARSET;    	} else {        lf.lfCharSet	= DEFAULT_CHARSET;    	}    lf.lfOutPrecision	= OUT_DEFAULT_PRECIS;    lf.lfClipPrecision	= CLIP_DEFAULT_PRECIS;    lf.lfQuality	= DEFAULT_QUALITY;    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;    if (faPtr->family == NULL) {	lf.lfFaceName[0] = '\0';    } else {	lstrcpyn(lf.lfFaceName, faPtr->family, sizeof(lf.lfFaceName));    }    //CkReleaseDC(hwnd, hdc);    /*     * Replace the standard X and Mac family names with the names that     * Windows likes.     */    if ((stricmp(lf.lfFaceName, "Times") == 0)	    || (stricmp(lf.lfFaceName, "New York") == 0)) {	strcpy(lf.lfFaceName, "Times New Roman");    } else if ((stricmp(lf.lfFaceName, "Courier") == 0)	    || (stricmp(lf.lfFaceName, "Monaco") == 0)) {	strcpy(lf.lfFaceName, "Courier New");    } else if ((stricmp(lf.lfFaceName, "Helvetica") == 0)	    || (stricmp(lf.lfFaceName, "Geneva") == 0)) {	strcpy(lf.lfFaceName, "Arial");    }    hFont = CkCreateFontIndirect(&lf);    if (hFont == NULL) {        hFont = CkGetStockObject(SYSTEM_FONT);	if (hFont == NULL) {	    panic("TkpGetFontFromAttributes: cannot get system font");	}    }    return AllocFont(tkFontPtr, tkwin, hFont);}/* *--------------------------------------------------------------------------- * * 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(tkFontPtr)    TkFont *tkFontPtr;		/* Token of font to be deleted. */{    WinFont *fontPtr;    fontPtr = (WinFont *) tkFontPtr;    CkDeleteFont(fontPtr->hFont);    ckfree((char *) fontPtr);}/* *--------------------------------------------------------------------------- * * TkpGetFontFamilies, WinFontEnumFamilyProc -- * *	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(interp, tkwin)    Tcl_Interp *interp;		/* Interp to hold result. */    Tk_Window tkwin;		/* For display to query. */{        Window window;    HWND hwnd;    HDC hdc;    window = Tk_WindowId(tkwin);    hwnd = (window == (Window) NULL) ? NULL : TkWinGetHWND(window);    hdc = CkGetDC(hwnd);    EnumFontFamilies(hdc, NULL, (FONTENUMPROC) WinFontFamilyEnumProc,	    (LPARAM) interp);    CkReleaseDC(hwnd, hdc);}/* ARGSUSED */static int CALLBACKWinFontFamilyEnumProc(elfPtr, ntmPtr, fontType, lParam)    ENUMLOGFONT *elfPtr;	/* Logical-font data. */    NEWTEXTMETRIC *ntmPtr;	/* Physical-font data (not used). */    int fontType;		/* Type of font (not used). */    LPARAM lParam;		/* Interp to hold result. */{    Tcl_Interp *interp;    interp = (Tcl_Interp *) lParam;    Tcl_AppendElement(interp, elfPtr->elfLogFont.lfFaceName);    return 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(tkfont, source, numChars, maxLength, flags, lengthPtr)    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. */

⌨️ 快捷键说明

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