summaryrefslogtreecommitdiff
path: root/DviP.h
blob: f06e16dc8bb817e46c5143b88247aae58d204be3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
 * $XConsortium: DviP.h,v 1.10 92/02/11 01:27:15 keith Exp $
 */
/* $XFree86: xc/programs/xditview/DviP.h,v 1.5 2002/06/20 17:40:44 keithp Exp $ */

/* 
 * DviP.h - Private definitions for Dvi widget
 */

#ifndef _XtDviP_h
#define _XtDviP_h

#ifdef USE_XFT
#include <X11/Xft/Xft.h>
#endif

#include "Dvi.h"
#include <X11/Xaw/SimpleP.h>
#include "DviChar.h"

/***********************************************************************
 *
 * Dvi Widget Private Data
 *
 ***********************************************************************/

/************************************
 *
 *  Class structure
 *
 ***********************************/

/*
 * New fields for the Dvi widget class record
 */

typedef struct _DviClass {
	int		makes_compiler_happy;  /* not used */
} DviClassPart;

/*
 * Full class record declaration
 */

typedef struct _DviClassRec {
    CoreClassPart	core_class;
    SimpleClassPart	simple_class;
    DviClassPart	command_class;
} DviClassRec;

extern DviClassRec dviClassRec;

/***************************************
 *
 *  Instance (widget) structure 
 *
 **************************************/

/*
 * a list of fonts we've used for this widget
 */

typedef struct _dviFontSizeList {
	struct _dviFontSizeList	*next;
	int			size;
	char			*x_name;
#ifdef USE_XFT
	XftFont			*font;
	Bool			core;
#else
	XFontStruct		*font;
#endif
	int			doesnt_exist;
} DviFontSizeList;

typedef struct _dviFontList {
	struct _dviFontList	*next;
	char			*dvi_name;
	char			*x_name;
	int			dvi_number;
	Boolean			initialized;
	Boolean			scalable;
	DviFontSizeList		*sizes;
	DviCharNameMap		*char_map;
} DviFontList;

typedef struct _dviFontMap {
	struct _dviFontMap	*next;
	char			*dvi_name;
	char			*x_name;
} DviFontMap;

#define DVI_TEXT_CACHE_SIZE	256
#define DVI_CHAR_CACHE_SIZE	1024

#ifdef USE_XFT
typedef struct _dviTextItem {
	char		*chars;
	int		nchars;
	int		x;
	XftFont		*font;
} DviTextItem;
#endif

typedef struct _dviCharCache {
#ifdef USE_XFT
	DviTextItem	cache[DVI_TEXT_CACHE_SIZE];
#else
	XTextItem	cache[DVI_TEXT_CACHE_SIZE];
#endif
	char		char_cache[DVI_CHAR_CACHE_SIZE];
	int		index;
	int		max;
	int		char_index;
	int		font_size;
	int		font_number;
#ifdef USE_XFT
	XftFont		*font;
#else
	XFontStruct	*font;
#endif
	int		start_x, start_y;
	int		x, y;
} DviCharCache;

typedef struct _dviState {
	struct _dviState	*next;
	int			font_size;
	int			font_bound;
	int			font_number;
	int			line_style;
	int			line_width;
	int			x;
	int			y;
} DviState;

typedef struct _dviFileMap {
	struct _dviFileMap	*next;
	long			position;
	int			page_number;
} DviFileMap;

/*
 * New fields for the Dvi widget record
 */

typedef struct {
	/*
	 * resource specifiable items
	 */
	char		*font_map_string;
	unsigned long	foreground;
	int		requested_page;
	int		last_page;
	FILE		*file;
	Boolean		seek;		/* file is "seekable" */
#ifdef USE_XFT
	XftFont		*default_font;
#else
	XFontStruct	*default_font;
#endif
	int		backing_store;
	Boolean		noPolyText;
	int		screen_resolution;
	float		page_width;
	float		page_height;
	int		size_scale_set;
	/*
 	 * private state
 	 */
	FILE		*tmpFile;	/* used when reading stdin */
	char		readingTmp;	/* reading now from tmp */
	char		ungot;		/* have ungetc'd a char */
	GC		normal_GC;
#ifdef USE_XFT
	XftDraw		*draw;
	XftColor	black;
#endif
	DviFileMap	*file_map;
	DviFontList	*fonts;
	DviFontMap	*font_map;
	int		current_page;
	int		font_size;
	int		font_number;
	int		device_resolution;
	int		line_width;
	int		line_style;
	int		desired_width;
	int		desired_height;
	int		size_scale;	/* font size scale */
#ifdef USE_XFT
	XftFont		*font;
#else
	XFontStruct	*font;
#endif
	int		display_enable;
	double		scale;		/* device coordinates to pixels */
	struct ExposedExtents {
	    int x1, y1, x2, y2;
	}		extents;
	DviState	*state;
	DviCharCache	cache;
} DviPart;

extern int		DviGetAndPut(DviWidget, int *);

#define DviGetIn(dw,cp)\
    (dw->dvi.tmpFile ? (\
	DviGetAndPut (dw, cp) \
    ) :\
	(*cp = getc (dw->dvi.file))\
)

#define DviGetC(dw, cp)\
    (dw->dvi.readingTmp ? (\
	((*cp = getc (dw->dvi.tmpFile)) == EOF) ? (\
	    fseek (dw->dvi.tmpFile, 0l, 2),\
	    (dw->dvi.readingTmp = 0),\
	    DviGetIn (dw,cp)\
	) : (\
	    *cp\
	)\
    ) : (\
	DviGetIn(dw,cp)\
    )\
)

#define DviUngetC(dw, c)\
    (dw->dvi.readingTmp ? (\
	ungetc (c, dw->dvi.tmpFile)\
    ) : ( \
	(dw->dvi.ungot = 1),\
	ungetc (c, dw->dvi.file)))

#define ToX(dw,device)		    ((int) ((device) * (dw)->dvi.scale + 0.5))
#define ToDevice(dw,x)		    ((int) ((x) / (dw)->dvi.scale + 0.5))
#define SizeScale(dw)		    ((dw)->dvi.size_scale ? (dw)->dvi.size_scale : 4)
#define FontSizeInPixels(dw,size)   ((int) ((size) * (dw)->dvi.screen_resolution / (SizeScale(dw) * 72)))
#define FontSizeInDevice(dw,size)   ((int) ((size) * (dw)->dvi.device_resolution / (SizeScale(dw) * 72)))

/*
 * Full widget declaration
 */

typedef struct _DviRec {
    CorePart	core;
    SimplePart	simple;
    DviPart	dvi;
} DviRec;

/* draw.c */
extern void		HorizontalMove(DviWidget, int);
extern void		HorizontalGoto(DviWidget, int);
extern void		VerticalMove(DviWidget, int);
extern void		VerticalGoto(DviWidget, int);
extern void		FlushCharCache(DviWidget);
extern void		SetGCForDraw(DviWidget);
extern void		DrawLine(DviWidget, int, int);
extern void		DrawCircle(DviWidget, int);
extern void		DrawEllipse(DviWidget, int, int);
extern void		DrawArc(DviWidget, int, int, int, int);
extern void		DrawSpline(DviWidget, char *, int);

/* font.c */
extern void		ParseFontMap(DviWidget);
extern void		DestroyFontMap(DviFontMap *);
extern void		SetFontPosition(DviWidget, int, char *, char *);
#ifdef USE_XFT
extern XftFont *	QueryFont(DviWidget, int, int);
#else
extern XFontStruct *	QueryFont(DviWidget, int, int);
#endif
extern DviCharNameMap *	QueryFontMap(DviWidget, int);

/* lex.c */
extern char *		GetLine(DviWidget, char *, int);
extern char *		GetWord(DviWidget, char *, int);
extern int		GetNumber(DviWidget);

/* page.c */
extern void		DestroyFileMap(DviFileMap *);
extern void		ForgetPagePositions(DviWidget);
extern void		RememberPagePosition(DviWidget, int);
extern long		SearchPagePosition(DviWidget, int);
extern void		FileSeek(DviWidget, long);

/* parse.c */
extern int		ParseInput(DviWidget);

/* Dvi.c */
extern void		SetDeviceResolution(DviWidget, int);

#endif /* _XtDviP_h */