4 * Author: Teemu Rantanen <tvr@cs.hut.fi>
5 * Copyright (c) 1992 Teemu Rantanen
8 * Created: Tue Mar 3 02:55:55 1992 tvr
9 * Last modified: Mon May 11 00:16:48 1992 tvr
15 #include <sys/types.h>
21 #include "../HText/HText.h"
24 #include "XlFormatText.h"
28 * Does nothing but updates htext-object positions. This has to be
29 * used after text is reformatted (on window size change).
31 void XlSetPageCoordinates(virtualx, virtualy, htext)
32 int virtualx, virtualy;
35 htext->xl_global->x = virtualx;
36 htext->xl_global->y = virtualy;
41 * Get HTextObject position (virtual position of screen area to display)
43 void XlGetCoordinates(virtualx, virtualy, htextobject)
44 int *virtualx, *virtualy;
45 HTextObject_t *htextobject;
50 *virtualx = htextobject->x;
51 *virtualy = htextobject->y;
56 * Can this object be cursor?
58 int xl_can_be_cursor(htextobject)
59 HTextObject_t *htextobject;
63 if (htextobject->paragraph)
66 for (i = 0; i < htextobject->length; i++)
67 if (htextobject->data[i] != ' ')
75 * Get pointer to hypertextobject nearest to chosen coordinates
78 XlLocateHTextObject(windowx, windowy, htext)
83 HTextObject_t *p_closest = NULL;
89 virtualx = windowx + htext->xl_global->x;
90 virtualy = windowy + htext->xl_global->y;
92 for (p = htext->first; p; p = p->next) {
93 int i = xl_object_on_region(htext, p, windowx, windowy, 0, 0);
95 if (xl_can_be_cursor(p)) {
98 * Point inside object ?
105 * Is this object closest ?
111 } else if (i < distance) {
122 printf("XlLocateHTextObject(%d, %d) -> (%d, %d) tag %s object '%s'\n",
124 p_closest->x, p_closest->y,
125 p_closest->xl_data->style->styletags,
126 p_closest ? p_closest->data : "");
133 * Delete all Xl data from a page. Free all data allocated on Xl-library.
135 void XlDeleteText(htext)
143 for (i = 0; i < htext->xl_global->nr_gcs; i++) {
144 XFreeGC(htext->xl_global->dpy, htext->xl_global->gcs[i]);
145 XFreeFont(htext->xl_global->dpy,
146 htext->xl_global->XlStyles[i].fontinfo);
149 XFreeGC(htext->xl_global->dpy, htext->xl_global->xorgc);
152 * Free data allocated here
167 free(htext->xl_global->XlStyles);
169 free(htext->xl_global->gcs);
171 free(htext->xl_global);
176 * What is the length of this without spaces
178 int xl_nospacelength(p, data, len)
183 if (xl_object_mode(p) & STYLE_RAW) {
190 for (i = 0; (i < len) && (*data++ != ' '); i++);
198 * Set up stuff needed to format text intelligently
200 void XlFormatTextForPrinting(htext, lmargin, rmargin)
207 XlStyle_t *loop = XlStyles;
220 while (loop->fontname) {
227 struct_len = sizeof(XlStyle_t) * i;
229 loop = (XlStyle_t *) malloc(struct_len);
231 htext->xl_global = (XlGlobalData_t *) malloc(sizeof(XlGlobalData_t));
233 htext->xl_global->XlStyles = loop;
235 memcpy(loop, XlStyles, struct_len);
239 loop->char_width = 1;
245 * Set up length and width
256 if (!st || (st != p->style)) {
258 current = (XlStyle_t *) xl_get_style_and_gc(p, NULL, htext);
262 p->xl_data = (XlObjectData_t *) malloc(sizeof(XlObjectData_t));
264 p->xl_data->style = current;
266 p->width = xl_nospacelength(p, p->data, p->length);
271 XlFormatText(lmargin, rmargin - lmargin, 0, &junk1, &junk2, htext);
288 free(htext->xl_global);