1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
|
|
|
/* under the terms of the GNU Library General Public License. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-08 10:04:35 -07:00
|
|
|
#include "libgraph.h"
|
1996-09-03 01:25:04 -07:00
|
|
|
#include <alloc.h>
|
1995-05-08 10:04:35 -07:00
|
|
|
|
|
|
|
XFontStruct * grfont = NULL;
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
static void gr_font(char *fontname)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
|
|
|
XFontStruct * font = XLoadQueryFont(grdisplay, fontname);
|
|
|
|
if (font == NULL) gr_fail("cannot find font %s", fontname);
|
|
|
|
if (grfont != NULL) XFreeFont(grdisplay, grfont);
|
|
|
|
grfont = font;
|
|
|
|
XSetFont(grdisplay, grwindow.gc, grfont->fid);
|
|
|
|
XSetFont(grdisplay, grbstore.gc, grfont->fid);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value gr_set_font(value fontname)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
|
|
|
gr_check_open();
|
|
|
|
gr_font(String_val(fontname));
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1998-09-23 10:28:10 -07:00
|
|
|
value gr_set_text_size (value sz)
|
|
|
|
{
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
static void gr_draw_text(char *txt, int len)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
|
|
|
if (grfont == NULL) gr_font(DEFAULT_FONT);
|
2000-03-13 06:09:28 -08:00
|
|
|
if (grremember_mode)
|
|
|
|
XDrawString(grdisplay, grbstore.win, grbstore.gc,
|
|
|
|
grx, Bcvt(gry) - grfont->descent + 1, txt, len);
|
|
|
|
if (grdisplay_mode) {
|
2000-02-08 06:26:12 -08:00
|
|
|
XDrawString(grdisplay, grwindow.win, grwindow.gc,
|
2000-04-05 11:30:22 -07:00
|
|
|
grx, Wcvt(gry) - grfont->descent + 1, txt, len);
|
2000-02-08 06:26:12 -08:00
|
|
|
XFlush(grdisplay);
|
|
|
|
}
|
1995-05-08 10:04:35 -07:00
|
|
|
grx += XTextWidth(grfont, txt, len);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value gr_draw_char(value chr)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
|
|
|
char str[1];
|
|
|
|
gr_check_open();
|
|
|
|
str[0] = Int_val(chr);
|
|
|
|
gr_draw_text(str, 1);
|
|
|
|
return Val_unit;
|
|
|
|
}
|
2000-02-08 06:26:12 -08:00
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value gr_draw_string(value str)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
|
|
|
gr_check_open();
|
|
|
|
gr_draw_text(String_val(str), string_length(str));
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value gr_text_size(value str)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
|
|
|
int width;
|
|
|
|
value res;
|
|
|
|
gr_check_open();
|
|
|
|
if (grfont == NULL) gr_font(DEFAULT_FONT);
|
|
|
|
width = XTextWidth(grfont, String_val(str), string_length(str));
|
1998-10-26 11:19:32 -08:00
|
|
|
res = alloc_small(2, 0);
|
1995-05-08 10:04:35 -07:00
|
|
|
Field(res, 0) = Val_int(width);
|
|
|
|
Field(res, 1) = Val_int(grfont->ascent + grfont->descent);
|
|
|
|
return res;
|
|
|
|
}
|