#include "xlib.h" #include "scheme48.h" extern XDrawText(), XDrawText16(); /* Calculation of text widths and extents should not be done using * the Xlib functions. For instance, the values returned by * XTextExtents() are only shorts and can therefore overflow for * long strings. */ s48_value Text_Width(s48_value Xfontstruct, s48_value text, s48_value format){ char* s; XChar2b* s2; XFontStruct* font = EXTRACT_XFONTSTRUCT(Xfontstruct); int len = (int)S48_VECTOR_LENGHT(text), i, tmp; if (s48_extract_integer(format) == 2){ for (i = 0; i < len; i++){ tmp = (int)s48_extract_integer(S48_VECTOR_REF(text, i)); s2[i].byte1 = (tmp >> 8) & 0xff; s2[i].byte2 = tmp & 0xff; } i = XTextWidth16(font, s2, len); } else{ for (i = 0; i < len; i++){ s[i] = (int)S48_extract_integer(S48_VECTOR_REF(text, i)); } i = XTextWidth(font, s, len); } return s48_enter_integer((long)i); } s48_value Extents_Text (s48_value Xfontstruct, s48_value text, s48_value format, s48_value which){ char* s; XChar2b* s2; XFontStruct* font = EXTRACT_XFONTSTRUCT(Xfontstruct); XCharStruct CI; int len = (int)S48_VECTOR_LENGHT(text), i, tmp, dir, fasc, fdesc; if (s48_extract_integer(format) == 2){ for (i = 0; i < len; i++){ tmp = (int)s48_extract_integer(S48_VECTOR_REF(text, i)); s2[i].byte1 = (tmp >> 8) & 0xff; s2[i].byte2 = tmp & 0xff; } XTextExtents16(font, s2, len, &dir, &fasc, &fdesc, &CI); }else{ 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; } s48_value Draw_Image_Text (s48_value Xdisplay, s48_value Xdrawable, s48_value Xgcontext, s48_value x, s48_value y, s48_value text, s48_value format){ int i, len, tmp; char* s; XChar2b* s2; len = S48_VECTOR_LENGTH(text); if (s48_extract_integer(format) == 2){ for (i = 0; i < len; i++) { 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++; } } //XTextItem* item[nitems]; //Maybe no font as first Element of text? if (S48_VECTOR_P(S48_VECTOR_REF(text, 0))){ 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; } void s48_init_text(void) { S48_EXPORT_FUNCTION(Text_Width); S48_EXPORT_FUNCTION(Extents_Text); S48_EXPORT_FUNCTION(Draw_Image_Text); S48_EXPORT_FUNCTION(Draw_Poly_Text); }