2003-03-10 21:47:38 -05:00
|
|
|
/* Copyright 2001-2003 by Norbert Freudemann, David Frese */
|
|
|
|
|
2001-05-08 10:21:00 -04:00
|
|
|
#include "xlib.h"
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Draw_Image_String(s48_value display, s48_value drawable,
|
|
|
|
s48_value gc, s48_value x, s48_value y,
|
|
|
|
s48_value string) {
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_DECLARE_GC_PROTECT_6(display, drawable, gc, x, y, string);
|
2003-03-10 21:47:38 -05:00
|
|
|
XDrawImageString(scx_extract_display(display),
|
|
|
|
scx_extract_drawable(drawable),
|
|
|
|
scx_extract_gc(gc),
|
|
|
|
s48_extract_integer(x),
|
|
|
|
s48_extract_integer(y),
|
|
|
|
s48_extract_string(string),
|
|
|
|
S48_STRING_LENGTH(string));
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_GC_RETURN(S48_UNSPECIFIC);
|
2003-03-10 21:47:38 -05:00
|
|
|
}
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Draw_Image_String_16(s48_value display, s48_value drawable,
|
|
|
|
s48_value gc, s48_value x, s48_value y,
|
|
|
|
s48_value string) {
|
|
|
|
int i, len = s48_list_length(string);
|
|
|
|
XChar2b chars[len];
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_DECLARE_GC_PROTECT_6(display, drawable, gc, x, y, string);
|
2003-03-10 21:47:38 -05:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
chars[i].byte1 = s48_extract_char(S48_CAR(S48_CAR(string)));
|
|
|
|
chars[i].byte2 = s48_extract_char(S48_CDR(S48_CAR(string)));
|
|
|
|
string = S48_CDR(string);
|
|
|
|
}
|
|
|
|
XDrawImageString16(scx_extract_display(display),
|
|
|
|
scx_extract_drawable(drawable),
|
|
|
|
scx_extract_gc(gc),
|
|
|
|
s48_extract_integer(x),
|
|
|
|
s48_extract_integer(y),
|
|
|
|
chars, len);
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_GC_RETURN(S48_UNSPECIFIC);
|
2003-03-10 21:47:38 -05:00
|
|
|
}
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_text_item = S48_FALSE;
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
void scx_extract_text_item(s48_value v, XTextItem* ti) {
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_DECLARE_GC_PROTECT_1(v);
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_check_record_type(v, scx_text_item);
|
|
|
|
if (S48_RECORD_REF(v, 0) != S48_FALSE) {
|
|
|
|
ti->nchars = S48_STRING_LENGTH(S48_RECORD_REF(v, 0));
|
|
|
|
ti->chars = (char*)malloc(ti->nchars);
|
|
|
|
strncpy(ti->chars, s48_extract_string(S48_RECORD_REF(v, 0)), ti->nchars);
|
|
|
|
} else {
|
|
|
|
ti->chars = NULL;
|
|
|
|
ti->nchars = 0;
|
2001-07-19 09:59:42 -04:00
|
|
|
}
|
2003-03-10 21:47:38 -05:00
|
|
|
ti->delta = s48_extract_integer(S48_RECORD_REF(v, 1));
|
|
|
|
ti->font = scx_extract_font(S48_RECORD_REF(v, 2));
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_GC_UNPROTECT();
|
2003-04-17 10:53:27 -04:00
|
|
|
/* Free all chars arrays! */
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
2001-07-19 09:59:42 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
void scx_extract_text_item_16(s48_value v, XTextItem16* ti) {
|
2003-05-02 11:29:09 -04:00
|
|
|
s48_value l = S48_NULL;
|
|
|
|
S48_DECLARE_GC_PROTECT_2(v, l);
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_check_record_type(v, scx_text_item);
|
|
|
|
{
|
|
|
|
if (S48_RECORD_REF(v, 0) != S48_FALSE) {
|
2003-05-02 11:29:09 -04:00
|
|
|
int i, n;
|
2003-05-04 11:19:39 -04:00
|
|
|
XChar2b* s;
|
2003-05-02 11:29:09 -04:00
|
|
|
l = S48_RECORD_REF(v, 0);
|
|
|
|
n = s48_list_length(l);
|
2003-05-04 11:19:39 -04:00
|
|
|
s = (XChar2b*)malloc(n * sizeof(XChar2b));
|
2003-03-10 21:47:38 -05:00
|
|
|
for (i = n-1; i >= 0; i--) {
|
|
|
|
ti->chars[i].byte1 = s48_extract_integer(S48_CAR(S48_CAR(l)));
|
|
|
|
ti->chars[i].byte2 = s48_extract_integer(S48_CDR(S48_CAR(l)));
|
|
|
|
}
|
|
|
|
ti->nchars = n;
|
|
|
|
} else {
|
|
|
|
ti->chars = NULL;
|
|
|
|
ti->nchars = 0;
|
2001-07-19 09:59:42 -04:00
|
|
|
}
|
2003-03-10 21:47:38 -05:00
|
|
|
ti->delta = s48_extract_integer(S48_RECORD_REF(v, 1));
|
|
|
|
ti->font = scx_extract_font(S48_RECORD_REF(v, 2));
|
2001-07-19 09:59:42 -04:00
|
|
|
}
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_GC_UNPROTECT();
|
2003-04-17 10:53:27 -04:00
|
|
|
/* Free all chars arrays! */
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Draw_Text(s48_value display, s48_value drawable,
|
|
|
|
s48_value gc, s48_value x, s48_value y,
|
|
|
|
s48_value items) {
|
|
|
|
int i, len = s48_list_length(items);
|
|
|
|
XTextItem parts[len];
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_DECLARE_GC_PROTECT_6(display, drawable, gc, x, y, items);
|
2003-03-10 21:47:38 -05:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
scx_extract_text_item(S48_CAR(items), &parts[i]);
|
|
|
|
items = S48_CDR(items);
|
2001-07-19 09:59:42 -04:00
|
|
|
}
|
2003-03-10 21:47:38 -05:00
|
|
|
XDrawText(scx_extract_display(display),
|
|
|
|
scx_extract_drawable(drawable),
|
|
|
|
scx_extract_gc(gc),
|
|
|
|
s48_extract_integer(x),
|
|
|
|
s48_extract_integer(y),
|
|
|
|
parts, len);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
free(parts[i].chars);
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_GC_RETURN(S48_UNSPECIFIC);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Draw_Text_16(s48_value display, s48_value drawable,
|
|
|
|
s48_value gc, s48_value x, s48_value y,
|
|
|
|
s48_value items) {
|
|
|
|
int i, len = s48_list_length(items);
|
|
|
|
XTextItem16 parts[len];
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_DECLARE_GC_PROTECT_6(display, drawable, gc, x, y, items);
|
2001-08-21 04:19:02 -04:00
|
|
|
for (i = 0; i < len; i++) {
|
2003-03-10 21:47:38 -05:00
|
|
|
scx_extract_text_item_16(S48_CAR(items), &parts[i]);
|
|
|
|
items = S48_CDR(items);
|
2001-08-21 04:19:02 -04:00
|
|
|
}
|
2003-03-10 21:47:38 -05:00
|
|
|
XDrawText16(scx_extract_display(display),
|
|
|
|
scx_extract_drawable(drawable),
|
|
|
|
scx_extract_gc(gc),
|
|
|
|
s48_extract_integer(x),
|
|
|
|
s48_extract_integer(y),
|
|
|
|
parts, len);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
free(parts[i].chars);
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_GC_RETURN(S48_UNSPECIFIC);
|
2003-03-10 21:47:38 -05:00
|
|
|
}
|
2001-05-08 10:21:00 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Text_Extents(s48_value font_struct, s48_value string) {
|
|
|
|
XCharStruct overall;
|
2003-03-25 13:27:18 -05:00
|
|
|
int dir, ascent, descent;
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_DECLARE_GC_PROTECT_2(font_struct, string);
|
2003-03-10 21:47:38 -05:00
|
|
|
XTextExtents(scx_extract_fontstruct(font_struct),
|
|
|
|
s48_extract_string(string),
|
|
|
|
S48_STRING_LENGTH(string),
|
2003-03-25 13:27:18 -05:00
|
|
|
&dir, &ascent, &descent,
|
2003-03-10 21:47:38 -05:00
|
|
|
&overall);
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_GC_RETURN(scx_enter_charstruct(&overall));
|
2003-03-10 21:47:38 -05:00
|
|
|
}
|
2001-07-31 10:51:21 -04:00
|
|
|
|
2003-03-10 21:47:38 -05:00
|
|
|
s48_value scx_Text_Extents_16(s48_value font_struct, s48_value string) {
|
|
|
|
XCharStruct overall;
|
2003-03-25 13:27:18 -05:00
|
|
|
int dir, ascent, descent;
|
2003-03-10 21:47:38 -05:00
|
|
|
int i, len = s48_list_length(string);
|
|
|
|
XChar2b chars[len];
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_DECLARE_GC_PROTECT_2(font_struct, string);
|
2003-03-10 21:47:38 -05:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
chars[i].byte1 = s48_extract_char(S48_CAR(S48_CAR(string)));
|
|
|
|
chars[i].byte2 = s48_extract_char(S48_CDR(S48_CAR(string)));
|
|
|
|
string = S48_CDR(string);
|
2001-08-21 04:19:02 -04:00
|
|
|
}
|
2003-03-10 21:47:38 -05:00
|
|
|
XTextExtents16(scx_extract_fontstruct(font_struct),
|
|
|
|
chars, len,
|
2003-03-25 13:27:18 -05:00
|
|
|
&dir, &ascent, &descent,
|
2003-03-10 21:47:38 -05:00
|
|
|
&overall);
|
2003-05-02 11:29:09 -04:00
|
|
|
S48_GC_RETURN(scx_enter_charstruct(&overall));
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|
2003-03-10 21:47:38 -05:00
|
|
|
|
2001-07-31 10:51:21 -04:00
|
|
|
void scx_init_text(void) {
|
2003-03-10 21:47:38 -05:00
|
|
|
S48_GC_PROTECT_GLOBAL(scx_text_item);
|
|
|
|
scx_text_item = s48_get_imported_binding("scx-text-item");
|
|
|
|
|
|
|
|
S48_EXPORT_FUNCTION(scx_Draw_Image_String);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Draw_Image_String_16);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Draw_Text);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Draw_Text_16);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Text_Extents);
|
|
|
|
S48_EXPORT_FUNCTION(scx_Text_Extents_16);
|
2001-05-08 10:21:00 -04:00
|
|
|
}
|