X11 Work Bench 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-2016 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 
77 // UTF-8 HANDLING
78 // X11 has XFree86 extensions with 'Xutf8' versions of a lot of things
79 // which is only applicable with the following
80 //#ifdef X_HAVE_UTF8_STRING
81 // I use the utf8 version
82 // etc.
83 //
84 // Unfortunately many things that I use don't have that available
85 // like XTextWidth for one (maybe I could use Xutf8TextExtents?)
86 // Using Xmb and Xwc equivalent methods should work on Interix
87 //
88 #if defined(X_HAVE_UTF8_STRING) || defined(__DOXYGEN__)
89 
90 #define WB_TEXT_EXTENTS Xutf8TextExtents
91 #define WB_TEXT_ESCAPEMENT Xutf8TextEscapement
92 #define WB_DRAW_STRING Xutf8DrawString
93 #define WB_DRAW_TEXT Xutf8DrawText
94 #define WB_LOOKUP_STRING Xutf8LookupString
96 #else // X_HAVE_UTF8_STRING
97 
98 #warning UTF8 not supported, using 'MB' equivalents
99 
100 #define WB_TEXT_EXTENTS XmbTextExtents
101 #define WB_TEXT_ESCAPEMENT XmbTextEscapement
102 #define WB_DRAW_STRING XmbDrawString
103 #define WB_DRAW_TEXT XmbDrawText
104 #define WB_LOOKUP_STRING XmbLookupString
106 #endif // X_HAVE_UTF8_STRING
107 
127 XFontStruct *WBCopyFont(XFontStruct *pFont);
128 
151 XFontStruct *WBLoadFont(Display *pDisplay, const char *szFontName,
152  int iFontSize, int iFlags);
153 
176 XFontStruct *WBLoadModifyFont(Display *pDisplay, const XFontStruct *pOriginal,
177  int iFontSize, int iFlags);
178 
179 
202 XFontSet WBCopyModifyFontSet(Display *pDisplay, XFontSet fsOrig, int iFontSize, int iFlags);
203 
204 
215 int WBFontAvgCharWidth(Display *pDisplay, const XFontStruct *pFont);
216 
217 
229 int WBFontSetDescent(Display *pDisplay, XFontSet fontSet);
230 
231 
243 int WBFontSetAscent(Display *pDisplay, XFontSet fontSet);
244 
245 
257 int WBFontSetHeight(Display *pDisplay, XFontSet fontSet);
258 
259 
271 int WBFontSetAvgCharWidth(Display *pDisplay, XFontSet fontSet);
272 
273 
285 XCharStruct WBFontSetMaxBounds(Display *pDisplay, XFontSet fontSet);
286 
287 
304 XFontSet WBFontSetFromFont(Display *pDisplay, const XFontStruct *pFont);
305 
306 
320 XFontStruct * WBFontFromFontSet(Display *pDisplay, XFontSet fontSet);
321 
322 
343 XFontSet WBFontSetFromFontSingle(Display *pDisplay, const XFontStruct *pFont);
344 
345 
359 int WBTextWidth(XFontSet fontSet, const char *szText, int cbText);
360 
361 
373 void WBDumpFontInfo(const char *pSpec); // debugging function - dumps a list of fonts and info
374 
375 
386 {
392 
399 
405 
406  // if the font size is > 0 then these bits apply
412 
421 
427 
433 
434  // reserved - font registry and encoding (installed X11 fonts typically include most if not all of these)
437  WBFontFlag_REG_ASCII = 0x300000,
439  WBFontFlag_REG_MISC = 0x500000,
441  WBFontFlag_REG_ADOBE = 0x700000,
450  WBFontFlag_REG_MASK = 0xf00000,
451 
452  // TODO: flags for 'encoding' ?
453 
454  WBFontFlag_WHATEVER = 0 // don't force anything (zero, default)
455 };
456 
457 
458 
459 #ifdef __cplusplus
460 };
461 #endif // __cplusplus
462 
463 
464 #endif // _FONT_HELPER_H_INCLUDED_
465 
XFontStruct * WBFontFromFontSet(Display *pDisplay, XFontSet fontSet)
Creates an 'XFontStruct' from the first font assigned to a Font Set.
Definition: font_helper.c:2026
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:409
use a font specific registry (mutually exclusive)
Definition: font_helper.h:438
font size is in 'points' (when font size > 0)
Definition: font_helper.h:408
reserved (style)
Definition: font_helper.h:395
bold font weight (mutually exclusive0
Definition: font_helper.h:417
condensed (alternate to 'fixed')
Definition: font_helper.h:389
reserved reg flag (reserved for future use)
Definition: font_helper.h:445
reserved reg flag (reserved for future use)
Definition: font_helper.h:449
reserved flags for font size > 0
Definition: font_helper.h:410
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:423
int WBTextWidth(XFontSet fontSet, const char *szText, int cbText)
Obtain the pixel width of specified text for a specified XFontSet.
Definition: font_helper.c:2066
semicondensed width (mutually exclusive)
Definition: font_helper.h:429
XFontSet WBFontSetFromFont(Display *pDisplay, const XFontStruct *pFont)
Creates an 'XFontSet' from an XFontStruct for a given display.
Definition: font_helper.c:1749
reserved reg flag (reserved for future use)
Definition: font_helper.h:447
'Any' pitch (default, zero)
Definition: font_helper.h:390
use ADOBE registry (mutually exclusive)
Definition: font_helper.h:440
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:1924
reserved reg flag (reserved for future use)
Definition: font_helper.h:448
font weight bit mask
Definition: font_helper.h:420
reserved reg flag (reserved for future use)
Definition: font_helper.h:442
'foundry mask'
Definition: font_helper.h:404
reserved (style)
Definition: font_helper.h:396
force fixed pitch
Definition: font_helper.h:387
'pitch mask'
Definition: font_helper.h:391
use ADOBE registry - a lot of fonts use this (mutually exclusive)
Definition: font_helper.h:441
medium font weight (mutually exclusive0
Definition: font_helper.h:415
'regular' slant (mutually exclusive)
Definition: font_helper.h:422
regular font weight (mutually exclusive0
Definition: font_helper.h:414
force freetype
Definition: font_helper.h:401
force raster (xfree86?)
Definition: font_helper.h:400
font size is in 'pixels' (when font size > 0)
Definition: font_helper.h:407
reserved reg flag (reserved for future use)
Definition: font_helper.h:444
reserved font weight (6) (not currently in use)
Definition: font_helper.h:419
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:439
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:428
demi-bold font weight (mutually exclusive0
Definition: font_helper.h:416
Any font weight specification (mutually exclusive)
Definition: font_helper.h:413
'size mask' for font size > 0
Definition: font_helper.h:411
force sans-serif
Definition: font_helper.h:393
'italic' slant (mutually exclusive)
Definition: font_helper.h:424
WBFontFlags
Font 'flag' enumeration.
Definition: font_helper.h:385
force serif (i.e. 'not sans')
Definition: font_helper.h:394
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:403
use ISO646-1991 registry (mutually exclusive)
Definition: font_helper.h:436
reserved (foundry)
Definition: font_helper.h:402
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:425
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:437
'Any' width (zero; mutually exclusive)
Definition: font_helper.h:431
reserved reg flag (reserved for future use)
Definition: font_helper.h:446
'Any' style (default, zero)
Definition: font_helper.h:397
'reserved' width type
Definition: font_helper.h:430
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:443
reserved font weight (5) (not currently in use)
Definition: font_helper.h:418
font registry mask
Definition: font_helper.h:450
force variable pitch
Definition: font_helper.h:388
use ISO8859 registry (mutually exclusive)
Definition: font_helper.h:435