4 * Author: Teemu Rantanen <tvr@cs.hut.fi>
5 * Copyright (c) 1992 Teemu Rantanen
8 * Created: Mon Mar 2 22:06:56 1992 tvr
9 * Last modified: Wed May 13 06:44:12 1992 tvr
14 #include <sys/types.h>
20 #include "../HText/HText.h"
25 #include "XlFormatText.h"
29 int xl_junk_object(HTextObject_t * p);
35 xl_get_style_and_gc(p, currentgc, t)
40 XlStyle_t *loop = t->xl_global->XlStyles;
45 while (loop->fontname && strcmp(loop->styletags, p->style->SGMLTag)) {
50 *currentgc = t->xl_global->gcs[loop - t->xl_global->XlStyles];
55 printf("holy mony, style not found\n");
63 * Setup resources for Xl (this can be changed at runtime some day)
65 int XlSetupResources(func)
74 table = (void *) (*func) ((void *) NULL, C_FONTS);
78 for (styles = XlStyles; styles->fontname; styles++) {
79 resource = (char *) (*func) (table, styles->config_name);
83 if (styles->must_free_fontname)
84 free(styles->fontname);
86 styles->must_free_fontname = 1;
88 styles->fontname = (char *) strdup(resource);
90 printf("XlConfigure: %s -> %s\n", styles->config_name, resource);
102 * For every page, setup Xl-stuff (including dpy, for multiple screens)
104 * - Calculate width and height for each object
105 * - Set page display coordinates to (0, 0)
106 * - Delete null space-objects (only spaces on nonraw-mode)
107 * - Something else (uh?)
109 int XlSetupText(display, window, fg, bg, htext)
118 XlStyle_t *s, *s_alloc;
137 * Duplicate Style-structure
146 * NOTE!!! Add one element because of null element at the end !!!
148 struct_length = sizeof(XlStyle_t) * ((s - XlStyles) + 1);
150 s_alloc = s = (XlStyle_t *) malloc(struct_length);
153 printf("cannot malloc on Xl\n");
157 memcpy(s, XlStyles, struct_length);
160 * Load fonts. Note. Fonts should be cached for every display.
162 while (s->fontname) {
164 (XFontStruct *) XLoadQueryFont(display, s->fontname);
167 printf("XlSetup: Cannot load font %s\nXlSetup: trying 'fixed'.\n",
171 (XFontStruct *) XLoadQueryFont(display, "fixed");
174 * Set font up on XlStyles -table so that font wont be tried
178 XlStyle_t *ss = XlStyles + (s - s_alloc);
180 if (ss->must_free_fontname)
183 ss->fontname = (char *) strdup("fixed");
189 printf("XlSetup: Cannot load 'fixed' ... sorry.\n");
201 * Allocate space for page specific Xl data
204 if (!htext->xl_global) {
206 htext->xl_global = (XlGlobalData_t *) malloc(sizeof(XlGlobalData_t));
208 memset(htext->xl_global, 0, sizeof(XlGlobalData_t));
211 htext->xl_global->dpy = display;
213 htext->xl_global->window = window;
215 htext->xl_global->XlStyles = s_alloc;
220 htext->xl_global->xorgc = XCreateGC(htext->xl_global->dpy,
221 htext->xl_global->window,
225 XSetFunction(htext->xl_global->dpy, htext->xl_global->xorgc, GXxor);
227 XSetForeground(htext->xl_global->dpy, htext->xl_global->xorgc, fg ^ bg);
230 htext->xl_global->nr_gcs = s - s_alloc;
232 htext->xl_global->gcs = (GC *) malloc((s - s_alloc) * sizeof(GC));
234 for (s = s_alloc, i = 0; s->fontname; s++, i++) {
236 htext->xl_global->gcs[i] =
237 XCreateGC(htext->xl_global->dpy,
238 htext->xl_global->window, 0, NULL);
240 XSetForeground(htext->xl_global->dpy,
241 htext->xl_global->gcs[i],
244 XSetFont(htext->xl_global->dpy,
245 htext->xl_global->gcs[i],
248 s->char_width = (int) XTextWidth(s->fontinfo, "i", 1);
252 * Set up graphics exposures to XCopyArea GC
254 XSetGraphicsExposures(display, htext->xl_global->gcs[0], True);
264 * Allocate space for Xl specific object part
267 p->xl_data = (XlObjectData_t *) malloc(sizeof(XlObjectData_t));
270 printf("cannot malloc in XlSetupText\n");
273 memset(p->xl_data, 0, sizeof(XlObjectData_t));
276 * Setup Xl styles. Check Xl style only on style changes
278 if (!st || (st != p->style)) {
280 current = xl_get_style_and_gc(p, ¤tgc, htext);
284 p->xl_data->style = current;
286 p->xl_data->gc = currentgc;
289 * Set up text dimensions. Use 'XTextExtents()'.
291 p->width = (int) XTextWidth(current->fontinfo,
292 (const char *) p->data,
295 p->height = current->fontinfo->ascent + current->fontinfo->descent;
302 * Check if this object is 'junk'-object and delete it if needed.
303 * Has to be here, because we need styles.
305 if (xl_junk_object(p)) {
306 HTextObject_t *prev = p->prev;
313 prev->next = p->next;
317 htext->first = p->next;
323 p->next->prev = prev;
332 * Free everything allocated
354 * If this object is not needed, it is 'junk' -object
356 int xl_junk_object(p)
364 if (xl_object_mode(p) & STYLE_RAW)
367 for (i = 0; i < p->length; i++)
368 if (p->data[i] != ' ')