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 */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../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
|
|
|
|
2004-03-24 07:02:06 -08:00
|
|
|
XFontStruct * caml_gr_font = NULL;
|
1995-05-08 10:04:35 -07:00
|
|
|
|
2004-03-24 07:02:06 -08:00
|
|
|
static void caml_gr_get_font(char *fontname)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
2004-03-24 07:02:06 -08:00
|
|
|
XFontStruct * font = XLoadQueryFont(caml_gr_display, fontname);
|
|
|
|
if (font == NULL) caml_gr_fail("cannot find font %s", fontname);
|
|
|
|
if (caml_gr_font != NULL) XFreeFont(caml_gr_display, caml_gr_font);
|
|
|
|
caml_gr_font = font;
|
|
|
|
XSetFont(caml_gr_display, caml_gr_window.gc, caml_gr_font->fid);
|
|
|
|
XSetFont(caml_gr_display, caml_gr_bstore.gc, caml_gr_font->fid);
|
1995-05-08 10:04:35 -07:00
|
|
|
}
|
|
|
|
|
2004-03-24 07:02:06 -08:00
|
|
|
value caml_gr_set_font(value fontname)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
2004-03-24 07:02:06 -08:00
|
|
|
caml_gr_check_open();
|
|
|
|
caml_gr_get_font(String_val(fontname));
|
1995-05-08 10:04:35 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2004-03-24 07:02:06 -08:00
|
|
|
value caml_gr_set_text_size (value sz)
|
1998-09-23 10:28:10 -07:00
|
|
|
{
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2004-03-24 07:02:06 -08:00
|
|
|
static void caml_gr_draw_text(char *txt, int len)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
2004-03-24 07:02:06 -08:00
|
|
|
if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
|
|
|
|
if (caml_gr_remember_modeflag)
|
|
|
|
XDrawString(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc,
|
|
|
|
caml_gr_x, Bcvt(caml_gr_y) - caml_gr_font->descent + 1, txt, len);
|
|
|
|
if (caml_gr_display_modeflag) {
|
|
|
|
XDrawString(caml_gr_display, caml_gr_window.win, caml_gr_window.gc,
|
|
|
|
caml_gr_x, Wcvt(caml_gr_y) - caml_gr_font->descent + 1, txt, len);
|
|
|
|
XFlush(caml_gr_display);
|
2000-02-08 06:26:12 -08:00
|
|
|
}
|
2004-03-24 07:02:06 -08:00
|
|
|
caml_gr_x += XTextWidth(caml_gr_font, txt, len);
|
1995-05-08 10:04:35 -07:00
|
|
|
}
|
|
|
|
|
2004-03-24 07:02:06 -08:00
|
|
|
value caml_gr_draw_char(value chr)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
|
|
|
char str[1];
|
2004-03-24 07:02:06 -08:00
|
|
|
caml_gr_check_open();
|
1995-05-08 10:04:35 -07:00
|
|
|
str[0] = Int_val(chr);
|
2004-03-24 07:02:06 -08:00
|
|
|
caml_gr_draw_text(str, 1);
|
1995-05-08 10:04:35 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
2000-02-08 06:26:12 -08:00
|
|
|
|
2004-03-24 07:02:06 -08:00
|
|
|
value caml_gr_draw_string(value str)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
2004-03-24 07:02:06 -08:00
|
|
|
caml_gr_check_open();
|
|
|
|
caml_gr_draw_text(String_val(str), string_length(str));
|
1995-05-08 10:04:35 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2004-03-24 07:02:06 -08:00
|
|
|
value caml_gr_text_size(value str)
|
1995-05-08 10:04:35 -07:00
|
|
|
{
|
|
|
|
int width;
|
|
|
|
value res;
|
2004-03-24 07:02:06 -08:00
|
|
|
caml_gr_check_open();
|
|
|
|
if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
|
|
|
|
width = XTextWidth(caml_gr_font, 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);
|
2004-03-24 07:02:06 -08:00
|
|
|
Field(res, 1) = Val_int(caml_gr_font->ascent + caml_gr_font->descent);
|
1995-05-08 10:04:35 -07:00
|
|
|
return res;
|
|
|
|
}
|