Commit 0864c980 authored by Jehan's avatar Jehan

Not bad. UTF-8 is passing. Many display issues to address

parent 4a22c2fe
This diff is collapsed.
......@@ -2951,6 +2951,19 @@ rxvt_init_vts( rxvt_t *r, int page, int profile )
PVTS(r, page)->outbuf_start = PVTS(r, page)->outbuf_end
= PVTS(r, page)->outbuf_base;
PVTS(r, page)->textbuf_start = PVTS(r, page)->textbuf_end
= PVTS(r, page)->textbuf_base;
SET_NULL( PVTS(r, page)->textbuf_escstart);
SET_NULL( PVTS(r, page)->textbuf_escfail);
/* Conversion state created and set to initial state. */
#ifdef HAVE_ICONV_H
PVTS(r, page)->shift_state = iconv_open ("WCHAR_T", ""); // TODO Jehan: is "" enough to define locale encoding?
#else
mbstate_t* mbst = PVTS(r, page)->shift_state = rxvt_malloc (sizeof (mbstate_t)); // TODO Jehan: test NULL?!
memset (mbst, 0, sizeof(mbst));
#endif
/* Initialize write out buffer */
SET_NULL(PVTS(r, page)->inbuf_base);
SET_NULL(PVTS(r, page)->inbuf_start);
......@@ -3007,6 +3020,11 @@ rxvt_destroy_termwin( rxvt_t *r, int page )
}
#endif
#ifdef HAVE_ICONV_H
iconv_close (PVTS(r, page)->shift_state);
#else
rxvt_free (PVTS(r, page)->shift_state);
#endif
rxvt_free (PVTS(r, page));
rxvt_dbgmsg ((DBG_DEBUG, DBG_INIT, "\tThe terminal %d has been successfully freed.\n", page));
}
......
......@@ -221,13 +221,12 @@ int rxvt_control_tty __PROTO((int fd_tty, const cha
/* Begin prototypes of screen.c */
void
rxvt_draw_string_x11 (rxvt_t* r, Window win, GC gc, Region refreshRegion,
int x, int y, char* str, int len, int (*draw_string)());
int x, int y, text_t* str, int len, int (*draw_string)());
#ifdef XFT_SUPPORT
void
rxvt_draw_string_xft (rxvt_t* r, Drawable d, GC gc, Region refreshRegion,
rend_t rend, int pfont,
XftDraw* win, XftColor* fore, int x, int y, char* str, int len,
void (*xftdraw_string)());
XftDraw* win, XftColor* fore, int x, int y, text_t* str, int len);
#endif
void rxvt_init_screen __PROTO((rxvt_t* r));
void rxvt_scr_reset __PROTO((rxvt_t* r, int page));
......@@ -238,7 +237,7 @@ int rxvt_scr_change_screen __PROTO((rxvt_t* r, int page,
void rxvt_scr_color __PROTO((rxvt_t* r, int page, unsigned int color, int fgbg));
void rxvt_scr_rendition __PROTO((rxvt_t* r, int page, int set, int style));
int rxvt_scroll_text __PROTO((rxvt_t* r, int page, int row1, int row2, int count, int spec));
void rxvt_scr_add_lines __PROTO((rxvt_t* r, int page, const unsigned char* str, int nlines, int len));
void rxvt_scr_add_lines __PROTO((rxvt_t* r, int page, text_t* str, int nlines, int len));
void rxvt_scr_backspace __PROTO((rxvt_t* r, int page));
void rxvt_scr_tab __PROTO((rxvt_t* r, int page, int count));
void rxvt_scr_backindex __PROTO((rxvt_t* r, int page));
......
......@@ -1677,7 +1677,7 @@ struct rxvt_hidden {
variable
MRXVT_TABTITLE*/
char* env_colorfgbg;
char* buffer;
text_t* buffer; // Jehan
char* locale;
#if 0
......
......@@ -56,7 +56,18 @@ typedef struct
int32_t col;
} row_col_t;
typedef unsigned char text_t;
//typedef unsigned char text_t;
#ifdef HAVE_ICONV_H
// With iconv, characters will be encoded in "UCS-4-INTERNAL", Full Unicode.
typedef uint32_t text_t;
#else
/* Without iconv, characters will be converted to wchar_t, which is often
* Unicode on most platform, though it is not required by the Unicode standard.
* Hence if possible, using iconv is preferred.
*/
typedef wchar_t text_t;
#endif
#if defined(TTY_256COLOR) || defined(MULTICHAR_SET)
# define rend_t uint32_t
#else
......@@ -763,12 +774,24 @@ typedef struct
/*
* Data read from cmd_fd is buffered in here [Child's output buffer]
*/
unsigned char *outbuf_escstart, /* Start of an escape sequence */
*outbuf_escfail, /* Position where processing of an
escape sequence last failed */
unsigned char //*outbuf_escstart, /* Start of an escape sequence */
//*outbuf_escfail, /* Position where processing of an
// escape sequence last failed */
*outbuf_start, /* current char */
*outbuf_end; /* End of read child's output */
unsigned char outbuf_base[BUFSIZ];
text_t *textbuf_escstart,
*textbuf_escfail,
*textbuf_start,
*textbuf_end;
text_t textbuf_base[BUFSIZ];
#ifdef HAVE_ICONV_H
iconv_t shift_state; // Shift state when using iconv.
#else
mbstate_t* shift_state; // Multi-bite Shift state in C99 standard.
#endif
} term_t;
#define TAB_MON_OFF 0 /* tab monitoring off */
......
......@@ -175,7 +175,7 @@ void static inline rxvt_clear_area (rxvt_t*, int page, int x, int y, unsig
void static inline rxvt_fill_rectangle (rxvt_t*, int page, int x, int y, unsigned int w, unsigned int h);
void
rxvt_scr_draw_string (rxvt_t* r, int page,
int x, int y, char* str, int len, int drawfunc,
int x, int y, text_t* str, int len, int drawfunc,
uint16_t fore, uint16_t back,
__attribute__((unused)) rend_t rend, Region refreshRegion);
void rxvt_scr_adjust_col (rxvt_t*, int, unsigned int);
......@@ -232,6 +232,7 @@ void
rxvt_blank_screen_mem(rxvt_t* r, int page, text_t **tp, rend_t **rp,
unsigned int row, rend_t efs)
{
int col;
int width = r->TermWin.ncol;
rend_t *er;
......@@ -245,10 +246,12 @@ rxvt_blank_screen_mem(rxvt_t* r, int page, text_t **tp, rend_t **rp,
if (tp[row] == NULL)
{
tp[row] = rxvt_malloc(sizeof(text_t) * width);
rp[row] = rxvt_malloc(sizeof(rend_t) * width);
tp[row] = rxvt_malloc (sizeof(text_t) * width);
rp[row] = rxvt_malloc (sizeof(rend_t) * width);
}
MEMSET(tp[row], ' ', width);
for (col = 0; col < width; col++)
tp[row][col] = ' ';
//MEMSET(tp[row], 0, sizeof (text_t) * width);//' ', width);
efs &= ~RS_baseattrMask;
for (er = rp[row]; width--;)
*er++ = efs;
......@@ -1076,11 +1079,11 @@ adjust_view_start( rxvt_t *r, int page, int nlines)
*/
/* EXTPROTO */
void
rxvt_scr_add_lines(rxvt_t* r, int page, const unsigned char *str, int nlines,
rxvt_scr_add_lines(rxvt_t* r, int page, text_t* str, int nlines,
int len)
{
unsigned char checksel, clearsel;
char c;
text_t c;
int i, row, last_col;
text_t *stp;
rend_t *srp;
......@@ -1144,6 +1147,7 @@ rxvt_scr_add_lines(rxvt_t* r, int page, const unsigned char *str, int nlines,
stp = PSCR(r, page).text[row];
srp = PSCR(r, page).rend[row];
#if 0
#ifdef MULTICHAR_SET
if(
PVTS(r, page)->lost_multi && CURCOL > 0 &&
......@@ -1153,6 +1157,7 @@ rxvt_scr_add_lines(rxvt_t* r, int page, const unsigned char *str, int nlines,
{
PVTS(r, page)->chstat = WBYTE;
}
#endif
#endif
for (i = 0; i < len;)
......@@ -1196,6 +1201,7 @@ rxvt_scr_add_lines(rxvt_t* r, int page, const unsigned char *str, int nlines,
continue;
default:
#if 0
#ifdef MULTICHAR_SET
if (r->encoding_method == ENC_NOENC)
{
......@@ -1267,6 +1273,7 @@ rxvt_scr_add_lines(rxvt_t* r, int page, const unsigned char *str, int nlines,
}
}
else
#endif
#endif
if (c == 127)
continue; /* yummmm..... */
......@@ -1303,6 +1310,7 @@ rxvt_scr_add_lines(rxvt_t* r, int page, const unsigned char *str, int nlines,
if (PSCR(r, page).flags & Screen_Insert)
rxvt_scr_insdel_chars(r, page, 1, INSERT);
#if 0
#ifdef MULTICHAR_SET
if (
IS_MULTI1(PVTS(r, page)->rstyle)
......@@ -1322,6 +1330,7 @@ rxvt_scr_add_lines(rxvt_t* r, int page, const unsigned char *str, int nlines,
stp[CURCOL + 1] = ' ';
srp[CURCOL + 1] &= ~RS_multiMask;
}
#endif
#endif
stp[CURCOL] = c;
......@@ -2817,8 +2826,7 @@ rxvt_fill_rectangle (rxvt_t* r, int page, int x, int y, unsigned int w, unsigned
void
rxvt_draw_string_xft (rxvt_t* r, Drawable d, GC gc, Region refreshRegion,
rend_t rend, int pfont,
XftDraw* win, XftColor* fore, int x, int y, char* str, int len,
void (*xftdraw_string)())
XftDraw* win, XftColor* fore, int x, int y, text_t* str, int len)
{
XftFont *font;
......@@ -2833,54 +2841,38 @@ rxvt_draw_string_xft (rxvt_t* r, Drawable d, GC gc, Region refreshRegion,
r->TermWin.xftPfont : r->TermWin.xftpfont;
}
#ifdef MULTICHAR_SET
else if( xftdraw_string == XftDrawStringUtf8 )
else
font = r->TermWin.xftmfont;
#endif
else font = r->TermWin.xftfont;
// else font = r->TermWin.xftfont;
rxvt_dbgmsg ((DBG_DEBUG, DBG_SCREEN, "Draw: 0x%8x %p: '%.40s'\n", rend, font, str ));
#ifdef MULTICHAR_SET
if( xftdraw_string == XftDrawStringUtf8 )
len = STRLEN( str);
#endif
# ifdef TEXT_SHADOW
if (r->h->rs[Rs_textShadow] && SHADOW_NONE != r->TermWin.shadow_mode)
{
/*
* Get the bounding box of the rectangle we would draw, and clip to it.
*/
void (*xftTextExtents)() = NULL; /* Suppress compile warning */
XGlyphInfo extents;
int sx, sy; /* Shadow offsets */
rxvt_dbgmsg ((DBG_VERBOSE, DBG_SCREEN, "handling text shadow for %s (%d)\n", str, len));
if( xftdraw_string == XftDrawString8 )
xftTextExtents = XftTextExtents8;
else if( xftdraw_string == XftDrawString16)
xftTextExtents = XftTextExtents16;
else if( xftdraw_string == XftDrawString32)
xftTextExtents = XftTextExtents32;
else if( xftdraw_string == XftDrawStringUtf8)
xftTextExtents = XftTextExtentsUtf8;
else
assert(0); /* Shouldn't happen */
xftTextExtents( r->Xdisplay, font, str, len, &extents);
XftTextExtents32 (r->Xdisplay, font, (FcChar32*) str, len, &extents);
/*
* We should ignore extents.height. The height of the drawn text might
* be much smaller than the height of the font (which is really what
* we've reserved space for.
*/
rxvt_set_clipping( r, win, gc, refreshRegion,
rxvt_set_clipping (r, win, gc, refreshRegion,
x, y - font->ascent, extents.width - extents.x, font->height,
&sx, &sy);
XFTDRAW_STRING (win, &(r->TermWin.xftshadow),
/*XFTDRAW_STRING (win, &(r->TermWin.xftshadow),
font, x+sx, y+sy, str, len);*/
XftDrawString32 (win, &(r->TermWin.xftshadow),
font, x+sx, y+sy, str, len);
/*
* We need to free clipping area, otherwise text on screen may be
......@@ -2891,7 +2883,7 @@ rxvt_draw_string_xft (rxvt_t* r, Drawable d, GC gc, Region refreshRegion,
}
# endif /* TEXT_SHADOW */
XFTDRAW_STRING (win, fore, font, x, y, str, len);
XftDrawString32 (win, fore, font, x, y, (FcChar32*) str, len);
}
#undef XFTDRAW_STRING
#endif /* XFT_SUPPORT */
......@@ -2903,17 +2895,18 @@ rxvt_draw_string_xft (rxvt_t* r, Drawable d, GC gc, Region refreshRegion,
/* EXTPROTO */
void
rxvt_draw_string_x11 (rxvt_t* r, Window win, GC gc, Region refreshRegion,
int x, int y, char* str, int len, int (*draw_string)())
int x, int y, text_t* str, int len, int (*draw_string)())
{
# ifdef TEXT_SHADOW
while (r->h->rs[Rs_textShadow] && SHADOW_NONE != r->TermWin.shadow_mode)
{
int escapement;
int sx, sy;
XGCValues gcvalue;
int (*xtextextents)();
int unused_dir, ascent, descent;
XCharStruct charstruct;
//XCharStruct charstruct;
GContext gid = XGContextFromGC( gc );
XFontStruct *font = XQueryFont( r->Xdisplay, gid);
......@@ -2929,16 +2922,10 @@ rxvt_draw_string_x11 (rxvt_t* r, Window win, GC gc, Region refreshRegion,
/*
* Get the bounding box of the rectangle we would draw, and clip to it.
*/
if( draw_string == XDrawImageString || draw_string == XDrawString)
xtextextents = XTextExtents;
else if ( draw_string == XDrawImageString16 ||
draw_string == XDrawString16)
xtextextents = XTextExtents16;
else
assert(0); /* Shouldn't happen */
xtextextents( font, str, len,
&unused_dir, &ascent, &descent, &charstruct);
//xtextextents( font, str, len,
// &unused_dir, &ascent, &descent, &charstruct);
// XwcTextExtents ??!
escapement = XwcTextEscapement (r->TermWin.fontset, (wchar_t*) str, len);
/*
* If we're using XDrawImageString, then when we draw the actual text,
......@@ -2952,27 +2939,29 @@ rxvt_draw_string_x11 (rxvt_t* r, Window win, GC gc, Region refreshRegion,
XSetFillStyle( r->Xdisplay, gc, FillSolid);
XFillRectangle( r->Xdisplay, win, gc,
x, y - font->ascent,
charstruct.width, font->ascent + font->descent);
escapement, font->ascent + font->descent);
//charstruct.width, font->ascent + font->descent);
if( draw_string == XDrawImageString )
draw_string = XDrawString;
else draw_string = XDrawString16;
}
/*
* Restrict output to the above bounding box.
*/
rxvt_set_clipping( r, NULL, gc, refreshRegion,
x, y - font->ascent,
charstruct.width, font->ascent + font->descent,
//charstruct.width, font->ascent + font->descent,
escapement, font->ascent + font->descent,
&sx, &sy);
/*
* Draw the shadow at the appropriate offset.
*/
XSetForeground (r->Xdisplay, gc, r->TermWin.shadow);
draw_string (r->Xdisplay, win, gc, x+sx, y+sy, str, len);
//draw_string (r->Xdisplay, win, gc, x+sx, y+sy, str, len);
XwcDrawString (r->Xdisplay, win, r->TermWin.fontset, gc, x+sx, y+sy, (wchar_t *) str, len);
/*
* Restore old GC values.
......@@ -2992,7 +2981,8 @@ rxvt_draw_string_x11 (rxvt_t* r, Window win, GC gc, Region refreshRegion,
# endif /* TEXT_SHADOW */
rxvt_dbgmsg ((DBG_DEBUG, DBG_SCREEN, "output entire string: %s\n", str));
draw_string (r->Xdisplay, win, gc, x, y, str, len);
//draw_string (r->Xdisplay, win, gc, x, y, str, len);
XwcDrawString (r->Xdisplay, win, r->TermWin.fontset, gc, x, y, (wchar_t *) str, len);
}
......@@ -3011,34 +3001,22 @@ rxvt_draw_string_x11 (rxvt_t* r, Window win, GC gc, Region refreshRegion,
/* INTPROTO */
void
rxvt_scr_draw_string (rxvt_t* r, int page,
int x, int y, char* str, int len, int drawfunc,
int x, int y, text_t* str, int len, int drawfunc,
uint16_t fore, uint16_t back,
__attribute__((unused)) rend_t rend, Region refreshRegion)
{
#ifdef XFT_SUPPORT
int fillback = 0;
int adjust;
void (*xftdraw_string) () = NULL;
switch (drawfunc)
{
case XFT_DRAW_IMAGE_STRING_8:
fillback = 1;
case XFT_DRAW_STRING_8:
xftdraw_string = XftDrawString8; break;
case XFT_DRAW_IMAGE_STRING_16:
fillback = 1;
case XFT_DRAW_STRING_16:
xftdraw_string = XftDrawString16; break;
break;
}
/*
* adjust is a variable that records whether each character of the string is
* 8 bits or 16 bits
*/
adjust = (XftDrawString8 == xftdraw_string) ? 0 : 1;
if (ISSET_OPTION(r, Opt_xft) && PVTS(r, page)->xftvt && xftdraw_string)
{
register int loop; /* loop iteration number */
......@@ -3047,54 +3025,33 @@ rxvt_scr_draw_string (rxvt_t* r, int page,
/*
** xft_draw_string_xft should call these two parameters
*/
register char* pstr; /* string to print */
register text_t* pstr; /* string to print */
register int plen; /* string length */
char* newstr;
text_t* newstr;
#ifdef MULTICHAR_SET
# ifdef HAVE_ICONV_H
char pbuf[1024]; /* buffer to save UTF-8 string */
text_t pbuf[1024]; /* buffer to save UTF-8 string */
# endif
#endif
/*
* Xft does not support XDrawImageString, so we need to clear the
* background of text by ourselves.
*/
if (fillback)
XftDrawRect( PVTS(r, page)->xftvt, &(r->xftColors[back]),
x, y, Width2Pixel(len * (1 + adjust)), Height2Pixel(1));
/* We use TermWin.xftfont->ascent here */
y += r->TermWin.xftfont->ascent;
/*
* Xft does not support XftDrawString16, so we need to convert the
* string to UTF-8. Here we reencode the string before conversion
*/
# ifdef MULTICHAR_SET
# ifdef HAVE_ICONV_H
if (adjust && (iconv_t) -1 != r->TermWin.xfticonv)
{
register int j, newlen = (len << 1);
switch (r->encoding_method)
{
case ENC_EUCJ:
case ENC_GB:
for (j = 0; j < newlen; j ++)
str[j] |= 0x80;
break;
case ENC_GBK: /* need to do nothing */
case ENC_BIG5: /* need to do nothing */
default:
break;
}
/* we will use utf8 routine to draw string */
xftdraw_string = XftDrawStringUtf8;
XGlyphInfo extents;
XftTextExtents32 (r->Xdisplay, r->TermWin.xftmfont, (XftChar32*) str, len, &extents);
XftDrawRect (PVTS(r, page)->xftvt, &(r->xftColors[back]),
x, y, extents.width, extents.height);
//Width2Pixel(len * (1 + adjust)), Height2Pixel(1));
//Width2Pixel(len), Height2Pixel(1));
// TODO: Nothing to free here?
// TODO: extents.xOff?
}
# endif
# endif /* MULTICHAR_SET */
/* We use TermWin.xftfont->ascent here */
y += r->TermWin.xftfont->ascent;
/*
** If the font is monospace, we print the entire string once,
......@@ -3179,7 +3136,7 @@ rxvt_scr_draw_string (rxvt_t* r, int page,
{
/* print string one by one character */
loop = len;
loopitem = 1 + adjust;
loopitem = 1; //+ adjust;
rxvt_dbgmsg ((DBG_VERBOSE, DBG_SCREEN, "output characters one by one\n"));
}
......@@ -3192,13 +3149,13 @@ rxvt_scr_draw_string (rxvt_t* r, int page,
if (XftDrawStringUtf8 == xftdraw_string)
{
/* We should convert the string to UTF-8 */
char* buf = pbuf; /* always init it */
text_t* buf = pbuf; /* always init it */
int buflen = sizeof(pbuf)-1;/* always init it */
int newlen = loopitem; /* always init it */
char* oldstr = newstr;
text_t* oldstr = newstr;
iconv (r->TermWin.xfticonv, (char**)(&newstr),
(size_t*) &newlen, &buf, (size_t*) &buflen);
*buf = (char) 0; /* set end of string */
*buf = (text_t) 0; /* set end of string */
pstr = pbuf;
/*
* we should use the length of original string, not UTF-8 string
......@@ -3222,7 +3179,7 @@ rxvt_scr_draw_string (rxvt_t* r, int page,
rxvt_draw_string_xft(r, PVTS( r, page)->vt, r->TermWin.gc,
refreshRegion, rend, NO_PFONT,
PVTS(r, page)->xftvt, &(r->xftColors[fore]),
x, y, pstr, plen, xftdraw_string);
x, y, pstr, plen);
x += Width2Pixel (loopitem);
newstr += loopitem; /* next string to display */
......@@ -3350,7 +3307,7 @@ rxvt_scr_refresh(rxvt_t* r, int page, unsigned char refresh_type)
rend_t* srp; /* screen-rend-pointer */
text_t* dtp; /* drawn-text pointer */
text_t* stp; /* screen-text-pointer */
char* buffer; /* local copy of r->h->buffer */
text_t* buffer; /* local copy of r->h->buffer */ // Jehan
/*
int (*drawfunc) () = XDrawString;
int (*image_drawfunc) () = XDrawImageString;
......@@ -3408,7 +3365,7 @@ rxvt_scr_refresh(rxvt_t* r, int page, unsigned char refresh_type)
if (h->currmaxcol < r->TermWin.ncol)
{
h->currmaxcol = r->TermWin.ncol;
h->buffer = rxvt_realloc(h->buffer, sizeof(char) * (h->currmaxcol + 1));
h->buffer = rxvt_realloc(h->buffer, sizeof(text_t) * (h->currmaxcol + 1));
}
buffer = h->buffer;
......
......@@ -360,23 +360,23 @@ draw_string (rxvt_t* r, Region clipRegion,
&& (iconv_t) -1 != r->TermWin.xfticonv
)
{
char buf[1024];
text_t buf[1024];
int plen = 1023;
char* pstr = buf;
text_t* pstr = buf;
int olen = len;
char* ostr = str;
/* convert to UTF-8 */
iconv (r->TermWin.xfticonv, (char**) &ostr,
(size_t*) &olen, &pstr, (size_t*) &plen);
*pstr = (char) 0; /* set end of string */
*pstr = (text_t) 0; /* set end of string */
rxvt_draw_string_xft (r, r->tabBar.win, r->tabBar.gc,
clipRegion, RS_None,
active ? USE_BOLD_PFONT : USE_PFONT,
r->tabBar.xftwin,
active ? &(r->tabBar.xftfg) : &(r->tabBar.xftifg),
x, y, buf, len, XftDrawStringUtf8);
x, y, buf, len);
if( r->TermWin.xftpfont )
{
XftTextExtentsUtf8( r->Xdisplay, r->TermWin.xftpfont,
......@@ -394,7 +394,7 @@ draw_string (rxvt_t* r, Region clipRegion,
active ? USE_BOLD_PFONT : USE_PFONT,
r->tabBar.xftwin,
active ? &(r->tabBar.xftfg) : &(r->tabBar.xftifg),
x, y, str, len, XftDrawString8);
x, y, str, len);
if( r->TermWin.xftpfont )
{
......@@ -439,7 +439,7 @@ draw_string (rxvt_t* r, Region clipRegion,
active ? USE_BOLD_PFONT : USE_PFONT,
r->tabBar.xftwin,
active ? &(r->tabBar.xftfg) : &(r->tabBar.xftifg),
x, y, str, len, XftDrawString8);
x, y, str, len);
if( r->TermWin.xftpfont )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment