Added correct memory allocation for the char and XChar2b arrays in
scx_Draw_Image_Text and scx_Draw_Poly_Text. Added the scx_ prefixes.
This commit is contained in:
parent
2c8bb6981f
commit
4b314ade40
119
c/xlib/text.c
119
c/xlib/text.c
|
@ -10,7 +10,7 @@ extern XDrawText(), XDrawText16();
|
|||
*/
|
||||
|
||||
|
||||
s48_value Text_Width(s48_value Xfontstruct, s48_value text, s48_value format){
|
||||
s48_value scx_Text_Width(s48_value Xfontstruct, s48_value text, s48_value format){
|
||||
char* s;
|
||||
XChar2b* s2;
|
||||
XFontStruct* font = SCX_EXTRACT_FONTSTRUCT(Xfontstruct);
|
||||
|
@ -33,7 +33,7 @@ s48_value Text_Width(s48_value Xfontstruct, s48_value text, s48_value format){
|
|||
}
|
||||
|
||||
|
||||
s48_value Extents_Text (s48_value Xfontstruct, s48_value text,
|
||||
s48_value scx_Extents_Text (s48_value Xfontstruct, s48_value text,
|
||||
s48_value format, s48_value which){
|
||||
char* s;
|
||||
XChar2b* s2;
|
||||
|
@ -69,105 +69,124 @@ s48_value Extents_Text (s48_value Xfontstruct, s48_value text,
|
|||
}
|
||||
|
||||
|
||||
s48_value Draw_Image_Text (s48_value Xdisplay, s48_value Xdrawable,
|
||||
s48_value scx_Draw_Image_Text (s48_value Xdisplay, s48_value Xdrawable,
|
||||
s48_value Xgcontext, s48_value x, s48_value y,
|
||||
s48_value text, s48_value format){
|
||||
s48_value text, s48_value is_twobyte){
|
||||
int i, len, tmp;
|
||||
char* s;
|
||||
XChar2b* s2;
|
||||
len = S48_VECTOR_LENGTH(text);
|
||||
|
||||
if (s48_extract_integer(format) == 2){
|
||||
if (!S48_FALSE_P(is_twobyte)) {
|
||||
XChar2b s2[len];
|
||||
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 (SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_DRAWABLE(Xdrawable),
|
||||
XDrawImageString16 (SCX_EXTRACT_DISPLAY(Xdisplay),
|
||||
SCX_EXTRACT_DRAWABLE(Xdrawable),
|
||||
SCX_EXTRACT_GCONTEXT(Xgcontext),
|
||||
(int)s48_extract_integer(x),
|
||||
(int)s48_extract_integer(y), s2, len);
|
||||
}else{
|
||||
for (i = 0; i < len; i++){
|
||||
(int)s48_extract_integer(y),
|
||||
s2, len);
|
||||
} else {
|
||||
char s[len];
|
||||
for (i = 0; i < len; i++) {
|
||||
s[i] = (int)s48_extract_integer(S48_VECTOR_REF(text, i));
|
||||
}
|
||||
XDrawImageString (SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_DRAWABLE(Xdrawable),
|
||||
XDrawImageString (SCX_EXTRACT_DISPLAY(Xdisplay),
|
||||
SCX_EXTRACT_DRAWABLE(Xdrawable),
|
||||
SCX_EXTRACT_GCONTEXT(Xgcontext),
|
||||
(int)s48_extract_integer(x),
|
||||
(int)s48_extract_integer(y), s, len);
|
||||
(int)s48_extract_integer(y),
|
||||
s, len);
|
||||
}
|
||||
return S48_UNSPECIFIC;
|
||||
}
|
||||
|
||||
|
||||
s48_value Draw_Poly_Text (s48_value Xdisplay, s48_value Xdrawable,
|
||||
// Draw_Poly_Text processes a vector like [[24 23 87 67] Xfont [12 0]] and
|
||||
// passes it to XDrawPolyText or XDrawPolyText16
|
||||
|
||||
s48_value scx_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);
|
||||
s48_value text, s48_value is_twobyte) {
|
||||
int i, len, nitems;
|
||||
s48_value temp_vec = S48_FALSE;
|
||||
char twobyte = !S48_FALSE_P(is_twobyte);
|
||||
len = S48_VECTOR_LENGTH(text);
|
||||
|
||||
// Nothing to do with an empty vector.
|
||||
if (len == 0) return S48_UNSPECIFIC;
|
||||
|
||||
// count the strings in text:
|
||||
nitems = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (S48_VECTOR_P(S48_VECTOR_REF(text, i)))
|
||||
nitems++;
|
||||
}
|
||||
|
||||
if (len == 0){
|
||||
return S48_UNSPECIFIC;
|
||||
}
|
||||
// count the strings in text:
|
||||
{
|
||||
XTextItem item[nitems];
|
||||
int set = 0, j, k, tmp;
|
||||
|
||||
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))){
|
||||
if (S48_VECTOR_P(S48_VECTOR_REF(text, 0))) {
|
||||
item[0].delta = 0;
|
||||
item[0].font = None;
|
||||
}
|
||||
// Generate the XTextItem{16}
|
||||
for (i = 0; i < len; i++) {
|
||||
if (S48_VECTOR_P(S48_VECTOR_REF(text,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];
|
||||
XChar2b* s2 = malloc(sizeof(XChar2b)*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++){
|
||||
(XTextItem16*)item[set].chars = s2;
|
||||
} else {
|
||||
char* s = malloc(sizeof(char)*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 = SCX_EXTRACT_FONT(S48_VECTOR_REF(text, i));
|
||||
item[set].delta = 0;
|
||||
} else {
|
||||
s48_value fontspec = S48_VECTOR_REF(text, i);
|
||||
s48_value font = S48_CAR(fontspec);
|
||||
item[set].font = S48_SYMBOL_P(font) ? None : SCX_EXTRACT_FONT(font);
|
||||
item[set].delta = s48_extract_integer(S48_CDR(fontspec));
|
||||
}
|
||||
}
|
||||
if (twobyte){
|
||||
XDrawText16(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_DRAWABLE(Xdrawable),
|
||||
SCX_EXTRACT_GCONTEXT(Xgcontext), (int)s48_extract_integer(x),
|
||||
(int)s48_extract_integer(y), (XTextItem16*) item, nitems);
|
||||
}else{
|
||||
// No pass it all to the Xlib
|
||||
if (twobyte) {
|
||||
XDrawText16(SCX_EXTRACT_DISPLAY(Xdisplay),
|
||||
SCX_EXTRACT_DRAWABLE(Xdrawable),
|
||||
SCX_EXTRACT_GCONTEXT(Xgcontext),
|
||||
(int)s48_extract_integer(x), (int)s48_extract_integer(y),
|
||||
(XTextItem16*) item, nitems);
|
||||
} else {
|
||||
XDrawText(SCX_EXTRACT_DISPLAY(Xdisplay), SCX_EXTRACT_DRAWABLE(Xdrawable),
|
||||
SCX_EXTRACT_GCONTEXT(Xgcontext), (int)s48_extract_integer(x),
|
||||
(int)s48_extract_integer(y), item, nitems);
|
||||
}
|
||||
return S48_UNSPECIFIC;
|
||||
// No free all character-arrays
|
||||
for (i = 0; i < nitems; i++)
|
||||
free(item[i].chars);
|
||||
}
|
||||
return S48_UNSPECIFIC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void scx_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);
|
||||
S48_EXPORT_FUNCTION(scx_Text_Width);
|
||||
S48_EXPORT_FUNCTION(scx_Extents_Text);
|
||||
S48_EXPORT_FUNCTION(scx_Draw_Image_Text);
|
||||
S48_EXPORT_FUNCTION(scx_Draw_Poly_Text);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue