2001-05-08 10:21:00 -04:00
|
|
|
#include "xlib.h"
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value Sym_Char_Info;
|
|
|
|
static s48_value Sym_Font_Info, Sym_Min, Sym_Max;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Generic_Predicate (Font)
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static Font_Equal (x, y) s48_value x, y; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Font id1 = FONT(x)->id, id2 = FONT(y)->id;
|
|
|
|
if (id1 && id2)
|
|
|
|
return id1 == id2 && FONT(x)->dpy == FONT(y)->dpy;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Generic_Print (Font, "#[font %lu]", FONT(x)->id ? FONT(x)->id : POINTER(x))
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static Font_Visit (fp, f) s48_value *fp; int (*f)(); {
|
2001-05-08 10:21:00 -04:00
|
|
|
(*f)(&FONT(*fp)->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Generic_Get_Display (Font, FONT)
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value Internal_Make_Font (finalize, dpy, name, id, info)
|
|
|
|
Display *dpy; s48_value name; Font id; XFontStruct *info; {
|
|
|
|
s48_value f;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_GC_PROTECT_1 (name);
|
2001-05-08 10:21:00 -04:00
|
|
|
f = Alloc_Object (sizeof (struct S_Font), T_Font, 0);
|
|
|
|
FONT(f)->dpy = dpy;
|
|
|
|
if (TYPE(name) == T_Symbol)
|
2001-05-14 09:48:37 -04:00
|
|
|
name = s48_extract_string(S48_SYMBOL_TO_STRING(name));
|
2001-05-08 10:21:00 -04:00
|
|
|
FONT(f)->name = name;
|
|
|
|
FONT(f)->id = id;
|
|
|
|
FONT(f)->info = info;
|
|
|
|
if (id)
|
|
|
|
Register_Object (f, (GENERIC)dpy, finalize ? P_Close_Font : (PFO)0, 0);
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_GC_UNPROTECT;
|
2001-05-08 10:21:00 -04:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Backwards compatibility: */
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value Make_Font (dpy, name, id, info)
|
|
|
|
Display *dpy; s48_value name; Font id; XFontStruct *info; {
|
2001-05-08 10:21:00 -04:00
|
|
|
return Internal_Make_Font (1, dpy, name, id, info);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value Make_Font_Foreign (dpy, name, id, info)
|
|
|
|
Display *dpy; s48_value name; Font id; XFontStruct *info; {
|
2001-05-08 10:21:00 -04:00
|
|
|
return Internal_Make_Font (0, dpy, name, id, info);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
Font Get_Font (f) s48_value f; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Check_Type (f, T_Font);
|
|
|
|
Open_Font_Maybe (f);
|
|
|
|
return FONT(f)->id;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static XFontStruct *Internal_Open_Font (d, name) Display *d; s48_value name; {
|
2001-05-08 10:21:00 -04:00
|
|
|
register char *s;
|
|
|
|
XFontStruct *p;
|
|
|
|
Alloca_Begin;
|
|
|
|
|
|
|
|
Get_Strsym_Stack (name, s);
|
|
|
|
Disable_Interrupts;
|
|
|
|
if ((p = XLoadQueryFont (d, s)) == 0)
|
|
|
|
Primitive_Error ("cannot open font: ~s", name);
|
|
|
|
Enable_Interrupts;
|
|
|
|
Alloca_End;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Open_Font (d, name) s48_value d, name; {
|
2001-05-08 10:21:00 -04:00
|
|
|
XFontStruct *p;
|
|
|
|
|
|
|
|
Check_Type (d, T_Display)
|
|
|
|
p = Internal_Open_Font (DISPLAY(d)->dpy, name);
|
|
|
|
return Make_Font (DISPLAY(d)->dpy, name, p->fid, p);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
void Open_Font_Maybe (f) s48_value f; {
|
|
|
|
s48_value name;
|
2001-05-08 10:21:00 -04:00
|
|
|
XFontStruct *p;
|
|
|
|
|
|
|
|
name = FONT(f)->name;
|
2001-05-14 09:48:37 -04:00
|
|
|
if (!S48_TRUE_P (name))
|
2001-05-08 10:21:00 -04:00
|
|
|
Primitive_Error ("invalid font");
|
|
|
|
if (FONT(f)->id == 0) {
|
|
|
|
p = Internal_Open_Font (FONT(f)->dpy, name);
|
|
|
|
FONT(f)->id = p->fid;
|
|
|
|
FONT(f)->info = p;
|
|
|
|
Register_Object (f, (GENERIC)(FONT(f)->dpy), P_Close_Font, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value P_Close_Font (f) s48_value f; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Check_Type (f, T_Font);
|
|
|
|
if (FONT(f)->id)
|
|
|
|
XUnloadFont (FONT(f)->dpy, FONT(f)->id);
|
|
|
|
FONT(f)->id = 0;
|
|
|
|
Deregister_Object (f);
|
|
|
|
return Void;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Font_Name (f) s48_value f; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Check_Type (f, T_Font);
|
|
|
|
return FONT(f)->name;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Gcontext_Font (g) s48_value g; {
|
2001-05-08 10:21:00 -04:00
|
|
|
register struct S_Gc *p;
|
|
|
|
register XFontStruct *info;
|
|
|
|
|
|
|
|
Check_Type (g, T_Gc);
|
|
|
|
p = GCONTEXT(g);
|
|
|
|
Disable_Interrupts;
|
|
|
|
info = XQueryFont (p->dpy, XGContextFromGC (p->gc));
|
|
|
|
Enable_Interrupts;
|
2001-05-14 09:48:37 -04:00
|
|
|
return Make_Font_Foreign (p->dpy, S48_FALSE, (Font)0, info);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value Internal_List_Fonts (d, pat, with_info) s48_value d, pat; {
|
2001-05-08 10:21:00 -04:00
|
|
|
char **ret;
|
|
|
|
int n;
|
|
|
|
XFontStruct *iret;
|
|
|
|
register i;
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value f, v;
|
2001-05-08 10:21:00 -04:00
|
|
|
Display *dpy;
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_DECLARE_GC_PROTECT(2);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
dpy = DISPLAY(d)->dpy;
|
|
|
|
Disable_Interrupts;
|
|
|
|
if (with_info)
|
|
|
|
ret = XListFontsWithInfo (dpy, Get_Strsym (pat), 65535, &n, &iret);
|
|
|
|
else
|
|
|
|
ret = XListFonts (dpy, Get_Strsym (pat), 65535, &n);
|
|
|
|
Enable_Interrupts;
|
2001-05-14 09:48:37 -04:00
|
|
|
v = s48_make_vector (n, S48_NULL);
|
|
|
|
f = S48_NULL;
|
|
|
|
S48_GC_PROTECT_2 (f, v);
|
2001-05-08 10:21:00 -04:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
f = Make_String (ret[i], strlen (ret[i]));
|
|
|
|
if (with_info)
|
|
|
|
f = Make_Font (dpy, f, (Font)0, &iret[i]);
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_VECTOR_SET(v, i, f;)
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_GC_UNPROTECT;
|
2001-05-08 10:21:00 -04:00
|
|
|
if (with_info)
|
|
|
|
XFreeFontInfo (ret, (XFontStruct *)0, 0);
|
|
|
|
else
|
|
|
|
XFreeFontNames (ret);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_List_Font_Names (d, pat) s48_value d, pat; {
|
2001-05-08 10:21:00 -04:00
|
|
|
return Internal_List_Fonts (d, pat, 0);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_List_Fonts (d, pat) s48_value d, pat; {
|
2001-05-08 10:21:00 -04:00
|
|
|
return Internal_List_Fonts (d, pat, 1);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Font_Info (f) s48_value f; {
|
2001-05-08 10:21:00 -04:00
|
|
|
Check_Type (f, T_Font);
|
|
|
|
FI = *FONT(f)->info;
|
|
|
|
return Record_To_Vector (Font_Info_Rec, Font_Info_Size,
|
|
|
|
Sym_Font_Info, FONT(f)->dpy, ~0L);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Char_Info (f, index) s48_value f, index; {
|
2001-05-08 10:21:00 -04:00
|
|
|
register t = TYPE(index);
|
|
|
|
register unsigned i;
|
|
|
|
register XCharStruct *cp;
|
|
|
|
register XFontStruct *p;
|
|
|
|
char *msg = "argument must be integer, character, 'min, or 'max";
|
|
|
|
|
|
|
|
Check_Type (f, T_Font);
|
|
|
|
Open_Font_Maybe (f);
|
|
|
|
p = FONT(f)->info;
|
|
|
|
cp = &p->max_bounds;
|
|
|
|
if (t == T_Symbol) {
|
2001-05-14 09:48:37 -04:00
|
|
|
if (S48_EQ_P(index, Sym_Min))
|
2001-05-08 10:21:00 -04:00
|
|
|
cp = &p->min_bounds;
|
2001-05-14 09:48:37 -04:00
|
|
|
else if (!S48_EQ_P(index, Sym_Max))
|
2001-05-08 10:21:00 -04:00
|
|
|
Primitive_Error (msg);
|
|
|
|
} else {
|
|
|
|
if (t == T_Character)
|
2001-05-14 09:48:37 -04:00
|
|
|
i = s48_extract_char(index);
|
2001-05-08 10:21:00 -04:00
|
|
|
else if (t == T_Fixnum || t == T_Bignum)
|
2001-05-14 09:48:37 -04:00
|
|
|
i = (unsigned)(int)s48_extract_integer (index);
|
2001-05-08 10:21:00 -04:00
|
|
|
else
|
|
|
|
Primitive_Error (msg);
|
|
|
|
if (!p->min_byte1 && !p->max_byte1) {
|
|
|
|
if (i < p->min_char_or_byte2 || i > p->max_char_or_byte2)
|
|
|
|
Range_Error (index);
|
|
|
|
i -= p->min_char_or_byte2;
|
|
|
|
} else {
|
|
|
|
register unsigned b1 = i & 0xff, b2 = (i >> 8) & 0xff;
|
|
|
|
if (b1 < p->min_byte1 || b1 > p->max_byte1 ||
|
|
|
|
b2 < p->min_char_or_byte2 || b2 > p->max_char_or_byte2)
|
|
|
|
Range_Error (index);
|
|
|
|
b1 -= p->min_byte1;
|
|
|
|
b2 -= p->min_char_or_byte2;
|
|
|
|
i = b1 * (p->max_char_or_byte2 - p->min_char_or_byte2 + 1) + b2;
|
|
|
|
}
|
|
|
|
if (p->per_char)
|
|
|
|
cp = p->per_char + i;
|
|
|
|
}
|
|
|
|
CI = *cp;
|
|
|
|
return Record_To_Vector (Char_Info_Rec, Char_Info_Size,
|
|
|
|
Sym_Char_Info, FONT(f)->dpy, ~0L);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Font_Properties (f) s48_value f; {
|
2001-05-08 10:21:00 -04:00
|
|
|
register i, n;
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value v, a, val, x;
|
|
|
|
S48_DECLARE_GC_PROTECT(4);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Check_Type (f, T_Font);
|
|
|
|
n = FONT(f)->info->n_properties;
|
2001-05-14 09:48:37 -04:00
|
|
|
v = s48_make_vector (n, S48_NULL);
|
|
|
|
a = val = S48_NULL;
|
|
|
|
S48_GC_PROTECT_4 (v, a, val, f);
|
2001-05-08 10:21:00 -04:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
register XFontProp *p = FONT(f)->info->properties+i;
|
|
|
|
a = Make_Atom (p->name);
|
2001-05-14 09:48:37 -04:00
|
|
|
val = s48_enter_integer ((unsigned long)p->card32);
|
|
|
|
x = s48_cons (a, val);
|
|
|
|
S48_VECTOR_SET(v, i, x;)
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_GC_UNPROTECT;
|
2001-05-08 10:21:00 -04:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Font_Path (d) s48_value d; {
|
|
|
|
s48_value v;
|
2001-05-08 10:21:00 -04:00
|
|
|
int i, n;
|
|
|
|
char **ret;
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
Disable_Interrupts;
|
|
|
|
ret = XGetFontPath (DISPLAY(d)->dpy, &n);
|
|
|
|
Enable_Interrupts;
|
2001-05-14 09:48:37 -04:00
|
|
|
v = s48_make_vector (n, S48_NULL);
|
|
|
|
S48_GC_PROTECT_1 (v);
|
2001-05-08 10:21:00 -04:00
|
|
|
for (i = 0; i < n; i++) {
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value x;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
|
|
|
x = Make_String (ret[i], strlen (ret[i]));
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_VECTOR_SET(v, i, x;)
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
2001-05-14 09:48:37 -04:00
|
|
|
S48_GC_UNPROTECT;
|
2001-05-08 10:21:00 -04:00
|
|
|
XFreeFontPath (ret);
|
|
|
|
return P_Vector_To_List (v);
|
|
|
|
}
|
|
|
|
|
2001-05-14 09:48:37 -04:00
|
|
|
static s48_value P_Set_Font_Path (d, p) s48_value d, p; {
|
2001-05-08 10:21:00 -04:00
|
|
|
register char **path;
|
|
|
|
register i, n;
|
2001-05-14 09:48:37 -04:00
|
|
|
s48_value c;
|
2001-05-08 10:21:00 -04:00
|
|
|
Alloca_Begin;
|
|
|
|
|
|
|
|
Check_Type (d, T_Display);
|
|
|
|
Check_List (p);
|
|
|
|
n = Fast_Length (p);
|
|
|
|
Alloca (path, char**, n * sizeof (char *));
|
2001-05-14 09:48:37 -04:00
|
|
|
for (i = 0; i < n; i++, p = S48_CDR (p)) {
|
|
|
|
c = S48_CAR (p);
|
2001-05-08 10:21:00 -04:00
|
|
|
Get_Strsym_Stack (c, path[i]);
|
|
|
|
}
|
|
|
|
XSetFontPath (DISPLAY(d)->dpy, path, n);
|
|
|
|
Alloca_End;
|
|
|
|
return Void;
|
|
|
|
}
|
|
|
|
|
|
|
|
elk_init_xlib_font () {
|
|
|
|
Define_Symbol (&Sym_Font_Info, "font-info");
|
|
|
|
Define_Symbol (&Sym_Char_Info, "char-info");
|
|
|
|
Define_Symbol (&Sym_Min, "min");
|
|
|
|
Define_Symbol (&Sym_Max, "max");
|
|
|
|
T_Font = Define_Type (0, "font", NOFUNC, sizeof (struct S_Font),
|
|
|
|
Font_Equal, Font_Equal, Font_Print, Font_Visit);
|
|
|
|
Define_Primitive (P_Fontp, "font?", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Font_Display, "font-display", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Open_Font, "open-font", 2, 2, EVAL);
|
|
|
|
Define_Primitive (P_Close_Font, "close-font", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Font_Name, "font-name", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Gcontext_Font, "gcontext-font", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_List_Font_Names, "list-font-names", 2, 2, EVAL);
|
|
|
|
Define_Primitive (P_List_Fonts, "list-fonts", 2, 2, EVAL);
|
|
|
|
Define_Primitive (P_Font_Info, "xlib-font-info", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Char_Info, "xlib-char-info", 2, 2, EVAL);
|
|
|
|
Define_Primitive (P_Font_Properties, "font-properties", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Font_Path, "font-path", 1, 1, EVAL);
|
|
|
|
Define_Primitive (P_Set_Font_Path, "set-font-path!", 2, 2, EVAL);
|
|
|
|
}
|