64 #include <X11/cursorfont.h> 71 #define FONT_DUMP_DEBUG_LEVEL DebugLevel_Heavy 76 static int bDisableAntiAlias = 0;
77 static int bEnableTrueTypeFonts = 0;
80 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 81 FT_Library __ftlib = NULL;
82 static int bInitFtLibOnce = 0;
83 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 86 void __internal_disable_antialias(
void)
88 bDisableAntiAlias = 1;
91 void __internal_enable_antialias(
void)
93 bDisableAntiAlias = 0;
98 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 105 #if XFT_VERSION < 20000 106 #warning - You need libXft version 2 or greater - true type fonts disabled 108 bEnableTrueTypeFonts = 0;
114 if(XftInit(0) == FcTrue && XftInitFtLibrary() == FcTrue )
120 bEnableTrueTypeFonts = 1;
128 if(FT_Init_FreeType(&__ftlib))
131 WB_WARN_PRINT(
"Unable to get own copy of FreeType library, disabled\n");
136 WB_ERROR_PRINT(
"Unable to initialize libXft - truetype fonts not enabled\n");
139 #endif // XFT_VERSION < 20000 140 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 147 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 154 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 159 return !bDisableAntiAlias;
164 bDisableAntiAlias = bEnable ? 1 : 0;
183 WB_WARN_PRINT(
"%s returns NULL (WBGetDefaultFont returns NULL)\n", __FUNCTION__);
192 memset(pRval, 0,
sizeof(*pRval));
197 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 198 if(pOldFont->pxftFont)
200 pRval->pxftFont = XftFontCopy(pDisplay, pOldFont->pxftFont);
208 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 210 if(pOldFont->
fsFont != None)
216 WB_WARN_PRINT(
"%s returns NULL (unable to copy font set)\n", __FUNCTION__);
226 WB_WARN_PRINT(
"%s returns NULL (unable to copy font struct)\n", __FUNCTION__);
244 WB_WARN_PRINT(
"%s returns NULL (no memory for structure)\n", __FUNCTION__);
259 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 262 XftFontClose(pDisplay, pFont->pxftFont);
263 pFont->pxftFont = NULL;
265 if(pFont->pxftFontInfo != None)
267 XftFontInfoDestroy(pDisplay, pFont->pxftFontInfo);
268 pFont->pxftFontInfo = NULL;
270 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 274 XFreeFontSet(pDisplay, pFont->
fsFont);
292 int iFontSize,
int iFlags)
304 memset(pRval, 0,
sizeof(*pRval));
309 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 311 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 314 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 323 WB_WARN_PRINT(
"%s returns NULL (WBLoadFontXl returns NULL)\n", __FUNCTION__);
337 WB_WARN_PRINT(
"%s returns NULL (no memory for structure)\n", __FUNCTION__);
353 __FUNCTION__, pFont, (
void *)(pFont ? pFont->
pDisplay : NULL));
363 "%s returns (cached) font avg char width %d\n", __FUNCTION__, pFont->
iAvgCharWidth);
367 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 370 WB_ERROR_PRINT(
"ERROR: %s font has 'pfxftFont' non-NULL\n", __FUNCTION__);
371 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 374 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 389 "%s returns font avg char width %d\n", __FUNCTION__, iRval);
404 __FUNCTION__, pFont, (
void *)(pFont ? pFont->
pDisplay : NULL));
414 "%s returns (cached) font max char width %d\n", __FUNCTION__, pFont->
iMaxCharWidth);
418 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 421 WB_ERROR_PRINT(
"ERROR: %s font has 'pfxftFont' non-NULL\n", __FUNCTION__);
422 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 425 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 438 "%s returns font max char width %d\n", __FUNCTION__, iRval);
453 __FUNCTION__, pFont, (
void *)(pFont ? pFont->
pDisplay : NULL));
463 "%s returns (cached) font descent %d\n", __FUNCTION__, pFont->
iDescent);
468 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 471 WB_ERROR_PRINT(
"ERROR: %s font has 'pfxftFont' non-NULL\n", __FUNCTION__);
472 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 475 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 490 "%s returns font descent %d\n", __FUNCTION__, iRval);
505 __FUNCTION__, pFont, (
void *)(pFont ? pFont->
pDisplay : NULL));
515 "%s returns (cached) font ascent %d\n", __FUNCTION__, pFont->
iAscent);
519 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 522 WB_ERROR_PRINT(
"ERROR: %s font has 'pfxftFont' non-NULL\n", __FUNCTION__);
523 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 526 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 541 "%s returns font ascent %d\n", __FUNCTION__, iRval);
556 __FUNCTION__, pFont, (
void *)(pFont ? pFont->
pDisplay : NULL));
566 "%s returns (cached) font height %d\n", __FUNCTION__, pFont->
iHeight);
570 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 573 WB_ERROR_PRINT(
"ERROR: %s font has 'pfxftFont' non-NULL\n", __FUNCTION__);
574 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 577 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 579 #warning review that this is the right way to handle this, or if there is a better way 587 "%s returns font height %d\n", __FUNCTION__, iRval);
599 memset(&rVal, 0,
sizeof(rVal));
603 WB_WARN_PRINT(
"%s returns 'zero' struct (bad param, %p, %p)\n",
604 __FUNCTION__, pFont, (
void *)(pFont ? pFont->
pDisplay : NULL));
618 "%s returns (cached) font extent %d %d %d %d %d\n",
626 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 629 WB_ERROR_PRINT(
"ERROR: %s font has 'pfxftFont' non-NULL\n", __FUNCTION__);
630 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 633 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 641 rVal.lbearing = pFont->
pFontStruct->max_bounds.lbearing;
642 rVal.rbearing = pFont->
pFontStruct->max_bounds.rbearing;
644 rVal.ascent = pFont->
pFontStruct->max_bounds.ascent;
645 rVal.descent = pFont->
pFontStruct->max_bounds.descent;
647 memcpy(&rVal, &(pFont->
pFontStruct->max_bounds),
sizeof(rVal));
654 "%s returns font extent %d %d %d %d %d\n",
655 __FUNCTION__, rVal.lbearing, rVal.rbearing, rVal.width, rVal.ascent, rVal.descent);
661 int iFontSize,
int iFlags)
682 WB_WARN_PRINT(
"%s returns NULL (pOriginal is NULL)\n", __FUNCTION__);
691 memset(pRval, 0,
sizeof(*pRval));
696 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 698 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 701 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 709 WB_WARN_PRINT(
"%s returns NULL (unable to copy font set)\n", __FUNCTION__);
722 WB_WARN_PRINT(
"%s returns NULL (unable to copy font struct)\n", __FUNCTION__);
740 WB_WARN_PRINT(
"%s returns NULL (not enough memory for structure)\n", __FUNCTION__);
752 if(!pFont || !cbText || !szText || (cbText < 0 && !*szText))
754 WB_ERROR_PRINT(
"TEMPORARY: %s - returning zero (bad parameter %p %p %d)\n",
755 __FUNCTION__, pFont, szText, cbText);
760 iLen = strlen(szText);
767 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 770 WB_ERROR_PRINT(
"ERROR: %s font initialization has 'pfxftFont' non-NULL\n", __FUNCTION__);
771 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 774 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 781 iRval = XTextWidth(pFont->
pFontStruct, szText, iLen);
785 "%s returns text width %d for \"%-.*s\"\n", __FUNCTION__, iRval, iLen, szText);
795 if(!pFont || !cbText || !szText || (cbText < 0 && !*szText))
797 WB_ERROR_PRINT(
"TEMPORARY: %s - returning zero (bad parameter %p %p %d)\n",
798 __FUNCTION__, pFont, szText, cbText);
803 iLen = strlen(szText);
811 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 814 WB_ERROR_PRINT(
"ERROR: %s font initialization has 'pfxftFont' non-NULL\n", __FUNCTION__);
815 #warning TODO: IMPLEMENT THIS PART for Xft FONTS 818 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 821 XRectangle rct, rct2;
823 memset(&rct2, 0,
sizeof(rct2));
829 pExtent->
width = rct2.width;
830 pExtent->
height = rct2.height;
834 int iDir, iAsc, iDesc;
837 memset(&cs, 0,
sizeof(cs));
840 XTextExtents(pFont->
pFontStruct, szText, iLen, &iDir, &iAsc, &iDesc, &cs);
843 pExtent->
width = cs.width;
844 pExtent->
height = cs.ascent + cs.descent;
int iMaxCharWidth
RESERVED - cached max character width (-1 if not valid). do not access this directly.
'window helper' main header file for the X11workbench Toolkit API
void WBFontSetEnableAntiAlias(int bEnable)
returns non-zero value if certain fonts should be anti-aliased when rendered
void WBFreeFont(Display *pDisplay, WB_FONT pFont)
free a WB_FONT that was created using one of the WBFont APIs
void __internal_font_helper_exit(void)
un-initialization for font helper - call once at end of program (WBExit() does this for you)
#define WB_DEBUG_PRINT(L,...)
Preferred method of implementing conditional debug output.
unsigned int width
the 'width' value of the extent.
int WBFontHeight(WB_FONTC pFont0)
Get the maximum character height from a WB_FONT.
int WBFontAscent(WB_FONTC pFont0)
Get the maximum character ascent from a WB_FONT.
Utilities for copying and drawing text, determining text extents, and so on.
XFontStruct * WBLoadModifyFontX(Display *pDisplay, const XFontStruct *pOriginal, int iFontSize, int iFlags)
load and modify a font according to the specified size and flags
int WBFontAvgCharWidth(WB_FONTC pFont0)
Get the average character width for a font.
WB_FONT WBCopyFont(Display *pDisplay, WB_FONTC pOldFont)
make a copy of an existing font (best when assigning to a window)
XFontSet WBFontSetFromFont(Display *pDisplay, const XFontStruct *pFont)
Creates an 'XFontSet' from an XFontStruct for a given display.
WB_FONT WBCopyModifyFont(Display *pDisplay, WB_FONTC pOriginal, int iFontSize, int iFlags)
load and modify a font according to the specified size and flags
#define WB_TEXT_ESCAPEMENT
int iDescent
RESERVED - cached font descent (-1 if not valid). do not access this directly.
int WBFontSetAvgCharWidth(Display *pDisplay, XFontSet fontSet)
Get the average character width for a font set.
static __inline__ Display * WBGetDefaultDisplay(void)
Returns the default Display.
struct WBFont * WB_FONT
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
WB_FONT WBLoadFont(Display *pDisplay, const char *szFontName, int iFontSize, int iFlags)
load a WB_FONT font object based on a font name, size, and font flags
int WBFontAvgCharWidthX(Display *pDisplay, const XFontStruct *pFont)
Get the average character width for a font.
Display * pDisplay
The Display pointer associated with this font (to be used internally)
int WBFontEnableAntiAlias(void)
returns non-zero value if certain fonts should be anti-aliased when rendered
XFontStruct * WBCopyFontX(XFontStruct *pOldFont)
make a copy of an existing font (best when assigning to a window)
void * WBAlloc(int nSize)
High performance memory sub-allocator 'allocate'.
#define END_XCALL_DEBUG_WRAPPER
wrapper macro for calls into the X11 library. This macro follows the call(s)
XCharStruct max_bounds
RESERVED - cached max bounds (all 0's if not valid). do not access this directly.
#define WB_ERROR_PRINT(...)
Preferred method of implementing an 'error level' debug message for all subsystems.
void WBFree(void *pBuf)
High performance memory sub-allocator 'free'.
XCharStruct WBFontMaxBounds(WB_FONTC pFont0)
Get a 'maximized' copy of 'max_bounds' (applicable to all font faces in the WB_FONT)
int WBFontSetDescent(Display *pDisplay, XFontSet fontSet)
Get the maximum character descent from a font set.
XFontSet fsFont
legacy 'XFontSet' for X11 raster fonts (UTF-8)
int iAvgCharWidth
RESERVED - cached average character width (-1 if not valid). do not access this directly.
internal wrapper struct for 'extent' definition
XFontStruct * pFontStruct
legacy 'XFontStruct' for X11 raster fonts
int WBFontDescent(WB_FONTC pFont0)
Get the maximum character descent from a WB_FONT.
int WBTextWidth(WB_FONTC pFont, const char *szText, int cbText)
Obtain the pixel width of specified text for a specified WB_FONT.
XFontSet WBCopyModifyFontSet(Display *pDisplay, XFontSet fsOrig, int iFontSize, int iFlags)
copy and modify a font set according to the specified size and flags
int WBFontMaxCharWidth(WB_FONTC pFont0)
Get the maximum character width for a font.
int iAscent
RESERVED - cached font ascent (-1 if not valid). do not access this directly.
void __internal_font_helper_init(void)
initialization for font helper - call once at start of program (WBInit() does this for you)
#define BEGIN_XCALL_DEBUG_WRAPPER
wrapper macro for calls into the X11 library. This macro precedes the call(s)
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
unsigned int height
the 'height' value of the extent.
void WBTextExtent(WB_FONTC pFont, const char *szText, int cbText, WB_EXTENT *pExtent)
Obtain the pixel extent of specified text for a specified XFontSet.
XCharStruct WBFontSetMaxBounds(Display *pDisplay, XFontSet fontSet)
Get a 'maximized' copy of the 'max_bounds' member for the font set.
int WBFontSetAscent(Display *pDisplay, XFontSet fontSet)
Get the maximum character ascent from a font set.
#define WB_WARN_PRINT(...)
Preferred method of implementing a 'warning level' debug message for all subsystems.
int iFlags
various bit flags
XFontStruct * WBLoadFontX(Display *pDisplay, const char *szFontName, int iFontSize, int iFlags)
load a font based on a font name, size, and font flags
int iHeight
RESERVED - cached font height (-1 if not valid). do not access this directly.
WB_FONTC WBGetDefaultFont(void)
Returns a pointer to the default font WB_FONT for the default display. This is a shared resource; do ...