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-2019 by Bob Frazier (aka 'Big Bad Bombastic Bob')
18 
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  MIT-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  MIT-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 tagDT_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 tagDT_WORDS
207 {
208  struct tagDT_WORDS *pPrev;
209  struct tagDT_WORDS *pNext;
210  int nCount;
211  int nMax;
212  int iMaxWidth;
214  const char *szText;
216 } DT_WORDS;
217 
218 
219 
241 void DTDrawString(Display *pDisplay, Drawable drawable, WB_FONTC pFont,
242  WBGC gc, int x, int y, const char *pString, int nLength);
243 
244 
246 // * \brief Calculate the ideal font based on the text and rectangle
247 // *
248 // * \param pRefFont A pointer to an XFontStruct (NULL implies system default font)
249 // * \param szText A pointer to a (0-byte terminated) ASCII string that may span multiple lines
250 // * \param geomBounds A pointer to a \ref WB_GEOM structure that defines a bounding rectangle
251 // *
252 // * sometimes you want to adjust text size to fit within a particular rectangle. This function
253 // * determines how to do that by adjusting the font size.
254 // *
255 // * Header File: draw_text.h
256 //**/
257 //XFontStruct *DTCalcIdealFont(XFontStruct *pRefFont, const char *szText, WB_GEOM *geomBounds);
258 
259 
273 WB_FONT DTCalcIdealFont(Display *pDisplay, WB_FONTC pFont, const char *szText, WB_GEOM *geomBounds);
274 
275 
301 int DTCalcIdealBounds0(XFontStruct *pFont, const char *szText, int iTabWidth, unsigned int iTabOrigin,
302  const WB_RECT *prcSource, WB_RECT *prcDest, int iAlignment);
303 
330 int DTCalcIdealBounds(Display *pDisplay, WB_FONTC pFont, const char *szText, int iTabWidth, unsigned int iTabOrigin,
331  const WB_RECT *prcSource, WB_RECT *prcDest, int iAlignment);
332 
355 void DTDrawSingleLineText(WB_FONTC pFontt, const char *szText, Display *pDisplay, WBGC gc, Drawable dw,
356  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
357 
378 void DTDrawMultiLineText(WB_FONTC pFont, const char *szText, Display *pDisplay, WBGC gc, Drawable dw,
379  int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment);
380 
381 
399 DT_WORDS * DTGetWordsFromText(Display *pDisplay, WB_FONTC pFont, const char *szText, int iAlignment);
400 
426 void DTPreRender(Display *pDisplay, WB_FONTC pFont, DT_WORDS *pWords, int iTabWidth, int iTabOrigin,
427  WB_RECT *prcBounds, int iAlignment, int iStartLine, int iEndLine);
428 
448 void DTRender(Display *pDisplay, WB_FONTC pFont, const DT_WORDS *pWords, WBGC gc, Drawable dw,
449  int iHScrollBy, int iVScrollBy, const WB_RECT *prcBounds, const WB_RECT *prcViewport, int iAlignment);
450 
451 #ifdef __cplusplus
452 };
453 #endif // __cplusplus
454 
455 
456 #endif // _DRAW_TEXT_H_INCLUDED_
457 
const char * szText
original text pointer
Definition: draw_text.h:214
int DTCalcIdealBounds(Display *pDisplay, WB_FONTC 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.
Definition: draw_text.c:579
'window helper' main header file for the X11workbench Toolkit API
int iWidth
width of text in pixels (based on font size) (NA for tabs, LF, valid for white space)
Definition: draw_text.h:167
center along the font baseline (single line only)
Definition: draw_text.h:88
internal flag, indicates that an underscore underlines the next character
Definition: draw_text.h:121
int nMax
max number of items in aWords (for memory allocation purposes)
Definition: draw_text.h:211
internal flag, 'single line only' (no line breaks). Implies DTAlignment_NO_WORD_WRAP
Definition: draw_text.h:120
int nCount
number of items in aWords
Definition: draw_text.h:210
top-aligned text (using highest vertical ascent)
Definition: draw_text.h:84
WB_FONT DTCalcIdealFont(Display *pDisplay, WB_FONTC pFont, const char *szText, WB_GEOM *geomBounds)
Calculate the ideal font based on the text and rectangle.
Definition: draw_text.c:277
horizontally centered text. tabs are treated as white space
Definition: draw_text.h:78
internal wrapper struct for X11 'geometry' definition
int iMaxWidth
maximum width of contained text, or -1 if not known
Definition: draw_text.h:212
struct tagDT_WORDS DT_WORDS
A collection of DT_WORD structures along with a pointer to the original text.
void DTDrawSingleLineText(WB_FONTC pFontt, const char *szText, Display *pDisplay, WBGC gc, Drawable dw, int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment)
draw single-line text
Definition: draw_text.c:1531
void DTPreRender(Display *pDisplay, WB_FONTC pFont, DT_WORDS *pWords, int iTabWidth, int iTabOrigin, WB_RECT *prcBounds, int iAlignment, int iStartLine, int iEndLine)
Pre-render a 'DT_WORDS' structure for subsequent display.
Definition: draw_text.c:1745
Structure defining a 'word' for rendering purposes.
Definition: draw_text.h:161
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
A collection of DT_WORD structures along with a pointer to the original text.
Definition: draw_text.h:206
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
Do not shrink the bounding rectangle for ideal text dimension.
Definition: draw_text.h:110
center within the bottom half of the rectangle (single line only)
Definition: draw_text.h:90
DTAlignment
Alignment flags for various 'draw text' API functions.
Definition: draw_text.h:75
int iIsTab
indicates that the text consists of tabs (nLength for number of tabs, pText is NULL)
Definition: draw_text.h:169
int iIsWhiteSpace
indicates that it is 'white space' (regular or special character) (nLength, width,...
Definition: draw_text.h:171
void DTDrawString(Display *pDisplay, Drawable drawable, WB_FONTC pFont, WBGC gc, int x, int y, const char *pString, int nLength)
Draw text in a platform-independent manner for UTF-8 or multi-byte text, equivalent to WBDrawString()...
Definition: draw_text.c:111
struct tagDT_WORD DT_WORD
Structure defining a 'word' for rendering purposes.
int iHeight
height of text in pixels (based on font size) (NA for tabs, LF, valid for white space)
Definition: draw_text.h:168
right-justified text
Definition: draw_text.h:79
DT_WORD aWords[1]
The actual data (self-contained within the memory block)
Definition: draw_text.h:215
internal wrapper struct for 'rectangle' definition
horizontal alignment mask
Definition: draw_text.h:82
struct tagDT_WORDS * pNext
pointer to next structure in linked list (reserved)
Definition: draw_text.h:209
int iY
Relative 'Y' pixel position for the beginning of this element (when pre-rendered, else -1)
Definition: draw_text.h:173
do not increase size vertically
Definition: draw_text.h:100
struct tagDT_WORDS * pPrev
pointer to previous structure in linked list (reserved)
Definition: draw_text.h:208
DT_WORDS * DTGetWordsFromText(Display *pDisplay, WB_FONTC pFont, const char *szText, int iAlignment)
Parse 'DT_WORDS' structure from single-line or multi-line text.
Definition: draw_text.c:365
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
void DTDrawMultiLineText(WB_FONTC pFont, const char *szText, Display *pDisplay, WBGC gc, Drawable dw, int iTabWidth, int iTabOrigin, const WB_RECT *prcBounds, int iAlignment)
draw multi-line text
Definition: draw_text.c:1538
center halfway up the 'ascent' portion (single line only)
Definition: draw_text.h:87
void DTRender(Display *pDisplay, WB_FONTC pFont, const DT_WORDS *pWords, WBGC gc, Drawable dw, int iHScrollBy, int iVScrollBy, const WB_RECT *prcBounds, const WB_RECT *prcViewport, int iAlignment)
Using pre-rendered 'DT_WORDS' structure, display.
Definition: draw_text.c:1791
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
Definition: font_helper.h:152
left-justified text
Definition: draw_text.h:77
internal wrapper struct for GC with local cache
int nLength
length of text element (in bytes)
Definition: draw_text.h:166
const char * pText
Definition: draw_text.h:163
bottom-aligned text (using lowest vertical descent)
Definition: draw_text.h:85
int iX
Relative 'X' pixel position for the beginning of this element (when pre-rendered, else -1)
Definition: draw_text.h:172
int iMaxHeight
maximum height of contained text, or -1 if not known
Definition: draw_text.h:213