X11 Work Bench 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-2016 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_SINGLELINE = 0x20000000,
120  DTAlignment_UNDERSCORE = 0x40000000,
121  DTAlignment_PRINTING = 0x80000000
122 };
124 
125 
160 typedef struct __DT_WORD__
161 {
162  const char *pText;
163  int nLength;
166  int iWidth;
167  int iHeight;
168  int iIsTab;
171  int iX;
172  int iY;
173 } DT_WORD;
174 
175 
205 typedef struct __DT_WORDS__
206 {
207  struct __DT_WORDS__ *pPrev;
208  struct __DT_WORDS__ *pNext;
209  int nCount;
210  int nMax;
211  int iMaxWidth;
213  const char *szText;
215 } DT_WORDS;
216 
217 
218 
231 int DTGetTextWidth(XFontSet fontSet, const char *szUTF8, int nLength);
232 
233 
246 XFontStruct *DTCalcIdealFont(XFontStruct *pRefFont, const char *szText, WB_GEOM *geomBounds);
247 
248 
262 XFontSet DTCalcIdealFontSet(Display *pDisplay, XFontSet fontSet, const char *szText, WB_GEOM *geomBounds);
263 
264 
290 int DTCalcIdealBounds0(XFontStruct *pFont, const char *szText, int iTabWidth, unsigned int iTabOrigin,
291  const WB_RECT *prcSource, WB_RECT *prcDest, int iAlignment);
292 
319 int DTCalcIdealBounds(Display *pDisplay, XFontSet fontSet, const char *szText, int iTabWidth, unsigned int iTabOrigin,
320  const WB_RECT *prcSource, WB_RECT *prcDest, int iAlignment);
321 
344 void DTDrawSingleLineText0(XFontStruct *pFont, const char *szText, Display *pDisplay, GC gc, Drawable dw,
345  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
346 
369 void DTDrawSingleLineText(XFontSet fontSet, const char *szText, Display *pDisplay, GC gc, Drawable dw,
370  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
371 
392 void DTDrawMultiLineText0(XFontStruct *pFont, const char *szText, Display *pDisplay, GC gc, Drawable dw,
393  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
394 
415 void DTDrawMultiLineText(XFontSet fontSet, const char *szText, Display *pDisplay, GC gc, Drawable dw,
416  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
417 
418 
435 DT_WORDS * DTGetWordsFromText0(XFontStruct *pFont, const char *szText, int iAlignment);
436 
454 DT_WORDS * DTGetWordsFromText(Display *pDisplay, XFontSet fontSet, const char *szText, int iAlignment);
455 
481 void DTPreRender(Display *pDisplay, XFontSet fontSet, DT_WORDS *pWords, int iTabWidth, int iTabOrigin,
482  WB_RECT *prcBounds, int iAlignment, int iStartLine, int iEndLine);
483 
503 void DTRender(Display *pDisplay, XFontSet fontSet, const DT_WORDS *pWords, GC gc, Drawable dw,
504  int iHScrollBy, int iVScrollBy, const WB_RECT *prcBounds, const WB_RECT *prcViewport, int iAlignment);
505 
506 #ifdef __cplusplus
507 };
508 #endif // __cplusplus
509 
510 
511 #endif // _DRAW_TEXT_H_INCLUDED_
512 
int iWidth
width of text in pixels (based on font size) (NA for tabs, LF, valid for white space) ...
Definition: draw_text.h:166
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:1561
&#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:170
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:1255
int iIsTab
indicates that the text consists of tabs (nLength for number of tabs, pText is NULL) ...
Definition: draw_text.h:168
DT_WORD aWords[1]
The actual data (self-contained within the memory block)
Definition: draw_text.h:214
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:266
const char * pText
Definition: draw_text.h:162
internal flag, indicates that an underscore underlines the next character
Definition: draw_text.h:120
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:1282
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:180
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:503
internal flag, &#39;single line only&#39; (no line breaks). Implies DTAlignment_NO_WORD_WRAP ...
Definition: draw_text.h:119
top-aligned text (using highest vertical ascent)
Definition: draw_text.h:84
const char * szText
original text pointer
Definition: draw_text.h:213
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:169
int iX
Relative &#39;X&#39; pixel position for the beginning of this element (when pre-rendered, else -1) ...
Definition: draw_text.h:171
struct __DT_WORDS__ DT_WORDS
A collection of DT_WORD structures along with a pointer to the original text.
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:208
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:209
struct __DT_WORDS__ * pPrev
pointer to previous structure in linked list (reserved)
Definition: draw_text.h:207
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:134
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:1338
int iHeight
height of text in pixels (based on font size) (NA for tabs, LF, valid for white space) ...
Definition: draw_text.h:167
internal wrapper struct for &#39;rectangle&#39; definition
int nMax
max number of items in aWords (for memory allocation purposes)
Definition: draw_text.h:210
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:1515
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:289
A collection of DT_WORD structures along with a pointer to the original text.
Definition: draw_text.h:205
horizontal alignment mask
Definition: draw_text.h:82
int iMaxWidth
maximum width of contained text, or -1 if not known
Definition: draw_text.h:211
do not increase size vertically
Definition: draw_text.h:100
int iY
Relative &#39;Y&#39; pixel position for the beginning of this element (when pre-rendered, else -1) ...
Definition: draw_text.h:172
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:1309
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:212
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:166
int nLength
length of text element (in bytes)
Definition: draw_text.h:165
Structure defining a &#39;word&#39; for rendering purposes.
Definition: draw_text.h:160