2003-03-10 21:47:38 -05:00
|
|
|
/* Copyright 2001-2003 by Norbert Freudemann, David Frese */
|
2001-07-18 11:44:41 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
#include "xlib.h"
|
2001-07-18 11:44:41 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Load_Font(s48_value display, s48_value font_name) {
|
|
|
|
return scx_enter_font(XLoadFont(scx_extract_display(display),
|
|
|
|
s48_extract_string(font_name)));
|
2001-07-18 11:44:41 -04:00
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Unload_Font(s48_value display, s48_value font) {
|
|
|
|
XUnloadFont(scx_extract_display(display),
|
|
|
|
scx_extract_font(font));
|
2001-07-18 11:44:41 -04:00
|
|
|
return S48_UNSPECIFIC;
|
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Query_Font(s48_value display, s48_value font) {
|
|
|
|
XFontStruct* fs = XQueryFont(scx_extract_display(display),
|
|
|
|
scx_extract_font(font));
|
|
|
|
if (fs == NULL)
|
|
|
|
return S48_FALSE;
|
|
|
|
else
|
|
|
|
return scx_enter_fontstruct(fs);
|
2001-07-18 11:44:41 -04:00
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Load_Query_Font(s48_value display, s48_value font_name) {
|
|
|
|
XFontStruct* fs = XLoadQueryFont(scx_extract_display(display),
|
|
|
|
s48_extract_string(font_name));
|
|
|
|
if (fs == NULL)
|
|
|
|
return S48_FALSE;
|
|
|
|
else
|
|
|
|
return scx_enter_fontstruct(fs);
|
2001-07-18 11:44:41 -04:00
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Free_Font(s48_value display, s48_value fontstruct) {
|
|
|
|
XFreeFont(scx_extract_display(display),
|
|
|
|
scx_extract_fontstruct(fontstruct));
|
|
|
|
return S48_UNSPECIFIC;
|
2001-10-09 11:42:26 -04:00
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_List_Fonts(s48_value display, s48_value pattern, s48_value max) {
|
|
|
|
s48_value res = S48_NULL;
|
|
|
|
int i, count;
|
|
|
|
char** fonts;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-07-18 11:44:41 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
fonts = XListFonts(scx_extract_display(display), s48_extract_string(pattern),
|
|
|
|
s48_extract_integer(max), &count);
|
|
|
|
S48_GC_PROTECT_1(res);
|
|
|
|
for (i = count; i > 0; i--)
|
|
|
|
res = s48_cons(s48_enter_string(fonts[i-1]), res);
|
2001-07-18 11:44:41 -04:00
|
|
|
S48_GC_UNPROTECT();
|
2003-03-10 21:47:38 -05:00
|
|
|
XFreeFontNames(fonts);
|
|
|
|
return res;
|
|
|
|
}
|
2001-07-18 11:44:41 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_List_Fonts_With_Info(s48_value display, s48_value pattern,
|
|
|
|
s48_value max) {
|
|
|
|
s48_value res = S48_NULL, cell = S48_NULL;
|
|
|
|
int i, count;
|
|
|
|
char** fonts;
|
|
|
|
XFontStruct* infos;
|
|
|
|
S48_DECLARE_GC_PROTECT(2);
|
|
|
|
|
|
|
|
fonts = XListFontsWithInfo(scx_extract_display(display),
|
|
|
|
s48_extract_string(pattern),
|
|
|
|
s48_extract_integer(max), &count,
|
|
|
|
&infos);
|
|
|
|
S48_GC_PROTECT_2(res, cell);
|
|
|
|
for (i = count; i > 0; i--) {
|
|
|
|
cell = scx_enter_fontstruct(&infos[i-1]);
|
|
|
|
cell = s48_cons(s48_enter_string(fonts[i-1]), cell);
|
|
|
|
res = s48_cons(cell, res);
|
|
|
|
}
|
|
|
|
S48_GC_UNPROTECT();
|
2003-04-17 10:53:27 -04:00
|
|
|
XFreeFontNames(fonts); /* FontStructs have to be freed later */
|
2003-03-10 21:47:38 -05:00
|
|
|
return res;
|
2001-07-18 11:44:41 -04:00
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Set_Font_Path(s48_value display, s48_value dirs) {
|
|
|
|
int i, n = s48_list_length(dirs);
|
2001-07-18 11:44:41 -04:00
|
|
|
char* sa[n];
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value l = dirs;
|
2001-07-18 11:44:41 -04:00
|
|
|
for (i = 0; i < n; i++) {
|
2003-03-10 21:47:38 -05:00
|
|
|
sa[i] = s48_extract_string(S48_CAR(l));
|
|
|
|
l = S48_CDR(l);
|
2001-07-18 11:44:41 -04:00
|
|
|
}
|
2003-03-10 21:47:38 -05:00
|
|
|
XSetFontPath(scx_extract_display(display), sa, n);
|
2001-07-18 11:44:41 -04:00
|
|
|
|
|
|
|
return S48_UNSPECIFIC;
|
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Get_Font_Path(s48_value display) {
|
|
|
|
int n, i;
|
2001-07-18 11:44:41 -04:00
|
|
|
char** sa;
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value res = S48_NULL;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-07-18 11:44:41 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
sa = XGetFontPath(scx_extract_display(display), &n);
|
2001-07-18 11:44:41 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
S48_GC_PROTECT_1(res);
|
|
|
|
for (i = n; i > 0; i--)
|
|
|
|
res = s48_cons(s48_enter_string(sa[i]), res);
|
2001-07-18 11:44:41 -04:00
|
|
|
S48_GC_UNPROTECT();
|
2003-03-10 21:47:38 -05:00
|
|
|
XFreeFontPath(sa);
|
2001-07-18 11:44:41 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
return res;
|
2001-07-18 11:44:41 -04:00
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
/* TODO:
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Font_Properties(s48_value Xfontstruct) {
|
2002-02-08 12:09:43 -05:00
|
|
|
s48_value v, t = S48_FALSE;
|
2001-07-18 11:44:41 -04:00
|
|
|
int i,n;
|
2003-03-10 21:47:38 -05:00
|
|
|
XFontStruct* fs = scx_extract_fontstruct(Xfontstruct);
|
2001-07-18 11:44:41 -04:00
|
|
|
XFontProp* p;
|
2002-02-08 12:09:43 -05:00
|
|
|
S48_DECLARE_GC_PROTECT(2);
|
2001-07-18 11:44:41 -04:00
|
|
|
|
|
|
|
n = fs->n_properties;
|
|
|
|
v = s48_make_vector(n, S48_FALSE);
|
2002-02-08 12:09:43 -05:00
|
|
|
S48_GC_PROTECT_2(v, t);
|
2001-07-18 11:44:41 -04:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
p = fs->properties+i;
|
2003-03-10 21:47:38 -05:00
|
|
|
t = scx_enter_atom(p->name);
|
2002-02-08 12:09:43 -05:00
|
|
|
t = s48_cons(t, s48_enter_integer(p->card32));
|
|
|
|
S48_VECTOR_SET(v, i, t);
|
2001-07-18 11:44:41 -04:00
|
|
|
}
|
2002-02-08 12:09:43 -05:00
|
|
|
|
2001-07-18 11:44:41 -04:00
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Font_Property(s48_value Xfontstruct, s48_value Xatom) {
|
2001-07-18 11:44:41 -04:00
|
|
|
unsigned long val;
|
2003-03-10 21:47:38 -05:00
|
|
|
if (XGetFontProperty(scx_extract_fontstruct(Xfontstruct),
|
|
|
|
scx_extract_atom(Xatom),
|
2001-07-18 11:44:41 -04:00
|
|
|
&val))
|
|
|
|
return s48_enter_integer(val);
|
|
|
|
else
|
|
|
|
return S48_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Font_Info(s48_value Xfontstruct) {
|
2003-03-10 21:47:38 -05:00
|
|
|
XFontStruct* fs = scx_extract_fontstruct(Xfontstruct);
|
2001-07-18 11:44:41 -04:00
|
|
|
s48_value v = s48_make_vector(9, S48_FALSE);
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
S48_GC_PROTECT_1(v);
|
|
|
|
|
2002-02-08 12:09:43 -05:00
|
|
|
S48_VECTOR_SET(v, 0, s48_enter_fixnum(fs->direction));
|
|
|
|
S48_VECTOR_SET(v, 1, s48_enter_fixnum(fs->min_char_or_byte2));
|
|
|
|
S48_VECTOR_SET(v, 2, s48_enter_fixnum(fs->max_char_or_byte2));
|
|
|
|
S48_VECTOR_SET(v, 3, s48_enter_fixnum(fs->min_byte1));
|
|
|
|
S48_VECTOR_SET(v, 4, s48_enter_fixnum(fs->max_byte1));
|
2001-07-18 11:44:41 -04:00
|
|
|
S48_VECTOR_SET(v, 5, S48_ENTER_BOOLEAN(fs->all_chars_exist));
|
2002-02-08 12:09:43 -05:00
|
|
|
S48_VECTOR_SET(v, 6, s48_enter_fixnum(fs->default_char));
|
|
|
|
S48_VECTOR_SET(v, 7, s48_enter_fixnum(fs->ascent));
|
|
|
|
S48_VECTOR_SET(v, 8, s48_enter_fixnum(fs->descent));
|
2001-07-18 11:44:41 -04:00
|
|
|
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value scx_Char_Info(s48_value Xfontstruct, s48_value index) {
|
2001-07-18 11:44:41 -04:00
|
|
|
// index must be an integer, #f for 'min or #t for 'max
|
|
|
|
XCharStruct* cp;
|
2003-03-10 21:47:38 -05:00
|
|
|
XFontStruct* p = scx_extract_fontstruct(Xfontstruct);
|
2001-07-31 10:51:21 -04:00
|
|
|
s48_value v = S48_FALSE;
|
2001-07-18 11:44:41 -04:00
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
|
|
|
|
|
|
if (S48_FALSE_P(index))
|
|
|
|
cp = &p->min_bounds;
|
|
|
|
else if (S48_TRUE_P(index))
|
2001-05-08 10:21:00 -04:00
|
|
|
cp = &p->max_bounds;
|
2001-07-18 11:44:41 -04:00
|
|
|
else
|
|
|
|
cp = &(p->per_char[s48_extract_integer(index)]); // calculated in scheme
|
|
|
|
|
|
|
|
v = s48_make_vector(6, S48_FALSE);
|
|
|
|
S48_GC_PROTECT_1(v);
|
2002-02-08 12:09:43 -05:00
|
|
|
|
|
|
|
S48_VECTOR_SET(v, 0, s48_enter_fixnum(cp->lbearing));
|
|
|
|
S48_VECTOR_SET(v, 1, s48_enter_fixnum(cp->rbearing));
|
|
|
|
S48_VECTOR_SET(v, 2, s48_enter_fixnum(cp->width));
|
|
|
|
S48_VECTOR_SET(v, 3, s48_enter_fixnum(cp->ascent));
|
|
|
|
S48_VECTOR_SET(v, 4, s48_enter_fixnum(cp->descent));
|
|
|
|
S48_VECTOR_SET(v, 5, s48_enter_fixnum(cp->attributes));
|
2001-07-18 11:44:41 -04:00
|
|
|
|
|
|
|
S48_GC_UNPROTECT();
|
|
|
|
return v;
|
|
|
|
}
|
2003-03-10 21:47:38 -05:00
|
|
|
*/
|
2001-07-18 11:44:41 -04:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
void scx_init_font(void) {
|
|
|
|
S48_EXPORT_FUNCTION(scx_Load_Font);
|
2003-03-10 21:47:38 -05:00
|
|
|
S48_EXPORT_FUNCTION(scx_Unload_Font);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Query_Font);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Load_Query_Font);
|
2001-07-31 10:51:21 -04:00
|
|
|
S48_EXPORT_FUNCTION(scx_Free_Font);
|
|
|
|
S48_EXPORT_FUNCTION(scx_List_Fonts);
|
2003-03-10 21:47:38 -05:00
|
|
|
S48_EXPORT_FUNCTION(scx_List_Fonts_With_Info);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Set_Font_Path);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Get_Font_Path);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|