X11workbench Toolkit  1.0
draw_text.h
Go to the documentation of this file.
1 // _ _ _ _ //
3 // __| | _ __ __ _ __ __ | |_ ___ __ __| |_ | |__ //
4 // / _` || '__|/ _` |\ \ /\ / / | __|/ _ \\ \/ /| __| | '_ \ //
5 // | (_| || | | (_| | \ V V / | |_| __/ > < | |_ _ | | | | //
6 // \__,_||_| \__,_| \_/\_/_____\__|\___|/_/\_\ \__|(_)|_| |_| //
7 // |_____| //
8 // //
9 // text draw, multi-line and tabbed text //
10 // Also, additional text-related utilities //
11 // //
13 
14 /*****************************************************************************
15 
16  X11workbench - X11 programmer's 'work bench' application and toolkit
17  Copyright (c) 2010-2018 by Bob Frazier (aka 'Big Bad Bombastic Bob')
18  all rights reserved
19 
20  DISCLAIMER: The X11workbench application and toolkit software are supplied
21  'as-is', with no warranties, either implied or explicit.
22  Any claims to alleged functionality or features should be
23  considered 'preliminary', and might not function as advertised.
24 
25  BSD-like license:
26 
27  There is no restriction as to what you can do with this software, so long
28  as you include the above copyright notice and DISCLAIMER for any distributed
29  work that is equal to or derived from this one, along with this paragraph
30  that explains the terms of the license if the source is also being made
31  available. A "derived work" describes a work that uses a significant portion
32  of the source files or algorithms that are included with this one.
33  Specifically excluded from this are files that were generated by the software,
34  or anything that is included with the software that is part of another package
35  (such as files that were created or added during the 'configure' process).
36  Specifically included is the use of part or all of any of the X11 workbench
37  toolkit source or header files in your distributed application. If you do not
38  ship the source, the above copyright statement is still required to be placed
39  in a reasonably prominent place, such as documentation, splash screens, and/or
40  'about the application' dialog boxes.
41 
42  Use and distribution are in accordance with GPL, LGPL, and/or the above
43  BSD-like license. See COPYING and README files for more information.
44 
45 
46  Additional information at http://sourceforge.net/projects/X11workbench
47 
48 ******************************************************************************/
49 
50 
58 #ifndef _DRAW_TEXT_H_INCLUDED_
59 #define _DRAW_TEXT_H_INCLUDED_
60 
61 #ifndef WINDOW_HELPER_H_INCLUDED
62 #include "window_helper.h"
63 #endif // WINDOW_HELPER_H_INCLUDED
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif // __cplusplus
68 
69 
76 {
81  DTAlignment_HMASK = 0xf,
83 
91  DTAlignment_VMASK = 0xf0,
92 
93  // these next flags are primarily for DTCalcIdealBounds, and some for DTCalcIdealFont
94 
96  DTAlignment_NO_VRESIZE = 0x200,
103 
108  DTAlignment_NO_SHRINK = 0x1000,
111 
113  DTAlignment_NO_WORD_WRAP = 0x4000,
116 
119  DTAlignment_ANTIALIAS = 0x10000000,
120  DTAlignment_SINGLELINE = 0x20000000,
121  DTAlignment_UNDERSCORE = 0x40000000,
122  DTAlignment_PRINTING = 0x80000000
123 };
125 
126 
161 typedef struct __DT_WORD__
162 {
163  const char *pText;
164  int nLength;
167  int iWidth;
168  int iHeight;
169  int iIsTab;
172  int iX;
173  int iY;
174 } DT_WORD;
175 
176 
206 typedef struct __DT_WORDS__
207 {
208  struct __DT_WORDS__ *pPrev;
209  struct __DT_WORDS__ *pNext;
210  int nCount;
211  int nMax;
212  int iMaxWidth;
214  const char *szText;
216 } DT_WORDS;
217 
218 
219 
240 void DTDrawString(Display *pDisplay, Drawable drawable, XFontSet fontSet,
241  GC gc, int x, int y, const char *pString, int nLength);
242 
243 
258 int DTGetTextWidth(XFontSet fontSet, const char *szUTF8, int nLength);
259 
274 void DTGetTextExtent(XFontSet fontSet, const char *szUTF8, int nLength, WB_EXTENT *pExtent);
275 
276 
289 XFontStruct *DTCalcIdealFont(XFontStruct *pRefFont, const char *szText, WB_GEOM *geomBounds);
290 
291 
305 XFontSet DTCalcIdealFontSet(Display *pDisplay, XFontSet fontSet, const char *szText, WB_GEOM *geomBounds);
306 
307 
333 int DTCalcIdealBounds0(XFontStruct *pFont, const char *szText, int iTabWidth, unsigned int iTabOrigin,
334  const WB_RECT *prcSource, WB_RECT *prcDest, int iAlignment);
335 
362 int DTCalcIdealBounds(Display *pDisplay, XFontSet fontSet, const char *szText, int iTabWidth, unsigned int iTabOrigin,
363  const WB_RECT *prcSource, WB_RECT *prcDest, int iAlignment);
364 
387 void DTDrawSingleLineText0(XFontStruct *pFont, const char *szText, Display *pDisplay, GC gc, Drawable dw,
388  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
389 
412 void DTDrawSingleLineText(XFontSet fontSet, const char *szText, Display *pDisplay, GC gc, Drawable dw,
413  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
414 
435 void DTDrawMultiLineText0(XFontStruct *pFont, const char *szText, Display *pDisplay, GC gc, Drawable dw,
436  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
437 
458 void DTDrawMultiLineText(XFontSet fontSet, const char *szText, Display *pDisplay, GC gc, Drawable dw,
459  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
460 
461 
478 DT_WORDS * DTGetWordsFromText0(XFontStruct *pFont, const char *szText, int iAlignment);
479 
497 DT_WORDS * DTGetWordsFromText(Display *pDisplay, XFontSet fontSet, const char *szText, int iAlignment);
498 
524 void DTPreRender(Display *pDisplay, XFontSet fontSet, DT_WORDS *pWords, int iTabWidth, int iTabOrigin,
525  WB_RECT *prcBounds, int iAlignment, int iStartLine, int iEndLine);
526 
546 void DTRender(Display *pDisplay, XFontSet fontSet, const DT_WORDS *pWords, GC gc, Drawable dw,
547  int iHScrollBy, int iVScrollBy, const WB_RECT *prcBounds, const WB_RECT *prcViewport, int iAlignment);
548 
549 #ifdef __cplusplus
550 };
551 #endif // __cplusplus
552 
553 
554 #endif // _DRAW_TEXT_H_INCLUDED_
555 
internal wrapper struct for &#39;extent&#39; definition
int iWidth
width of text in pixels (based on font size) (NA for tabs, LF, valid for white space) ...
Definition: draw_text.h:167
void DTRender(Display *pDisplay, XFontSet fontSet, const DT_WORDS *pWords, GC gc, Drawable dw, int iHScrollBy, int iVScrollBy, const WB_RECT *prcBounds, const WB_RECT *prcViewport, int iAlignment)
Using pre-rendered &#39;DT_WORDS&#39; structure, display.
Definition: draw_text.c:1831
&#39;window helper&#39; main header file for the X11workbench Toolkit API
int iIsWhiteSpace
indicates that it is &#39;white space&#39; (regular or special character) (nLength, width, height applies)
Definition: draw_text.h:171
void DTDrawSingleLineText0(XFontStruct *pFont, const char *szText, Display *pDisplay, GC gc, Drawable dw, int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment)
draw single-line text
Definition: draw_text.c:1506
int iIsTab
indicates that the text consists of tabs (nLength for number of tabs, pText is NULL) ...
Definition: draw_text.h:169
DT_WORD aWords[1]
The actual data (self-contained within the memory block)
Definition: draw_text.h:215
center along the font baseline (single line only)
Definition: draw_text.h:88
DT_WORDS * DTGetWordsFromText0(XFontStruct *pFont, const char *szText, int iAlignment)
Parse &#39;DT_WORDS&#39; structure from single-line or multi-line text.
Definition: draw_text.c:364
const char * pText
Definition: draw_text.h:163
internal flag, indicates that an underscore underlines the next character
Definition: draw_text.h:121
void DTDrawSingleLineText(XFontSet fontSet, const char *szText, Display *pDisplay, GC gc, Drawable dw, int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment)
draw single-line text
Definition: draw_text.c:1533
XFontSet DTCalcIdealFontSet(Display *pDisplay, XFontSet fontSet, const char *szText, WB_GEOM *geomBounds)
Calculate the ideal font based on the text and rectangle.
Definition: draw_text.c:278
int DTCalcIdealBounds(Display *pDisplay, XFontSet fontSet, const char *szText, int iTabWidth, unsigned int iTabOrigin, const WB_RECT *prcSource, WB_RECT *prcDest, int iAlignment)
Calculate the ideal bounding rectangle for the specified text and font.
Definition: draw_text.c:601
internal flag, &#39;single line only&#39; (no line breaks). Implies DTAlignment_NO_WORD_WRAP ...
Definition: draw_text.h:120
top-aligned text (using highest vertical ascent)
Definition: draw_text.h:84
const char * szText
original text pointer
Definition: draw_text.h:214
horizontally centered text. tabs are treated as white space
Definition: draw_text.h:78
int iIsLineFeed
indicates a line feed (CR, CRLF, LF, or LFCR) (nLength for number of line feeds, pText is NULL) ...
Definition: draw_text.h:170
int iX
Relative &#39;X&#39; pixel position for the beginning of this element (when pre-rendered, else -1) ...
Definition: draw_text.h:172
struct __DT_WORDS__ DT_WORDS
A collection of DT_WORD structures along with a pointer to the original text.
internal flag, applies simple anti-aliasing. See WBSimpleAntiAliasImage() and WBSimpleAntiAliasPixmap...
Definition: draw_text.h:119
do not increase size horizontally
Definition: draw_text.h:101
center using entire text height (ascent + descent for single line)
Definition: draw_text.h:86
int DTCalcIdealBounds0(XFontStruct *pFont, const char *szText, int iTabWidth, unsigned int iTabOrigin, const WB_RECT *prcSource, WB_RECT *prcDest, int iAlignment)
Calculate the ideal bounding rectangle for the specified text and font.
center within the top half of the rectangle (single line only)
Definition: draw_text.h:89
struct __DT_WORDS__ * pNext
pointer to next structure in linked list (reserved)
Definition: draw_text.h:209
Do not shrink the bounding rectangle for ideal text dimension.
Definition: draw_text.h:110
int nCount
number of items in aWords
Definition: draw_text.h:210
struct __DT_WORDS__ * pPrev
pointer to previous structure in linked list (reserved)
Definition: draw_text.h:208
center within the bottom half of the rectangle (single line only)
Definition: draw_text.h:90
DTAlignment
Alignment flags for various &#39;draw text&#39; API functions.
Definition: draw_text.h:75
int DTGetTextWidth(XFontSet fontSet, const char *szUTF8, int nLength)
XTextWidth equivalent for MBCS and UTF-8 strings.
Definition: draw_text.c:215
void DTDrawMultiLineText(XFontSet fontSet, const char *szText, Display *pDisplay, GC gc, Drawable dw, int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment)
draw multi-line text
Definition: draw_text.c:1589
int iHeight
height of text in pixels (based on font size) (NA for tabs, LF, valid for white space) ...
Definition: draw_text.h:168
internal wrapper struct for &#39;rectangle&#39; definition
int nMax
max number of items in aWords (for memory allocation purposes)
Definition: draw_text.h:211
struct __DT_WORD__ DT_WORD
Structure defining a &#39;word&#39; for rendering purposes.
right-justified text
Definition: draw_text.h:79
void DTPreRender(Display *pDisplay, XFontSet fontSet, DT_WORDS *pWords, int iTabWidth, int iTabOrigin, WB_RECT *prcBounds, int iAlignment, int iStartLine, int iEndLine)
Pre-render a &#39;DT_WORDS&#39; structure for subsequent display.
Definition: draw_text.c:1785
DT_WORDS * DTGetWordsFromText(Display *pDisplay, XFontSet fontSet, const char *szText, int iAlignment)
Parse &#39;DT_WORDS&#39; structure from single-line or multi-line text.
Definition: draw_text.c:387
A collection of DT_WORD structures along with a pointer to the original text.
Definition: draw_text.h:206
horizontal alignment mask
Definition: draw_text.h:82
int iMaxWidth
maximum width of contained text, or -1 if not known
Definition: draw_text.h:212
do not increase size vertically
Definition: draw_text.h:100
void DTDrawString(Display *pDisplay, Drawable drawable, XFontSet fontSet, GC gc, int x, int y, const char *pString, int nLength)
Draw text in a platform-independent manner for UTF-8 or multi-byte text.
Definition: draw_text.c:109
void DTGetTextExtent(XFontSet fontSet, const char *szUTF8, int nLength, WB_EXTENT *pExtent)
XTextExtent equivalent for MBCS and UTF-8 strings.
Definition: draw_text.c:243
int iY
Relative &#39;Y&#39; pixel position for the beginning of this element (when pre-rendered, else -1) ...
Definition: draw_text.h:173
void DTDrawMultiLineText0(XFontStruct *pFont, const char *szText, Display *pDisplay, GC gc, Drawable dw, int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment)
draw multi-line text
Definition: draw_text.c:1560
center halfway up the &#39;ascent&#39; portion (single line only)
Definition: draw_text.h:87
left-justified text
Definition: draw_text.h:77
int iMaxHeight
maximum height of contained text, or -1 if not known
Definition: draw_text.h:213
bottom-aligned text (using lowest vertical descent)
Definition: draw_text.h:85
internal wrapper struct for X11 &#39;geometry&#39; definition
XFontStruct * DTCalcIdealFont(XFontStruct *pRefFont, const char *szText, WB_GEOM *geomBounds)
Calculate the ideal font based on the text and rectangle.
Definition: draw_text.c:264
int nLength
length of text element (in bytes)
Definition: draw_text.h:166
Structure defining a &#39;word&#39; for rendering purposes.
Definition: draw_text.h:161