Changes for scheme48 and scx
This commit is contained in:
parent
736a828fbe
commit
71fc990882
303
c/xlib/text.c
303
c/xlib/text.c
|
@ -1,31 +1,10 @@
|
||||||
#include "xlib.h"
|
#include "xlib.h"
|
||||||
|
#include "scheme48.h"
|
||||||
|
|
||||||
extern XDrawText(), XDrawText16();
|
extern XDrawText(), XDrawText16();
|
||||||
static s48_value Sym_1byte, Sym_2byte;
|
|
||||||
|
|
||||||
static Two_Byte (format) s48_value format; {
|
|
||||||
Check_Type (format, T_Symbol);
|
|
||||||
if (S48_EQ_P(format, Sym_1byte))
|
|
||||||
return 0;
|
|
||||||
else if (S48_EQ_P(format, Sym_2byte))
|
|
||||||
return 1;
|
|
||||||
Primitive_Error ("index format must be '1-byte or '2-byte");
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
|
||||||
|
|
||||||
static Get_1_Byte_Char (x) s48_value x; {
|
|
||||||
register c = (int)s48_extract_integer (x);
|
|
||||||
if (c < 0 || c > 255)
|
|
||||||
Range_Error (x);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Get_2_Byte_Char (x) s48_value x; {
|
|
||||||
register c = (int)s48_extract_integer (x);
|
|
||||||
if (c < 0 || c > 65535)
|
|
||||||
Range_Error (x);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calculation of text widths and extents should not be done using
|
/* Calculation of text widths and extents should not be done using
|
||||||
* the Xlib functions. For instance, the values returned by
|
* the Xlib functions. For instance, the values returned by
|
||||||
|
@ -33,148 +12,164 @@ static Get_2_Byte_Char (x) s48_value x; {
|
||||||
* long strings.
|
* long strings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static s48_value Internal_Text_Metrics (font, t, f, width) s48_value font, t, f; {
|
|
||||||
char *s;
|
|
||||||
XChar2b *s2;
|
|
||||||
XFontStruct *info;
|
|
||||||
s48_value *data;
|
|
||||||
register i, n;
|
|
||||||
int dir, fasc, fdesc;
|
|
||||||
Alloca_Begin;
|
|
||||||
|
|
||||||
Check_Type (font, T_Font);
|
s48_value Text_Width(s48_value Xfontstruct, s48_value text, s48_value format){
|
||||||
info = FONT(font)->info;
|
char* s;
|
||||||
Check_Type (t, T_Vector);
|
XChar2b* s2;
|
||||||
n = S48_VECTOR_LENGTH(t);
|
XFontStruct* font = EXTRACT_XFONTSTRUCT(Xfontstruct);
|
||||||
data = VECTOR(t)->data;
|
int len = (int)S48_VECTOR_LENGHT(text), i, tmp;
|
||||||
if (Two_Byte (f)) {
|
if (s48_extract_integer(format) == 2){
|
||||||
Alloca (s2, XChar2b*, n * sizeof (XChar2b));
|
for (i = 0; i < len; i++){
|
||||||
for (i = 0; i < n; i++) {
|
tmp = (int)s48_extract_integer(S48_VECTOR_REF(text, i));
|
||||||
register c = Get_2_Byte_Char (data[i]);
|
s2[i].byte1 = (tmp >> 8) & 0xff;
|
||||||
s2[i].byte1 = (c >> 8) & 0xff;
|
s2[i].byte2 = tmp & 0xff;
|
||||||
s2[i].byte2 = c & 0xff;
|
|
||||||
}
|
|
||||||
if (width)
|
|
||||||
i = XTextWidth16 (info, s2, n);
|
|
||||||
else
|
|
||||||
XTextExtents16 (info, s2, n, &dir, &fasc, &fdesc, &CI);
|
|
||||||
} else {
|
|
||||||
Alloca (s, char*, n);
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
s[i] = Get_1_Byte_Char (data[i]);
|
|
||||||
if (width)
|
|
||||||
i = XTextWidth (info, s, n);
|
|
||||||
else
|
|
||||||
XTextExtents (info, s, n, &dir, &fasc, &fdesc, &CI);
|
|
||||||
}
|
}
|
||||||
Alloca_End;
|
i = XTextWidth16(font, s2, len);
|
||||||
return width ? s48_enter_integer (i) : Record_To_Vector (Char_Info_Rec,
|
}
|
||||||
Char_Info_Size, Sym_Char_Info, FONT(font)->dpy, ~0L);
|
else{
|
||||||
}
|
for (i = 0; i < len; i++){
|
||||||
|
s[i] = (int)S48_extract_integer(S48_VECTOR_REF(text, i));
|
||||||
static s48_value P_Text_Width (font, t, f) s48_value font, t, f; {
|
|
||||||
return Internal_Text_Metrics (font, t, f, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static s48_value P_Text_Extents (font, t, f) s48_value font, t, f; {
|
|
||||||
return Internal_Text_Metrics (font, t, f, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static s48_value P_Draw_Image_Text (d, gc, x, y, t, f) s48_value d, gc, x, y, t, f; {
|
|
||||||
Display *dpy;
|
|
||||||
Drawable dr = Get_Drawable (d, &dpy);
|
|
||||||
s48_value *data;
|
|
||||||
register i, n;
|
|
||||||
char *s;
|
|
||||||
XChar2b *s2;
|
|
||||||
Alloca_Begin;
|
|
||||||
|
|
||||||
Check_Type (gc, T_Gc);
|
|
||||||
Check_Type (t, T_Vector);
|
|
||||||
n = S48_VECTOR_LENGTH(t);
|
|
||||||
data = VECTOR(t)->data;
|
|
||||||
if (Two_Byte (f)) {
|
|
||||||
Alloca (s2, XChar2b*, n * sizeof (XChar2b));
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
register c = Get_2_Byte_Char (data[i]);
|
|
||||||
s2[i].byte1 = (c >> 8) & 0xff;
|
|
||||||
s2[i].byte2 = c & 0xff;
|
|
||||||
}
|
|
||||||
XDrawImageString16 (dpy, dr, GCONTEXT(gc)->gc, (int)s48_extract_integer (x),
|
|
||||||
(int)s48_extract_integer (y), s2, n);
|
|
||||||
} else {
|
|
||||||
Alloca (s, char*, n);
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
s[i] = Get_1_Byte_Char (data[i]);
|
|
||||||
XDrawImageString (dpy, dr, GCONTEXT(gc)->gc, (int)s48_extract_integer (x),
|
|
||||||
(int)s48_extract_integer (y), s, n);
|
|
||||||
}
|
}
|
||||||
Alloca_End;
|
i = XTextWidth(font, s, len);
|
||||||
return Void;
|
}
|
||||||
|
return s48_enter_integer((long)i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static s48_value P_Draw_Poly_Text (d, gc, x, y, t, f) s48_value d, gc, x, y, t, f; {
|
|
||||||
Display *dpy;
|
|
||||||
Drawable dr = Get_Drawable (d, &dpy);
|
|
||||||
s48_value *data;
|
|
||||||
register i, n, j, k;
|
|
||||||
int twobyte, nitems;
|
|
||||||
XTextItem *items;
|
|
||||||
int (*func)();
|
|
||||||
Alloca_Begin;
|
|
||||||
|
|
||||||
Check_Type (gc, T_Gc);
|
s48_value Extents_Text (s48_value Xfontstruct, s48_value text,
|
||||||
twobyte = Two_Byte (f);
|
s48_value format, s48_value which){
|
||||||
func = twobyte ? (int(*)())XDrawText16 : (int(*)())XDrawText;
|
char* s;
|
||||||
Check_Type (t, T_Vector);
|
XChar2b* s2;
|
||||||
if ((n = S48_VECTOR_LENGTH(t)) == 0)
|
XFontStruct* font = EXTRACT_XFONTSTRUCT(Xfontstruct);
|
||||||
return Void;
|
XCharStruct CI;
|
||||||
for (data = VECTOR(t)->data, i = 0, nitems = 1; i < n; i++)
|
int len = (int)S48_VECTOR_LENGHT(text), i, tmp, dir, fasc, fdesc;
|
||||||
if (TYPE(data[i]) == T_Font) nitems++;
|
if (s48_extract_integer(format) == 2){
|
||||||
Alloca (items, XTextItem*, nitems * sizeof (XTextItem));
|
for (i = 0; i < len; i++){
|
||||||
items[0].delta = 0;
|
tmp = (int)s48_extract_integer(S48_VECTOR_REF(text, i));
|
||||||
items[0].font = None;
|
s2[i].byte1 = (tmp >> 8) & 0xff;
|
||||||
for (j = k = i = 0; i <= n; i++) {
|
s2[i].byte2 = tmp & 0xff;
|
||||||
if (i == n || TYPE(data[i]) == T_Font) {
|
}
|
||||||
items[j].nchars = i-k;
|
XTextExtents16(font, s2, len, &dir, &fasc, &fdesc, &CI);
|
||||||
if (twobyte) {
|
}else{
|
||||||
register XChar2b *p;
|
for (i = 0; i < len; i++){
|
||||||
|
s[i] = (int)s48_extract_integer(S48_VECTOR_REF(text, i));
|
||||||
|
}
|
||||||
|
XTextExtents(font, s, len, &dir, &fasc, &fdesc, &CI);
|
||||||
|
}
|
||||||
|
switch(s48_extract_integer(which)){
|
||||||
|
case 0:
|
||||||
|
return s48_enter_integer((long) CI.lbearing);
|
||||||
|
case 1:
|
||||||
|
return s48_enter_integer((long) CI.rbearing);
|
||||||
|
case 2:
|
||||||
|
return s48_enter_integer((long) CI.width);
|
||||||
|
case 3:
|
||||||
|
return s48_enter_integer((long) CI.ascent);
|
||||||
|
case 4:
|
||||||
|
return s48_enter_integer((long) CI.descent);
|
||||||
|
}
|
||||||
|
return S48_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
Alloca (p, XChar2b*, (i-k) * sizeof (XChar2b));
|
|
||||||
((XTextItem16 *)items)[j].chars = p;
|
|
||||||
for ( ; k < i; k++, p++) {
|
|
||||||
register c = Get_2_Byte_Char (data[k]);
|
|
||||||
p->byte1 = (c >> 8) & 0xff;
|
|
||||||
p->byte2 = c & 0xff;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
register char *p;
|
|
||||||
|
|
||||||
Alloca (p, char*, i-k);
|
s48_value Draw_Image_Text (s48_value Xdisplay, s48_value Xdrawable,
|
||||||
items[j].chars = p;
|
s48_value Xgcontext, s48_value x, s48_value y,
|
||||||
for ( ; k < i; k++)
|
s48_value text, s48_value format){
|
||||||
*p++ = Get_1_Byte_Char (data[k]);
|
int i, len, tmp;
|
||||||
}
|
char* s;
|
||||||
k++;
|
XChar2b* s2;
|
||||||
j++;
|
len = S48_VECTOR_LENGTH(text);
|
||||||
if (i < n) {
|
|
||||||
items[j].delta = 0;
|
if (s48_extract_integer(format) == 2){
|
||||||
Open_Font_Maybe (data[i]);
|
for (i = 0; i < len; i++) {
|
||||||
items[j].font = FONT(data[i])->id;
|
tmp = (int)s48_extract_integer(S48_VECTOR_REF(text, i));
|
||||||
}
|
s2[i].byte1 = (tmp >> 8) & 0xff;
|
||||||
|
s2[i].byte2 = tmp & 0xff;
|
||||||
|
}
|
||||||
|
XDrawImageString16 (EXTRACT_DISPLAY(Xdisplay), EXTRACT_DRAWABLE(Xdrawable),
|
||||||
|
EXTRACT_GCONTEXT(Xgcontext),
|
||||||
|
(int)s48_extract_integer(x),
|
||||||
|
(int)s48_extract_integer(y), s2, len);
|
||||||
|
}else{
|
||||||
|
for (i = 0; i < len; i++){
|
||||||
|
s[i] = (int)s48_extract_integer(S48_VECTOR_REF(text, i));
|
||||||
|
}
|
||||||
|
XDrawImageString (EXTRACT_DISPLAY(Xdisplay), EXTRACT_INTEGER(Xdrawable),
|
||||||
|
EXTRACT_GCONTEXT(Xgcontext),
|
||||||
|
(int)s48_extract_integer(x),
|
||||||
|
(int)s48_extract_integer(y), s, len);
|
||||||
|
}
|
||||||
|
return S48_UNSPECIFIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
s48_value Draw_Poly_Text (s48_value Xdisplay, s48_value Xdrawable,
|
||||||
|
s48_value Xgcontext, s48_value x, s48_value y,
|
||||||
|
s48_value text, s48_value format){
|
||||||
|
int i, j, k, len, nitems, set = 0, tmp;
|
||||||
|
XTextItem* item;
|
||||||
|
s48_value temp_vec;
|
||||||
|
int twobyte = (int)s48_extract_integer(format);
|
||||||
|
len = S48_VECTOR_LENGTH(text);
|
||||||
|
|
||||||
|
if (!len){
|
||||||
|
return S48_UNSPECIFIC;
|
||||||
|
}
|
||||||
|
// count the strings in text:
|
||||||
|
for (i = 0; i < len; i++){
|
||||||
|
if (S48_VECTOR_P(S48_VECTOR_REF(text, i))){
|
||||||
|
nitems++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(*func)(dpy, dr, GCONTEXT(gc)->gc, (int)s48_extract_integer (x), (int)s48_extract_integer (y),
|
//XTextItem* item[nitems];
|
||||||
items, nitems);
|
//Maybe no font as first Element of text?
|
||||||
Alloca_End;
|
if (S48_VECTOR_P(S48_VECTOR_REF(text, 0))){
|
||||||
return Void;
|
item[0].delta = 0;
|
||||||
|
item[0].font = None;
|
||||||
|
}
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
if (S48_VECTOR_P(S48_VECTOR_REF(text,i))){
|
||||||
|
temp_vec = S48_VECTOR_REF(text,i);
|
||||||
|
k = S48_VECTOR_LENGTH(temp_vec);
|
||||||
|
item[set].nchars = k;
|
||||||
|
if (twobyte) {
|
||||||
|
XChar2b s2[k];
|
||||||
|
for (j = 0; j < k; j++){
|
||||||
|
tmp = (int)s48_extract_integer(S48_VECTOR_REF(temp_vec, j));
|
||||||
|
s2[j].byte1 = (tmp >> 8) & 0xff;
|
||||||
|
s2[j].byte2 = tmp & 0xff;
|
||||||
|
}
|
||||||
|
(XTextItem16* )item[set].chars = s2;
|
||||||
|
}else{
|
||||||
|
char s[k];
|
||||||
|
for(j = 0; j < k; j++){
|
||||||
|
s[j] = (int)s48_extract_integer(S48_VECTOR_REF(temp_vec, j));
|
||||||
|
}
|
||||||
|
item[set].chars = s;
|
||||||
|
}
|
||||||
|
set++;
|
||||||
|
}else{
|
||||||
|
item[set].font = EXTRACT_XFONT(S48_VECTOR_REF(text, i));
|
||||||
|
item[set].delta = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (twobyte){
|
||||||
|
XDrawText16(EXTRACT_DISPLAY(Xdisplay), EXTRACT_DRAWABLE(Xdrawable),
|
||||||
|
EXTRACT_GCONTEXT(Xgcontext), (int)s48_extract_integer(x),
|
||||||
|
(int)s48_extract_integer(y), (XTextItem16*) item, nitems);
|
||||||
|
}else{
|
||||||
|
XDrawText(EXTRACT_DISPLAY(Xdisplay), EXTRACT_DRAWABLE(Xdrawable),
|
||||||
|
EXTRACT_GCONTEXT(Xgcontext), (int)s48_extract_integer(x),
|
||||||
|
(int)s48_extract_integer(y), item, nitems);
|
||||||
|
}
|
||||||
|
return S48_UNSPECIFIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
elk_init_xlib_text () {
|
|
||||||
Define_Primitive (P_Text_Width, "text-width", 3, 3, EVAL);
|
|
||||||
Define_Primitive (P_Text_Extents, "xlib-text-extents", 3, 3, EVAL);
|
void s48_init_text(void) {
|
||||||
Define_Primitive (P_Draw_Image_Text, "draw-image-text", 6, 6, EVAL);
|
S48_EXPORT_FUNCTION(Text_Width);
|
||||||
Define_Primitive (P_Draw_Poly_Text, "draw-poly-text", 6, 6, EVAL);
|
S48_EXPORT_FUNCTION(Extents_Text);
|
||||||
Define_Symbol (&Sym_1byte, "1-byte");
|
S48_EXPORT_FUNCTION(Draw_Image_Text);
|
||||||
Define_Symbol (&Sym_2byte, "2-byte");
|
S48_EXPORT_FUNCTION(Draw_Poly_Text);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue