1/*
2 * DviP.h - Private definitions for Dvi widget
3 */
4
5#ifndef _XtDviP_h
6#define _XtDviP_h
7
8#ifdef USE_XFT
9#include <X11/Xft/Xft.h>
10#endif
11
12#include "Dvi.h"
13#include <X11/Xaw/SimpleP.h>
14#include "DviChar.h"
15
16/***********************************************************************
17 *
18 * Dvi Widget Private Data
19 *
20 ***********************************************************************/
21
22/************************************
23 *
24 *  Class structure
25 *
26 ***********************************/
27
28/*
29 * New fields for the Dvi widget class record
30 */
31
32typedef struct _DviClass {
33    int makes_compiler_happy;   /* not used */
34} DviClassPart;
35
36/*
37 * Full class record declaration
38 */
39
40typedef struct _DviClassRec {
41    CoreClassPart core_class;
42    SimpleClassPart simple_class;
43    DviClassPart command_class;
44} DviClassRec;
45
46extern DviClassRec dviClassRec;
47
48/***************************************
49 *
50 *  Instance (widget) structure
51 *
52 **************************************/
53
54/*
55 * a list of fonts we've used for this widget
56 */
57
58typedef struct _dviFontSizeList {
59    struct _dviFontSizeList *next;
60    int size;
61    char *x_name;
62#ifdef USE_XFT
63    XftFont *font;
64    Bool core;
65#else
66    XFontStruct *font;
67#endif
68    int doesnt_exist;
69} DviFontSizeList;
70
71typedef struct _dviFontList {
72    struct _dviFontList *next;
73    char *dvi_name;
74    char *x_name;
75    int dvi_number;
76    Boolean initialized;
77    Boolean scalable;
78    DviFontSizeList *sizes;
79    DviCharNameMap *char_map;
80} DviFontList;
81
82typedef struct _dviFontMap {
83    struct _dviFontMap *next;
84    char *dvi_name;
85    char *x_name;
86} DviFontMap;
87
88#define DVI_TEXT_CACHE_SIZE	256
89#define DVI_CHAR_CACHE_SIZE	1024
90
91#ifdef USE_XFT
92typedef struct _dviTextItem {
93    char *chars;
94    int nchars;
95    int x;
96    XftFont *font;
97} DviTextItem;
98#endif
99
100typedef struct _dviCharCache {
101#ifdef USE_XFT
102    DviTextItem cache[DVI_TEXT_CACHE_SIZE];
103#else
104    XTextItem cache[DVI_TEXT_CACHE_SIZE];
105#endif
106    char char_cache[DVI_CHAR_CACHE_SIZE];
107    int index;
108    int max;
109    int char_index;
110    int font_size;
111    int font_number;
112#ifdef USE_XFT
113    XftFont *font;
114#else
115    XFontStruct *font;
116#endif
117    int start_x, start_y;
118    int x, y;
119} DviCharCache;
120
121typedef struct _dviState {
122    struct _dviState *next;
123    int font_size;
124    int font_bound;
125    int font_number;
126    int line_style;
127    int line_width;
128    int x;
129    int y;
130} DviState;
131
132typedef struct _dviFileMap {
133    struct _dviFileMap *next;
134    long position;
135    int page_number;
136} DviFileMap;
137
138/*
139 * New fields for the Dvi widget record
140 */
141
142typedef struct {
143    /*
144     * resource specifiable items
145     */
146    char *font_map_string;
147    unsigned long foreground;
148    int requested_page;
149    int last_page;
150    FILE *file;
151    Boolean seek;               /* file is "seekable" */
152#ifdef USE_XFT
153    XftFont *default_font;
154#else
155    XFontStruct *default_font;
156#endif
157    int backing_store;
158    Boolean noPolyText;
159    int screen_resolution;
160    float page_width;
161    float page_height;
162    int size_scale_set;
163    /*
164     * private state
165     */
166    FILE *tmpFile;              /* used when reading stdin */
167    char readingTmp;            /* reading now from tmp */
168    char ungot;                 /* have ungetc'd a char */
169    GC normal_GC;
170#ifdef USE_XFT
171    XftDraw *draw;
172    XftColor black;
173#endif
174    DviFileMap *file_map;
175    DviFontList *fonts;
176    DviFontMap *font_map;
177    int current_page;
178    int font_size;
179    int font_number;
180    int device_resolution;
181    int line_width;
182    int line_style;
183    int desired_width;
184    int desired_height;
185    int size_scale;             /* font size scale */
186#ifdef USE_XFT
187    XftFont *font;
188#else
189    XFontStruct *font;
190#endif
191    int display_enable;
192    double scale;               /* device coordinates to pixels */
193    struct ExposedExtents {
194        int x1, y1, x2, y2;
195    } extents;
196    DviState *state;
197    DviCharCache cache;
198} DviPart;
199
200extern int DviGetAndPut(DviWidget, int *);
201
202#define DviGetIn(dw,cp)\
203    (dw->dvi.tmpFile ? (\
204	DviGetAndPut (dw, cp) \
205    ) :\
206	(*cp = getc (dw->dvi.file))\
207)
208
209#define DviGetC(dw, cp)\
210    (dw->dvi.readingTmp ? (\
211	((*cp = getc (dw->dvi.tmpFile)) == EOF) ? (\
212	    fseek (dw->dvi.tmpFile, 0l, SEEK_END),\
213	    (dw->dvi.readingTmp = 0),\
214	    DviGetIn (dw,cp)\
215	) : (\
216	    *cp\
217	)\
218    ) : (\
219	DviGetIn(dw,cp)\
220    )\
221)
222
223#define DviUngetC(dw, c)\
224    (dw->dvi.readingTmp ? (\
225	ungetc (c, dw->dvi.tmpFile)\
226    ) : ( \
227	(dw->dvi.ungot = 1),\
228	ungetc (c, dw->dvi.file)))
229
230#define ToX(dw,device)		    ((int) ((device) * (dw)->dvi.scale + 0.5))
231#define ToDevice(dw,x)		    ((int) ((x) / (dw)->dvi.scale + 0.5))
232#define SizeScale(dw)		    ((dw)->dvi.size_scale ? (dw)->dvi.size_scale : 4)
233#define FontSizeInPixels(dw,size)   ((int) ((size) * (dw)->dvi.screen_resolution / (SizeScale(dw) * 72)))
234#define FontSizeInDevice(dw,size)   ((int) ((size) * (dw)->dvi.device_resolution / (SizeScale(dw) * 72)))
235
236/*
237 * Full widget declaration
238 */
239
240typedef struct _DviRec {
241    CorePart core;
242    SimplePart simple;
243    DviPart dvi;
244} DviRec;
245
246/* previously in draw.c */
247static inline void
248HorizontalMove(DviWidget dw, int delta)
249{
250    dw->dvi.state->x += delta;
251}
252
253static inline void
254HorizontalGoto(DviWidget dw, int NewPosition)
255{
256    dw->dvi.state->x = NewPosition;
257}
258
259static inline void
260VerticalMove(DviWidget dw, int delta)
261{
262    dw->dvi.state->y += delta;
263}
264
265static inline void
266VerticalGoto(DviWidget dw, int NewPosition)
267{
268    dw->dvi.state->y = NewPosition;
269}
270
271/* draw.c */
272extern void FlushCharCache(DviWidget);
273extern void SetGCForDraw(DviWidget);
274extern void DrawLine(DviWidget, int, int);
275extern void DrawCircle(DviWidget, int);
276extern void DrawEllipse(DviWidget, int, int);
277extern void DrawArc(DviWidget, int, int, int, int);
278extern void DrawSpline(DviWidget, const char *, int);
279
280/* font.c */
281extern void ParseFontMap(DviWidget);
282extern void DestroyFontMap(DviFontMap *);
283extern void SetFontPosition(DviWidget, int, const char *, const char *);
284
285#ifdef USE_XFT
286extern XftFont *QueryFont(DviWidget, int, int);
287#else
288extern XFontStruct *QueryFont(DviWidget, int, int);
289#endif
290extern DviCharNameMap *QueryFontMap(DviWidget, int);
291
292/* lex.c */
293extern char *GetLine(DviWidget, char *, int);
294extern char *GetWord(DviWidget, char *, int);
295extern int GetNumber(DviWidget);
296
297/* page.c */
298extern void DestroyFileMap(DviFileMap *);
299extern void ForgetPagePositions(DviWidget);
300extern void RememberPagePosition(DviWidget, int);
301extern long SearchPagePosition(DviWidget, int);
302extern void FileSeek(DviWidget, long);
303
304/* parse.c */
305extern int ParseInput(DviWidget);
306
307/* Dvi.c */
308extern void SetDeviceResolution(DviWidget, int);
309
310#endif                          /* _XtDviP_h */
311