X11workbench Toolkit  1.0
font_helper.h
Go to the documentation of this file.
1 // __ _ _ _ _ //
3 // / _| ___ _ __ | |_ | |__ ___ | | _ __ ___ _ __ | |__ //
4 // | |_ / _ \ | '_ \ | __| | '_ \ / _ \| || '_ \ / _ \| '__|| '_ \ //
5 // | _|| (_) || | | || |_ | | | || __/| || |_) || __/| | _ | | | | //
6 // |_| \___/ |_| |_| \__|_____|_| |_| \___||_|| .__/ \___||_|(_)|_| |_| //
7 // |_____| |_| //
8 // basic font enumeration and selection //
9 // //
11 
12 /*****************************************************************************
13 
14  X11workbench - X11 programmer's 'work bench' application and toolkit
15  Copyright (c) 2010-2018 by Bob Frazier (aka 'Big Bad Bombastic Bob')
16  all rights reserved
17 
18  DISCLAIMER: The X11workbench application and toolkit software are supplied
19  'as-is', with no warranties, either implied or explicit.
20  Any claims to alleged functionality or features should be
21  considered 'preliminary', and might not function as advertised.
22 
23  BSD-like license:
24 
25  There is no restriction as to what you can do with this software, so long
26  as you include the above copyright notice and DISCLAIMER for any distributed
27  work that is equal to or derived from this one, along with this paragraph
28  that explains the terms of the license if the source is also being made
29  available. A "derived work" describes a work that uses a significant portion
30  of the source files or algorithms that are included with this one.
31  Specifically excluded from this are files that were generated by the software,
32  or anything that is included with the software that is part of another package
33  (such as files that were created or added during the 'configure' process).
34  Specifically included is the use of part or all of any of the X11 workbench
35  toolkit source or header files in your distributed application. If you do not
36  ship the source, the above copyright statement is still required to be placed
37  in a reasonably prominent place, such as documentation, splash screens, and/or
38  'about the application' dialog boxes.
39 
40  Use and distribution are in accordance with GPL, LGPL, and/or the above
41  BSD-like license. See COPYING and README files for more information.
42 
43 
44  Additional information at http://sourceforge.net/projects/X11workbench
45 
46 ******************************************************************************/
47 
66 #ifndef _FONT_HELPER_H_INCLUDED_
67 #define _FONT_HELPER_H_INCLUDED_
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif // __cplusplus
72 
73 #ifndef _WINDOW_HELPER_H_INCLUDED_
74 typedef struct _WBExtent_ WB_EXTENT; // forward reference on WB_EXTENT structure for WBTextExtent()
75 #endif // _WINDOW_HELPER_H_INCLUDED_
76 
77 
81 // UTF-8 HANDLING
82 // X11 has XFree86 extensions with 'Xutf8' versions of a lot of things
83 // which is only applicable with the following
84 //#ifdef X_HAVE_UTF8_STRING
85 // I use the utf8 version
86 // etc.
87 //
88 // Unfortunately many things that I use don't have that available
89 // like XTextWidth for one (maybe I could use Xutf8TextExtents?)
90 // Using Xmb and Xwc equivalent methods should work on Interix
91 //
92 #if defined(X_HAVE_UTF8_STRING) || defined(__DOXYGEN__)
93 
94 #define WB_TEXT_EXTENTS Xutf8TextExtents
95 #define WB_TEXT_ESCAPEMENT Xutf8TextEscapement
96 #define WB_DRAW_STRING Xutf8DrawString
97 #define WB_DRAW_TEXT Xutf8DrawText
98 #define WB_LOOKUP_STRING Xutf8LookupString
100 #else // X_HAVE_UTF8_STRING
101 
102 #warning UTF8 not supported, using 'MB' equivalents
103 
104 #define WB_TEXT_EXTENTS XmbTextExtents
105 #define WB_TEXT_ESCAPEMENT XmbTextEscapement
106 #define WB_DRAW_STRING XmbDrawString
107 #define WB_DRAW_TEXT XmbDrawText
108 #define WB_LOOKUP_STRING XmbLookupString
110 #endif // X_HAVE_UTF8_STRING
111 
131 XFontStruct *WBCopyFont(XFontStruct *pFont);
132 
155 XFontStruct *WBLoadFont(Display *pDisplay, const char *szFontName,
156  int iFontSize, int iFlags);
157 
180 XFontStruct *WBLoadModifyFont(Display *pDisplay, const XFontStruct *pOriginal,
181  int iFontSize, int iFlags);
182 
183 
206 XFontSet WBCopyModifyFontSet(Display *pDisplay, XFontSet fsOrig, int iFontSize, int iFlags);
207 
208 
219 int WBFontAvgCharWidth(Display *pDisplay, const XFontStruct *pFont);
220 
221 
233 int WBFontSetDescent(Display *pDisplay, XFontSet fontSet);
234 
235 
247 int WBFontSetAscent(Display *pDisplay, XFontSet fontSet);
248 
249 
261 int WBFontSetHeight(Display *pDisplay, XFontSet fontSet);
262 
263 
275 int WBFontSetAvgCharWidth(Display *pDisplay, XFontSet fontSet);
276 
277 
289 XCharStruct WBFontSetMaxBounds(Display *pDisplay, XFontSet fontSet);
290 
291 
308 XFontSet WBFontSetFromFont(Display *pDisplay, const XFontStruct *pFont);
309 
310 
324 XFontStruct * WBFontFromFontSet(Display *pDisplay, XFontSet fontSet);
325 
326 
347 XFontSet WBFontSetFromFontSingle(Display *pDisplay, const XFontStruct *pFont);
348 
349 
363 int WBTextWidth(XFontSet fontSet, const char *szText, int cbText);
364 
365 
381 void WBTextExtent(XFontSet fontSet, const char *szText, int cbText, WB_EXTENT *pExtent);
382 
383 
395 void WBDumpFontInfo(const char *pSpec); // debugging function - dumps a list of fonts and info
396 
397 
408 {
414 
421 
427 
428  // if the font size is > 0 then these bits apply
434 
443 
449 
455 
456  // reserved - font registry and encoding (installed X11 fonts typically include most if not all of these)
459  WBFontFlag_REG_ASCII = 0x300000,
461  WBFontFlag_REG_MISC = 0x500000,
463  WBFontFlag_REG_ADOBE = 0x700000,
472  WBFontFlag_REG_MASK = 0xf00000,
473 
474  // TODO: flags for 'encoding' ?
475 
476  WBFontFlag_WHATEVER = 0 // don't force anything (zero, default)
477 };
478 
479 
480 
481 #ifdef __cplusplus
482 };
483 #endif // __cplusplus
484 
485 
486 #endif // _FONT_HELPER_H_INCLUDED_
487 
XFontStruct * WBFontFromFontSet(Display *pDisplay, XFontSet fontSet)
Creates an 'XFontStruct' from the first font assigned to a Font Set.
Definition: font_helper.c:2027
XFontStruct * WBLoadFont(Display *pDisplay, const char *szFontName, int iFontSize, int iFlags)
load a font based on a font name, size, and font flags
Definition: font_helper.c:858
font size is in 'twips' (when font size > 0)
Definition: font_helper.h:431
internal wrapper struct for 'extent' definition
use a font specific registry (mutually exclusive)
Definition: font_helper.h:460
font size is in 'points' (when font size > 0)
Definition: font_helper.h:430
reserved (style)
Definition: font_helper.h:417
bold font weight (mutually exclusive0
Definition: font_helper.h:439
condensed (alternate to 'fixed')
Definition: font_helper.h:411
reserved reg flag (reserved for future use)
Definition: font_helper.h:467
reserved reg flag (reserved for future use)
Definition: font_helper.h:471
reserved flags for font size > 0
Definition: font_helper.h:432
XFontStruct * WBLoadModifyFont(Display *pDisplay, const XFontStruct *pOriginal, int iFontSize, int iFlags)
load and modify a font according to the specified size and flags
Definition: font_helper.c:1350
'oblique' slant (mutually exclusive)
Definition: font_helper.h:445
int WBTextWidth(XFontSet fontSet, const char *szText, int cbText)
Obtain the pixel width of specified text for a specified XFontSet.
Definition: font_helper.c:2067
semicondensed width (mutually exclusive)
Definition: font_helper.h:451
XFontSet WBFontSetFromFont(Display *pDisplay, const XFontStruct *pFont)
Creates an 'XFontSet' from an XFontStruct for a given display.
Definition: font_helper.c:1750
reserved reg flag (reserved for future use)
Definition: font_helper.h:469
'Any' pitch (default, zero)
Definition: font_helper.h:412
use ADOBE registry (mutually exclusive)
Definition: font_helper.h:462
void WBTextExtent(XFontSet fontSet, const char *szText, int cbText, WB_EXTENT *pExtent)
Obtain the pixel extent of specified text for a specified XFontSet.
Definition: font_helper.c:2102
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...
Definition: font_helper.c:1925
reserved reg flag (reserved for future use)
Definition: font_helper.h:470
font weight bit mask
Definition: font_helper.h:442
reserved reg flag (reserved for future use)
Definition: font_helper.h:464
'foundry mask'
Definition: font_helper.h:426
reserved (style)
Definition: font_helper.h:418
force fixed pitch
Definition: font_helper.h:409
'pitch mask'
Definition: font_helper.h:413
use ADOBE registry - a lot of fonts use this (mutually exclusive)
Definition: font_helper.h:463
medium font weight (mutually exclusive0
Definition: font_helper.h:437
'regular' slant (mutually exclusive)
Definition: font_helper.h:444
regular font weight (mutually exclusive0
Definition: font_helper.h:436
force freetype
Definition: font_helper.h:423
force raster (xfree86?)
Definition: font_helper.h:422
font size is in 'pixels' (when font size > 0)
Definition: font_helper.h:429
reserved reg flag (reserved for future use)
Definition: font_helper.h:466
reserved font weight (6) (not currently in use)
Definition: font_helper.h:441
XFontSet WBCopyModifyFontSet(Display *pDisplay, XFontSet fsOrig, int iFontSize, int iFlags)
copy and modify a font set according to the specified size and flags
Definition: font_helper.c:1441
use 'MISC' registry (mutually exclusive)
Definition: font_helper.h:461
int WBFontSetHeight(Display *pDisplay, XFontSet fontSet)
Get the maximum character height from a font set.
Definition: font_helper.c:1178
int WBFontSetAvgCharWidth(Display *pDisplay, XFontSet fontSet)
Get the average character width for a font set.
Definition: font_helper.c:1227
normal width (mutually exclusive)
Definition: font_helper.h:450
demi-bold font weight (mutually exclusive0
Definition: font_helper.h:438
Any font weight specification (mutually exclusive)
Definition: font_helper.h:435
'size mask' for font size > 0
Definition: font_helper.h:433
force sans-serif
Definition: font_helper.h:415
'italic' slant (mutually exclusive)
Definition: font_helper.h:446
WBFontFlags
Font 'flag' enumeration.
Definition: font_helper.h:407
force serif (i.e. 'not sans')
Definition: font_helper.h:416
int WBFontSetDescent(Display *pDisplay, XFontSet fontSet)
Get the maximum character descent from a font set.
Definition: font_helper.c:1094
int WBFontAvgCharWidth(Display *pDisplay, const XFontStruct *pFont)
Get the average character width for a font.
Definition: font_helper.c:998
'Any' foundry (default, zero)
Definition: font_helper.h:425
use ISO646-1991 registry (mutually exclusive)
Definition: font_helper.h:458
reserved (foundry)
Definition: font_helper.h:424
int WBFontSetAscent(Display *pDisplay, XFontSet fontSet)
Get the maximum character ascent from a font set.
Definition: font_helper.c:1136
XCharStruct WBFontSetMaxBounds(Display *pDisplay, XFontSet fontSet)
Get a 'maximized' copy of the 'max_bounds' member for the font set.
Definition: font_helper.c:1287
'default' slant (zero; mutually exclusive; may return an italic or oblique font)
Definition: font_helper.h:447
void WBDumpFontInfo(const char *pSpec)
Dump debug information about fonts according to pSpec.
Definition: font_helper.c:415
use ASCII registry (mutually exclusive)
Definition: font_helper.h:459
'Any' width (zero; mutually exclusive)
Definition: font_helper.h:453
reserved reg flag (reserved for future use)
Definition: font_helper.h:468
'Any' style (default, zero)
Definition: font_helper.h:419
'reserved' width type
Definition: font_helper.h:452
XFontStruct * WBCopyFont(XFontStruct *pFont)
make a copy of an existing font (best when assigning to a window)
Definition: font_helper.c:97
reserved reg flag (reserved for future use)
Definition: font_helper.h:465
reserved font weight (5) (not currently in use)
Definition: font_helper.h:440
font registry mask
Definition: font_helper.h:472
force variable pitch
Definition: font_helper.h:410
use ISO8859 registry (mutually exclusive)
Definition: font_helper.h:457