gridP.h revision 1afad795
1/*
2
3Copyright 1993, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included
12in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall
23not be used in advertising or otherwise to promote the sale, use or
24other dealings in this Software without prior written authorization
25from The Open Group.
26
27*/
28
29#ifndef _FontGridP_h_
30#define _FontGridP_h_
31
32#include "grid.h"
33
34typedef struct _FontGridClassPart { int dummy; } FontGridClassPart;
35
36typedef struct _FontGridClassRec {
37    CoreClassPart	core_class;
38    SimpleClassPart	simple_class;
39    FontGridClassPart	grid_class;
40} FontGridClassRec;
41extern FontGridClassRec fontgridClassRec;
42
43typedef struct _FontGridPart {
44    XFontStruct *	text_font;		/* font to display */
45    int			cell_cols, cell_rows;  /* number of cells */
46    int			cell_width, cell_height;  /* size of cell */
47#ifndef XRENDER
48    Pixel		foreground_pixel;	/* color of text */
49#endif
50    Pixel		box_pixel;	/* for box_chars */
51    Boolean		center_chars;	/* center characters in grid */
52    Boolean		box_chars;	/* put box around logical width */
53    XtCallbackList	callbacks;	/* for notifying caller */
54    int			internal_pad;	/* extra padding inside grid */
55    long		start_char;	/* first character of grid */
56    int			grid_width;	/* width of grid lines */
57    /* private data */
58    GC			text_gc;	/* printing text */
59    GC			box_gc;		/* for box_chars */
60    int			xoff, yoff;	/* extra offsets within grid */
61#ifdef XRENDER
62    XftDraw		*draw;
63    XftColor		fg_color;
64    XftFont		*text_face;
65#endif
66} FontGridPart;
67
68typedef struct _FontGridRec {
69    CorePart		core;
70    SimplePart		simple;
71    FontGridPart	fontgrid;
72} FontGridRec;
73
74#ifdef XRENDER
75
76#define GridFontHeight(g)   ((g)->fontgrid.text_face ? \
77			     (g)->fontgrid.text_face->height : \
78			     (g)->fontgrid.text_font ? \
79			     (g)->fontgrid.text_font->ascent + \
80			     (g)->fontgrid.text_font->descent : 1)
81#define GridFontAscent(g)   ((g)->fontgrid.text_face ? \
82			     (g)->fontgrid.text_face->ascent : \
83			     (g)->fontgrid.text_font ? \
84			     (g)->fontgrid.text_font->ascent: 1)
85#define GridFontWidth(g)    ((g)->fontgrid.text_face ? \
86			     (g)->fontgrid.text_face->max_advance_width : \
87			     (g)->fontgrid.text_font ? \
88			     (g)->fontgrid.text_font->max_bounds.width : 1)
89#define GridForeground(g)   ((g)->fontgrid.fg_color.pixel)
90
91#else /* XRENDER */
92
93#define GridFontHeight(g)   ((g)->fontgrid.text_font->ascent + \
94			     (g)->fontgrid.text_font->descent)
95#define GridFontAscent(g)   ((g)->fontgrid.text_font ? \
96			     (g)->fontgrid.text_font->ascent: 1)
97#define GridFontWidth(g)    ((g)->fontgrid.text_font->max_bounds.width)
98#define GridForeground(g)   ((g)->fontgrid.foreground_pixel)
99
100#endif /* else XRENDER */
101
102#define DefaultCellWidth(fgw) (GridFontWidth(fgw) \
103			       + ((fgw)->fontgrid.internal_pad * 2))
104#define DefaultCellHeight(fgw) (GridFontHeight(fgw) + \
105				((fgw)->fontgrid.internal_pad * 2))
106
107#define CellWidth(fgw) (((int)(fgw)->core.width - (fgw)->fontgrid.grid_width) \
108			/ (fgw)->fontgrid.cell_cols \
109			- (fgw)->fontgrid.grid_width)
110#define CellHeight(fgw) (((int)(fgw)->core.height - (fgw)->fontgrid.grid_width)\
111			 / (fgw)->fontgrid.cell_rows \
112			 - (fgw)->fontgrid.grid_width)
113
114#endif /* !_FontGridP_h_ */
115