1 /*
2 
3 Copyright 1993, 1998  The Open Group
4 
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10 
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
25 from The Open Group.
26 
27 */
28 
29 #ifndef _FontGridP_h_
30 #define _FontGridP_h_
31 
32 #include "grid.h"
33 
34 typedef struct _FontGridClassPart { int dummy; } FontGridClassPart;
35 
36 typedef struct _FontGridClassRec {
37     CoreClassPart	core_class;
38     SimpleClassPart	simple_class;
39     FontGridClassPart	grid_class;
40 } FontGridClassRec;
41 extern FontGridClassRec fontgridClassRec;
42 
43 typedef 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 
68 typedef 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