64 #include <X11/cursorfont.h> 71 #define FONT_DUMP_DEBUG_LEVEL DebugLevel_Heavy 76 static char *InternalCheckSetLocale(
void);
80 static XFontStruct *WBGetDefaultFontStruct()
93 static XFontSet WBGetDefaultFontSet(Display *pDisplay)
114 if(XGetFontProperty(pOldFont, XA_FONT, &lName))
121 "%s(%s)\n", __FUNCTION__, pName);
131 WB_WARN_PRINT(
"%s - WARNING: %d not an atom\n", __FUNCTION__, (
int)lName);
147 "%s - call to XQueryFont for %d (%08xH)\n", __FUNCTION__, (
int)pOldFont->fid, (
int)pOldFont->fid);
161 void WBFontNameFromAlias(
const char *szFontName,
char *szDest,
int cbDest)
163 XFontStruct *pFSInfo=NULL;
171 bzero(szDest, cbDest);
173 if(ppNames && iCount > 0)
177 WB_WARN_PRINT(
"%s - WARNING: WBFontNameFromAlias returns iCount > 1\n", __FUNCTION__);
180 strncpy(szDest, ppNames[0], cbDest);
183 XFreeFontInfo(ppNames, pFSInfo, iCount);
189 char tbuf[256], tbuf2[64];
192 if(!szFontName || !*szFontName)
195 if(szFontName[0] !=
'-')
198 WBFontNameFromAlias(szFontName, tbuf,
sizeof(tbuf));
202 strcat(tbuf, szFontName);
207 if(szFontName[0] !=
'-')
209 WB_WARN_PRINT(
"%s - * BUG * font name doesn't start with a '-' \"%s\"\n", __FUNCTION__, szFontName);
219 bzero(pRval,
sizeof(
WB_FONT_INFO) + strlen(szFontName));
221 p1 = (
char *)(pRval->data);
222 strcpy(p1, szFontName + 1);
224 #define DO_FONT_PARSE_THING(X) pRval->X=p1; while(*p1 && *p1 != '-') p1++; if(*p1 == '-') *(p1++) = 0 225 #define DO_FONT_PARSE_THING1() bzero(tbuf2,sizeof(tbuf2)); p3=tbuf2; \ 226 while(*p1 && *p1 != '-' && p3 < (tbuf2 + sizeof(tbuf2) - 2)) *(p3++)=*(p1++); \ 227 while(*p1 && *p1 != '-') p1++; if(*p1 == '-') *(p1++) = 0 228 #define DO_FONT_PARSE_THING2(X) DO_FONT_PARSE_THING1(); \ 229 if(!tbuf2[0] || tbuf2[0]=='*') pRval->X = -1; else pRval->X = atoi(tbuf2) 231 DO_FONT_PARSE_THING(szFoundry);
232 DO_FONT_PARSE_THING(szFamily);
233 DO_FONT_PARSE_THING1();
234 if(!strcasecmp(tbuf2,
"regular"))
236 else if(!strcasecmp(tbuf2,
"medium"))
238 else if(!strcasecmp(tbuf2,
"demibold"))
240 else if(!strcasecmp(tbuf2,
"bold"))
242 else if(tbuf2[0] ==
'*')
247 DO_FONT_PARSE_THING1();
250 else if(tbuf2[0] ==
'o')
252 else if(tbuf2[0] ==
'i')
254 else if(tbuf2[0] ==
'*')
259 DO_FONT_PARSE_THING1();
260 if(!strcasecmp(tbuf2,
"normal"))
262 else if(!strcasecmp(tbuf2,
"semicondensed"))
264 else if(!strcasecmp(tbuf2,
"condensed"))
266 else if(tbuf2[0] ==
'*')
271 DO_FONT_PARSE_THING(szAdStyle);
272 DO_FONT_PARSE_THING2(iPixelSize);
273 DO_FONT_PARSE_THING2(iPointSize);
274 DO_FONT_PARSE_THING2(iResX);
275 DO_FONT_PARSE_THING2(iResY);
276 DO_FONT_PARSE_THING1();
279 else if(tbuf2[0] ==
'm')
281 else if(tbuf2[0] ==
'p')
283 else if(tbuf2[0] ==
'*')
284 pRval->iSpacing = -1;
288 DO_FONT_PARSE_THING2(iAvgWidth);
289 DO_FONT_PARSE_THING(szRegistry);
290 DO_FONT_PARSE_THING(szEncoding);
302 #undef DO_FONT_PARSE_THING2 303 #undef DO_FONT_PARSE_THING1 304 #undef DO_FONT_PARSE_THING 309 #define FUZZY_FONT_EXACT_MATCH (3 + 10 + 5 + 5 + 2 + 4 + 3 + 3 + 1 + 5 + 4 + 4) 315 if(!strcasecmp(p1->szFoundry, p2->szFoundry) ||
316 p1->szFoundry[0] ==
'*' || p2->szFoundry[0] ==
'*' ||
317 !p1->szFoundry[0] || !p2->szFoundry[0])
322 if(!strcasecmp(p1->szFamily, p2->szFamily) ||
323 p1->szFamily[0] ==
'*' || p2->szFamily[0] ==
'*')
328 if(p1->iWeight == -1 || p2->iWeight == -1 || p1->iWeight == p2->iWeight)
331 iRval += 3 - abs(p1->iWeight - p2->iWeight);
333 if(p1->iSlant == -1 || p2->iSlant == -1 || p1->iSlant == p2->iSlant)
336 iRval += 3 - abs(p1->iSlant - p2->iSlant);
338 if(p1->iWidth == -1 || p2->iWidth == -1 || p1->iWidth == p2->iWidth)
344 if(!strcasecmp(p1->szAdStyle,p2->szAdStyle) ||
345 p1->szAdStyle[0] ==
'*' || p2->szAdStyle[0] ==
'*')
349 else if((!p1->szAdStyle[0] || !p1->szAdStyle[1]) &&
350 (!strcasecmp(p1->szAdStyle,
"sans") || !strcasecmp(p2->szAdStyle,
"sans")))
354 else if(!p1->szAdStyle[0] || !p1->szAdStyle[1])
363 if(p1->iPixelSize == -1 || p2->iPixelSize == -1 || p1->iPixelSize == p2->iPixelSize)
366 iRval += 2 - abs(p1->iPixelSize - p2->iPixelSize);
368 if(p1->iPointSize == -1 || p2->iPointSize == -1 || p1->iPointSize == p2->iPointSize)
371 iRval += 2 - abs(p1->iPointSize - p2->iPointSize) / 10;
373 if((p1->iResX == p2->iResX && p1->iResY == p2->iResY) ||
374 (p1->iResX == -1 && p1->iResY == -1) ||
375 (p2->iResX == -1 && p2->iResY == -1))
380 if(p1->iSpacing == -1 || p2->iSpacing == -1 || p1->iSpacing == p2->iSpacing)
382 else if(p1->iSpacing == 0 || p2->iSpacing == 0)
385 iRval += 3 - abs(p1->iSpacing - p2->iSpacing) / 5;
387 if(!strcasecmp(p1->szRegistry,p2->szRegistry) ||
388 !p1->szRegistry[0] || !p2->szRegistry[0] ||
389 p1->szRegistry[0] ==
'*' || p2->szRegistry[0] ==
'*')
394 if(!strcasecmp(p1->szEncoding,p2->szEncoding) ||
395 !p1->szEncoding[0] || !p2->szEncoding[0] ||
396 p1->szEncoding[0] ==
'*' || p2->szEncoding[0] ==
'*')
404 static int InternalFontMatch2(
const char *p1,
const char *p2)
412 iRval = InternalFontMatch(pfi1, pfi2);
428 static __inline__
int __string_valid_check(
const char *pString) {
return pString && *pString; }
430 static void InternalBuildFontString(
const char *szFontName,
int iSize,
int iFlags,
431 char *pBuf,
int cbBuf,
int bForceWildcard)
440 strncpy(pBuf, szFontName, cbBuf);
449 #define DO_FONT_BUILD_THING(X) if((p1 + 2) >= pEnd) return; *(p1++) = '-'; \ 450 if(__string_valid_check(X)) { strncpy(p1, X, (pEnd - p1)); p1 += strlen(p1); } else *(p1++) = '*'; \ 451 *p1 = 0; if((p1 + 1) >= pEnd) return 453 DO_FONT_BUILD_THING(pFI->szFoundry);
454 DO_FONT_BUILD_THING(pFI->szFamily);
460 strcpy(tbuf,
"regular");
463 strcpy(tbuf,
"medium");
466 strcpy(tbuf,
"demibold");
469 strcpy(tbuf,
"bold");
481 strcpy(tbuf,
"regular");
484 strcpy(tbuf,
"medium");
487 strcpy(tbuf,
"demibold");
490 strcpy(tbuf,
"bold");
493 if(bForceWildcard || !*tbuf)
498 DO_FONT_BUILD_THING(tbuf);
531 if(bForceWildcard || !*tbuf)
536 DO_FONT_BUILD_THING(tbuf);
542 strcpy(tbuf,
"normal");
545 strcpy(tbuf,
"semicondensed");
548 strcpy(tbuf,
"condensed");
560 strcpy(tbuf,
"normal");
563 strcpy(tbuf,
"semicondensed");
566 if(bForceWildcard || !*tbuf)
571 DO_FONT_BUILD_THING(tbuf);
573 strncpy(tbuf, pFI->szAdStyle,
sizeof(tbuf));
579 strcpy(tbuf,
"sans");
590 DO_FONT_BUILD_THING(tbuf);
595 iAvgWidth = pFI->iAvgWidth;
599 if(pFI->iPixelSize > 0 && iSize < 0 && !bForceWildcard)
600 sprintf(tbuf,
"%d", pFI->iPixelSize);
603 if(pFI->iPixelSize != iSize)
605 sprintf(tbuf,
"%d", iSize);
610 DO_FONT_BUILD_THING(tbuf);
612 if(pFI->iPointSize > 0 && !bForceWildcard)
614 if(iSize <= 0 || iSize == pFI->iPixelSize)
615 sprintf(tbuf,
"%d", pFI->iPointSize);
617 sprintf(tbuf,
"%d", ((pFI->iPointSize * 2 * iSize / pFI->iPixelSize) + 1) / 2);
622 DO_FONT_BUILD_THING(tbuf);
627 if(pFI->iPointSize > 0 && !bForceWildcard)
631 && iSize * 10 == pFI->iPointSize) ||
633 && iSize / 2 == pFI->iPointSize))
635 sprintf(tbuf,
"%d", pFI->iPixelSize);
643 sprintf(tbuf,
"%d", ((pFI->iPixelSize * 20 * iSize / pFI->iPointSize) + 1) / 2);
647 sprintf(tbuf,
"%d", ((pFI->iPixelSize * iSize / pFI->iPointSize) + 1) / 2);
653 DO_FONT_BUILD_THING(tbuf);
655 if(pFI->iPointSize > 0 && iSize < 0 && !bForceWildcard)
656 sprintf(tbuf,
"%d", pFI->iPointSize);
661 sprintf(tbuf,
"%d", iSize * 10);
662 if(pFI->iPointSize != iSize * 10)
667 sprintf(tbuf,
"%d", iSize / 2);
668 if(pFI->iPointSize != iSize / 2)
675 DO_FONT_BUILD_THING(tbuf);
679 if(pFI->iPixelSize > 0 && !bForceWildcard)
680 sprintf(tbuf,
"%d", pFI->iPixelSize);
684 DO_FONT_BUILD_THING(tbuf);
686 if(pFI->iPointSize > 0 && !bForceWildcard)
687 sprintf(tbuf,
"%d", pFI->iPointSize);
691 DO_FONT_BUILD_THING(tbuf);
694 if(!bForceWildcard && pFI->iResX > 0)
695 sprintf(tbuf,
"%d", pFI->iResX);
699 DO_FONT_BUILD_THING(tbuf);
701 if(!bForceWildcard && pFI->iResY > 0)
702 sprintf(tbuf,
"%d", pFI->iResY);
706 DO_FONT_BUILD_THING(tbuf);
709 switch(pFI->iSpacing)
737 if(!*tbuf || bForceWildcard)
742 DO_FONT_BUILD_THING(tbuf);
745 if(bForceWildcard || iAvgWidth <= 0)
748 sprintf(tbuf,
"%d", pFI->iAvgWidth);
750 DO_FONT_BUILD_THING(tbuf);
754 if(!bForceWildcard || pFI->szRegistry[0])
755 strcpy(tbuf, pFI->szRegistry);
761 DO_FONT_BUILD_THING(tbuf);
763 if(!bForceWildcard || pFI->szEncoding[0])
764 strcpy(tbuf, pFI->szEncoding);
768 DO_FONT_BUILD_THING(tbuf);
772 XFontStruct *
WBLoadFontX(Display *pDisplay,
const char *szFontName,
773 int iFontSize,
int iFlags)
775 XFontStruct *pRval=NULL, *pFSInfo=NULL;
777 int i1, i2, i3, iBest, iCount = 0;
779 char tbuf[512], tbuf2[512], tbuf3[512];
820 if(szFontName && *szFontName && !strchr(szFontName,
'*') && !strchr(szFontName,
'-'))
823 WBFontNameFromAlias(szFontName, tbuf,
sizeof(tbuf));
828 strncpy(tbuf + 3, szFontName,
sizeof(tbuf) - 3);
835 strncpy(tbuf, szFontName,
sizeof(tbuf));
840 if(iFlags || iFontSize)
842 InternalBuildFontString(tbuf, iFontSize, iFlags, tbuf2,
sizeof(tbuf2), FALSE);
846 strncpy(tbuf2, tbuf,
sizeof(tbuf2));
849 ppNames = XListFontsWithInfo(pDisplay, tbuf2, 2, &iCount, &pFSInfo);
854 if(iCount == 1 && ppNames)
855 pRval = XLoadQueryFont(pDisplay, *ppNames);
859 XFreeFontInfo(ppNames, pFSInfo, iCount);
870 InternalBuildFontString(tbuf, iFontSize, iFlags, tbuf3,
sizeof(tbuf3), TRUE);
873 ppNames = XListFontsWithInfo(pDisplay, tbuf3, 8192, &iCount, &pFSInfo);
875 if(ppNames && iCount == 1)
877 pRval = XLoadQueryFont(pDisplay, *ppNames);
879 else if(ppNames && iCount > 1)
882 for(i1 = 0, i2 = -1; i1 < iCount; i1++)
884 i3 = InternalFontMatch2(ppNames[i1], tbuf2);
894 pRval = XLoadQueryFont(pDisplay, ppNames[i2]);
901 XFreeFontInfo(ppNames, pFSInfo, iCount);
914 unsigned long lName, lPoints;
936 if(XGetFontProperty((XFontStruct *)pFont,
aAVERAGE_WIDTH, &lName) &&
937 XGetFontProperty((XFontStruct *)pFont, XA_POINT_SIZE, &lPoints) &&
940 iRval = (pFont->ascent + pFont->descent) * lName / lPoints;
947 if(XGetFontProperty((XFontStruct *)pFont, XA_QUAD_WIDTH, &lName) && lName)
954 if(XGetFontProperty((XFontStruct *)pFont, XA_FONT, &lName))
958 if(!pName && pDisplay)
970 pFI = WBParseFontName(pName);
976 iRval = (pFI->iAvgWidth * pFI->iPixelSize) / pFI->iPointSize;
1001 iRval = XTextWidth((XFontStruct *)pFont,
" ", 1);
1005 iRval = (pFont->ascent + pFont->descent) / 2;
1007 WB_ERROR_PRINT(
"TEMPORARY: %s - desperately returning 'half-height' avg font width %d\n", __FUNCTION__, iRval);
1015 XFontStruct **ppFontStruct = NULL;
1016 char **ppFontNames = NULL;
1017 int i1, i2, iN, iMax;
1022 fontSet = WBGetDefaultFontSet(pDisplay);
1026 WB_ERROR_PRINT(
"ERROR: %s - no default font set available\n", __FUNCTION__);
1031 iN = XFontsOfFontSet(fontSet, &ppFontStruct, &ppFontNames);
1035 for(iMax=0, i1=0; i1 < iN; i1++)
1037 if(!ppFontStruct[i1])
1042 i2 = ppFontStruct[i1]->descent;
1057 XFontStruct **ppFontStruct = NULL;
1058 char **ppFontNames = NULL;
1059 int i1, i2, iN, iMax;
1064 fontSet = WBGetDefaultFontSet(pDisplay);
1068 WB_ERROR_PRINT(
"ERROR: %s - no default font set available\n", __FUNCTION__);
1073 iN = XFontsOfFontSet(fontSet, &ppFontStruct, &ppFontNames);
1077 for(iMax=0, i1=0; i1 < iN; i1++)
1079 if(!ppFontStruct[i1])
1084 i2 = ppFontStruct[i1]->ascent;
1099 XFontStruct **ppFontStruct = NULL;
1100 char **ppFontNames = NULL;
1101 int i1, i2, iN, iMaxD, iMaxH;
1106 fontSet = WBGetDefaultFontSet(pDisplay);
1110 WB_ERROR_PRINT(
"ERROR: %s - no default font set available\n", __FUNCTION__);
1115 iN = XFontsOfFontSet(fontSet, &ppFontStruct, &ppFontNames);
1119 for(iMaxD=0, iMaxH=0, i1=0; i1 < iN; i1++)
1121 if(!ppFontStruct[i1])
1126 i2 = ppFontStruct[i1]->descent;
1133 i2 = ppFontStruct[i1]->ascent;
1143 return iMaxD + iMaxH;
1148 XFontStruct **ppFontStruct = NULL;
1149 char **ppFontNames = NULL;
1150 int i1, i2, iN, iTotal, iMax, iCount;
1155 fontSet = WBGetDefaultFontSet(pDisplay);
1159 WB_ERROR_PRINT(
"ERROR: %s - no default font set available\n", __FUNCTION__);
1164 iN = XFontsOfFontSet(fontSet, &ppFontStruct, &ppFontNames);
1168 for(iCount=0, iMax=0, iTotal=0, i1=0; i1 < iN; i1++)
1170 if(!ppFontStruct[i1])
1194 iTotal += iCount >> 1;
1209 XFontStruct **ppFontStruct = NULL;
1210 char **ppFontNames = NULL;
1214 bzero(&rVal,
sizeof(rVal));
1218 fontSet = WBGetDefaultFontSet(pDisplay);
1222 WB_ERROR_PRINT(
"ERROR: %s - no default font set available\n", __FUNCTION__);
1227 iN = XFontsOfFontSet(fontSet, &ppFontStruct, &ppFontNames);
1231 for(iMax=0, i1=0; i1 < iN; i1++)
1233 if(!ppFontStruct[i1])
1238 if(rVal.lbearing < ppFontStruct[i1]->max_bounds.lbearing)
1240 rVal.lbearing = ppFontStruct[i1]->max_bounds.lbearing;
1243 if(rVal.rbearing < ppFontStruct[i1]->max_bounds.rbearing)
1245 rVal.rbearing = ppFontStruct[i1]->max_bounds.rbearing;
1248 if(rVal.width < ppFontStruct[i1]->max_bounds.width)
1250 rVal.width = ppFontStruct[i1]->max_bounds.width;
1253 if(rVal.ascent < ppFontStruct[i1]->max_bounds.ascent)
1255 rVal.ascent = ppFontStruct[i1]->max_bounds.ascent;
1258 if(rVal.descent < ppFontStruct[i1]->max_bounds.descent)
1260 rVal.descent = ppFontStruct[i1]->max_bounds.descent;
1270 int iFontSize,
int iFlags)
1272 unsigned long lName;
1281 if(XGetFontProperty((XFontStruct *)pOriginal, XA_FONT, &lName))
1285 if(!pName && pDisplay)
1307 if(pFI->iPixelSize > 0)
1309 iFontSize = pFI->iPixelSize;
1312 else if(pFI->iPointSize > 0)
1314 iFontSize = pFI->iPointSize;
1326 iFontSize = pOriginal->ascent + pOriginal->descent;
1336 "%s(%s)\n", __FUNCTION__, pName);
1338 pRval =
WBLoadFontX(pDisplay, pName, iFontSize, iFlags);
1342 pRval = XLoadQueryFont(pDisplay, pName);
1361 XFontSet fsRval = None;
1362 char *p1, *pLocale, *pName, *pDef = NULL;
1363 char **ppMissing = NULL;
1370 fsOrig = WBGetDefaultFontSet(pDisplay);
1374 WB_ERROR_PRINT(
"ERROR: %s - no default font set available\n", __FUNCTION__);
1381 p1 = XBaseFontNameListOfFontSet(fsOrig);
1384 WB_ERROR_PRINT(
"ERROR: %s - font set can't get base name\n", __FUNCTION__);
1391 WB_ERROR_PRINT(
"ERROR: %s - no memory for copying base name\n", __FUNCTION__);
1395 p1 = strchr(pName,
',');
1407 if(!iFontSize && iFlags)
1415 if(pFI->iPixelSize > 0)
1417 iFontSize = pFI->iPixelSize;
1420 else if(pFI->iPointSize > 0)
1422 iFontSize = pFI->iPointSize;
1449 if(iFlags || iFontSize)
1453 InternalBuildFontString(pName, iFontSize, iFlags, tbuf,
sizeof(tbuf), FALSE);
1459 strncpy(tbuf, pName,
sizeof(tbuf));
1463 "%s(%s)\n", __FUNCTION__, pName);
1468 pLocale = InternalCheckSetLocale();
1474 fsRval = XCreateFontSet(pDisplay, tbuf, &ppMissing, &nMissing, &pDef);
1476 if(fsRval == None &&
1477 strcmp(tbuf, pName))
1479 fsRval = XCreateFontSet(pDisplay, pName, &ppMissing, &nMissing, &pDef);
1486 setlocale(LC_ALL, pLocale);
1492 setlocale(LC_ALL,
"C");
1499 if(ppMissing || nMissing > 0)
1503 XFreeStringList(ppMissing);
1507 WB_ERROR_PRINT(
"*BUG* %s - nMissing is %d\n", __FUNCTION__, nMissing);
1529 #ifdef USE_FONT_LIST_FOR_FONT_SET 1531 static char * InternalGetMatchingFontNameList(Display *pDisplay,
const char *szFontName)
1535 int i1, iCount, iLen;
1536 XFontStruct *pFSInfo;
1540 ppNames = XListFontsWithInfo(pDisplay, szFontName, 8192, &iCount, &pFSInfo);
1544 for(i1=0, iLen=1; i1 < iCount; i1++)
1546 iLen += strlen(ppNames[i1]) + 1;
1553 for(i1=0, p1=pRval; i1 < iCount; i1++)
1560 strcpy(p1, ppNames[i1]);
1565 XFreeFontInfo(ppNames, pFSInfo, iCount);
1576 #endif // USE_FONT_LIST_FOR_FONT_SET 1581 unsigned long lName;
1582 char *pName = NULL, *pDef = NULL;
1583 XFontSet rVal = None;
1584 char **ppMissing = NULL;
1587 static const char szISO[]=
"-ISO8859-";
1596 pFont = WBGetDefaultFontStruct();
1606 if(XGetFontProperty((XFontStruct *)pFont, XA_FONT, &lName))
1610 if(!pName && pDisplay)
1619 WB_ERROR_PRINT(
"%s - no font name, returning NULL\n", __FUNCTION__);
1623 p1 =
WBReAlloc(pName, strlen(pName) * 2 + 64);
1629 WB_ERROR_PRINT(
"%s - no memory to update font name, returning NULL\n", __FUNCTION__);
1667 p1 = pName + strlen(pName) -
sizeof(szISO);
1669 while(p1 > pName && strncasecmp(p1, szISO,
sizeof(szISO)-1))
1683 pLocale = InternalCheckSetLocale();
1692 rVal = XCreateFontSet(pDisplay, pName, &ppMissing, &nMissing, &pDef);
1703 setlocale(LC_CTYPE, pLocale);
1717 if(ppMissing || nMissing > 0)
1730 XFreeStringList(ppMissing);
1734 WB_ERROR_PRINT(
"*BUG* %s - nMissing is %d\n", __FUNCTION__, nMissing);
1743 WB_ERROR_PRINT(
"%s - no result, returning NULL\n", __FUNCTION__);
1761 unsigned long lName;
1762 char *pName = NULL, *pDef = NULL;
1763 XFontSet rVal = None;
1764 char **ppMissing = NULL;
1772 pFont = WBGetDefaultFontStruct();
1782 if(XGetFontProperty((XFontStruct *)pFont, XA_FONT, &lName))
1786 if(!pName && pDisplay)
1795 WB_ERROR_PRINT(
"%s - no font name, returning NULL\n", __FUNCTION__);
1799 p1 = setlocale(LC_CTYPE, NULL);
1810 setlocale(LC_CTYPE,
"C");
1814 rVal = XCreateFontSet(pDisplay, pName, &ppMissing, &nMissing, &pDef);
1816 WB_ERROR_PRINT(
"TEMPORARY: %s - setting locale back to \"%s\"\n", __FUNCTION__, pLocale);
1820 setlocale(LC_CTYPE, pLocale);
1833 if(ppMissing || nMissing > 0)
1837 XFreeStringList(ppMissing);
1841 WB_ERROR_PRINT(
"*BUG* %s - nMissing is %d\n", __FUNCTION__, nMissing);
1850 WB_ERROR_PRINT(
"%s - no result, returning NULL\n", __FUNCTION__);
1868 XFontStruct **ppFontStruct = NULL;
1869 char **ppFontNames = NULL;
1871 XFontStruct *pRval = NULL;
1876 fontSet = WBGetDefaultFontSet(pDisplay);
1880 WB_ERROR_PRINT(
"ERROR: %s - no default font set available\n", __FUNCTION__);
1885 iN = XFontsOfFontSet(fontSet, &ppFontStruct, &ppFontNames);
1889 for(i1=0; i1 < iN; i1++)
1891 if(ppFontStruct[i1])
1911 if(fontSet == None || !cbText || !szText || (cbText < 0 && !*szText))
1913 WB_ERROR_PRINT(
"TEMPORARY: %s - returning zero (bad parameter)\n", __FUNCTION__);
1918 iLen = strlen(szText);
1943 XRectangle rct, rct2;
1947 if(fontSet == None || !cbText || !szText || (cbText < 0 && !*szText))
1949 WB_ERROR_PRINT(
"TEMPORARY: %s - returning zero (bad parameter)\n", __FUNCTION__);
1954 iLen = strlen(szText);
1961 memset(&rct2, 0,
sizeof(rct2));
1967 pExtent->
width = rct2.width;
1968 pExtent->
height = rct2.height;
1985 char *InternalCheckSetLocale(
void)
1987 char *p1, *pLocale, *pNewLocale;
1988 static const char szUTF8[]=
".UTF-8";
1991 p1 = setlocale(LC_CTYPE, NULL);
2006 if(!strcasecmp(pLocale + strlen(pLocale) - (
sizeof(szUTF8)-1), szUTF8))
2017 if(!strcasecmp(pLocale,
"C") ||
2018 !strcasecmp(pLocale,
"POSIX"))
2028 p1 = pNewLocale + strlen(pNewLocale);
2030 while(p1 > pNewLocale && *(--p1) !=
'.') { }
2043 if(setlocale(LC_CTYPE, pNewLocale))
2063 WB_ERROR_PRINT(
"TEMPORARY: %s - fallback, set locale to \"en_US.UTF-8\"\n", __FUNCTION__);
2065 setlocale(LC_CTYPE,
"en_US.UTF-8");
2097 unsigned min_char_or_byte2;
2098 unsigned max_char_or_byte2;
2101 Bool all_chars_exist;
2102 unsigned default_char;
2104 XFontProp *properties;
2105 XCharStruct min_bounds;
2106 XCharStruct max_bounds;
2107 XCharStruct *per_char;
2115 " fid = %d (%08xH)\n" 2117 " min_char_or_byte2= %d\n" 2118 " max_char_or_byte2= %d\n" 2121 " all_chars_exist = %d\n" 2122 " default_char = %d\n" 2123 " n_properties = %d\n",
2125 (
int)pFont->fid, (
int)pFont->fid,
2127 pFont->min_char_or_byte2,
2128 pFont->max_char_or_byte2,
2131 pFont->all_chars_exist,
2132 pFont->default_char,
2133 pFont->n_properties);
2135 for(i1=0; i1 < pFont->n_properties; i1++)
2141 (
int)pFont->properties[i1].name,p1,
2142 pFont->properties[i1].card32,
2143 pFont->properties[i1].card32, p2);
2166 XFontStruct *pFSInfo;
2168 ppNames = XListFontsWithInfo(pDisplay, szFontName, 8192, &iCount, &pFSInfo);
2172 WBDebugPrint(
"%s - fonts matching \"%s\"\n", __FUNCTION__, szFontName);
2174 for(i1=0; i1 < iCount; i1++)
2181 WBDebugPrint(
"%s - NO fonts match \"%s\"\n", __FUNCTION__, szFontName);
2187 XFreeFontInfo(ppNames, pFSInfo, iCount);
2191 static void WBDumpFontSet(Display *pDisplay, XFontSet fontSet)
2193 XFontStruct **ppFontStruct = NULL;
2194 char **ppFontNames = NULL;
2197 iN = XFontsOfFontSet(fontSet, &ppFontStruct, &ppFontNames);
2199 WBDebugPrint(
"%s - font set contains %d fonts\n", __FUNCTION__, iN);
2200 WBDebugPrint(
"font set locale \"%s\"\n", XLocaleOfFontSet(fontSet));
2202 WBDebugPrint(
"base name: \"%s\"\n\n", XBaseFontNameListOfFontSet(fontSet));
2204 for(i1=0; i1 < iN; i1++)
2214 XFontStruct *pFSInfo=NULL;
2215 char **ppNames=NULL;
2216 int i1, i2, iCount = 0;
2219 if(!szFontName || !*szFontName)
2223 else if(szFontName[0] !=
'-')
2226 strcat(temp, szFontName);
2232 strcat(temp, szFontName);
2236 if(szFontName && *szFontName)
2242 ppNames = XListFontsWithInfo(
WBGetDefaultDisplay(), szFontName, 16384, &iCount, &pFSInfo);
2253 WBDebugPrint(
"%s - no matching fonts\n", __FUNCTION__);
2261 for(i1=0; i1 < iCount; i1++)
2276 (
int)pFSInfo[i1].fid, (
int)pFSInfo[i1].fid, pFSInfo[i1].direction,
2277 pFSInfo[i1].ascent, pFSInfo[i1].descent);
2279 for(i2=0; i2 < pFSInfo[i1].n_properties && pFSInfo[i1].properties; i2++)
2281 XFontProp *pProp = pFSInfo[i1].properties + i2;
2286 strncpy(temp, pName,
sizeof(temp));
2291 sprintf(temp,
"Atom %d (%08xH)", (
int)pProp->name, (
int)pProp->name);
2295 temp, pProp->card32, pProp->card32);
2304 XFreeFontInfo(ppNames, pFSInfo, iCount);
2308 XFreeFontNames(ppNames);
font size is in 'twips' (when font size > 0)
font size is in 'points' (when font size > 0)
'window helper' main header file for the X11workbench Toolkit API
#define WB_DEBUG_PRINT(L,...)
Preferred method of implementing conditional debug output.
unsigned int width
the 'width' value of the extent.
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
bold font weight (mutually exclusive0
condensed (alternate to 'fixed')
'oblique' slant (mutually exclusive)
XFontSet WBFontSetFromFont(Display *pDisplay, const XFontStruct *pFont)
Creates an 'XFontSet' from an XFontStruct for a given display.
semicondensed width (mutually exclusive)
#define WB_TEXT_ESCAPEMENT
'Any' pitch (default, zero)
int WBFontSetAvgCharWidth(Display *pDisplay, XFontSet fontSet)
Get the average character width for a font set.
static __inline__ Display * WBGetDefaultDisplay(void)
Returns the default Display.
void * WBReAlloc(void *pBuf, int nNewSize)
High performance memory sub-allocator 're-allocate'.
medium font weight (mutually exclusive0
void WBTextExtentX(XFontSet fontSet, const char *szText, int cbText, WB_EXTENT *pExtent)
Obtain the pixel extent of specified text for a specified XFontSet.
int WBFontAvgCharWidthX(Display *pDisplay, const XFontStruct *pFont)
Get the average character width for a font.
XFontStruct * WBCopyFontX(XFontStruct *pOldFont)
make a copy of an existing font (best when assigning to a window)
XFontSet WBFontSetFromFontSingle(Display *pDisplay, const XFontStruct *pFont)
Creates an 'XFontSet' from an XFontStruct for a given display, with only a single font in the set.
'regular' slant (mutually exclusive)
regular font weight (mutually exclusive0
Atom aAVERAGE_WIDTH
Atoms for fonts - Average Character Width.
font size is in 'pixels' (when font size > 0)
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)
static void WBDumpFontSet(Display *pDisplay, XFontSet fontSet)
debug function to dump font set members
int WBFontSetHeight(Display *pDisplay, XFontSet fontSet)
Get the maximum character height from a font set.
#define WB_ERROR_PRINT(...)
Preferred method of implementing an 'error level' debug message for all subsystems.
normal width (mutually exclusive)
demi-bold font weight (mutually exclusive0
void WBFree(void *pBuf)
High performance memory sub-allocator 'free'.
static void WBDumpMatchingFontNames(Display *pDisplay, const char *szFontName)
debug function to dump matching font names
int WBFontSetDescent(Display *pDisplay, XFontSet fontSet)
Get the maximum character descent from a font set.
Any font weight specification (mutually exclusive)
'size mask' for font size > 0
'italic' slant (mutually exclusive)
force serif (i.e. 'not sans')
XFontSet fsFont
legacy 'XFontSet' for X11 raster fonts (UTF-8)
int WBTextWidthX(XFontSet fontSet, const char *szText, int cbText)
Obtain the pixel width of specified text for a specified XFontSet.
internal wrapper struct for 'extent' definition
XFontStruct * pFontStruct
legacy 'XFontStruct' for X11 raster fonts
XFontStruct * WBFontFromFontSet(Display *pDisplay, XFontSet fontSet)
Creates an 'XFontStruct' from the first font assigned to a Font Set.
XFontSet WBCopyModifyFontSet(Display *pDisplay, XFontSet fsOrig, int iFontSize, int iFlags)
copy and modify a font set according to the specified size and flags
Internal structure, caching font information (mostly for legacy font support)
#define BEGIN_XCALL_DEBUG_WRAPPER
wrapper macro for calls into the X11 library. This macro precedes the call(s)
static void WBDumpFontStruct(const XFontStruct *pFont)
debug function to dump font struct members
'default' slant (zero; mutually exclusive; may return an italic or oblique font)
void WBDumpFontInfo(const char *szFontName)
Dump debug information about fonts according to pSpec.
void WBDebugPrint(const char *pFmt,...) __attribute__((format(printf
conditional debug message output
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
char * WBCopyString(const char *pSrc)
A simple utility that returns a WBAlloc() copy of a 0-byte terminated string.
'Any' width (zero; mutually exclusive)
unsigned int height
the 'height' value of the extent.
#define WB_IF_DEBUG_LEVEL(L)
Preferred method of implementing conditional debug 'if block' code.
'Any' style (default, zero)
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.
XFontStruct * WBLoadFontX(Display *pDisplay, const char *szFontName, int iFontSize, int iFlags)
load a font based on a font name, size, and font flags
void WBCatString(char **ppDest, const char *pSrc)
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string.
WB_FONTC WBGetDefaultFont(void)
Returns a pointer to the default font WB_FONT for the default display. This is a shared resource; do ...