diff -X xclude -ubBwrN o/links-2.1pre17/dip.c links-2.1pre17/dip.c --- o/links-2.1pre17/dip.c 2005-01-02 22:17:25.000000000 +0200 +++ links-2.1pre17/dip.c 2005-03-22 16:42:20.000000000 +0200 @@ -12,6 +12,10 @@ #include "links.h" +#ifdef USE_FRIBIDI +#include +#endif + #ifdef HAVE_MATH_H #include #endif /* HAVE_MATH_H */ @@ -1732,6 +1736,19 @@ my_width; struct rect saved_clip; +#ifdef USE_FRIBIDI + unsigned char txt[1024]; + unsigned char utext[1024]; + int l; + FriBidiCharType base = FRIBIDI_TYPE_ON; + + l=fribidi_utf8_to_unicode(text, strlen(text), utext); + fribidi_log2vis( utext, l, &base, + txt, NULL, NULL, NULL); + fribidi_unicode_to_utf8(txt, l, utext); + text=utext; +#endif + if (y+style->height<=device->clip.y1||y>=device->clip.y2) goto o; if (style -> flags){ /* Underline */ diff -X xclude -ubBwrN o/links-2.1pre17/html_r.c links-2.1pre17/html_r.c --- o/links-2.1pre17/html_r.c 2005-01-22 22:51:53.000000000 +0200 +++ links-2.1pre17/html_r.c 2005-03-30 00:11:24.000000000 +0200 @@ -5,6 +5,12 @@ #include "links.h" +#ifdef USE_FRIBIDI +#include +#define RTL 1 +#endif +#undef USE_FRIBIDI + #define format format_ struct f_data *init_formatted(struct document_options *opt) @@ -521,8 +527,10 @@ if (i + par_format.rightmargin > p->x) p->x = i + par_format.rightmargin; if (p->data) { #ifdef DEBUG +#ifndef USE_FRIBIDI if ((POS(i, p->cy) & 0xff) != ' ') internal("bad split: %c", (char)POS(i, p->cy)); #endif +#endif move_chars(p, i+1, p->cy, par_format.leftmargin, p->cy+1); del_chars(p, i, p->cy); } @@ -536,14 +544,15 @@ return 1 + (p->cx == -1); } -void align_line(struct part *p, int y) +int align_line(struct part *p, int y) { int na; - if (!p->data) return; - if (!LEN(y) || par_format.align == AL_LEFT || par_format.align == AL_NO || par_format.align == AL_BLOCK /* !!! fixme! */) return; + if (!p->data) return 0; + if (!LEN(y) || par_format.align == AL_LEFT || par_format.align == AL_NO || par_format.align == AL_BLOCK /* !!! fixme! */) return 0; na = rm(par_format) - LEN(y); if (par_format.align == AL_CENTER) na /= 2; if (na > 0) shift_chars(p, y, na); + return na; } struct link *new_link(struct f_data *f) @@ -651,14 +660,35 @@ static struct text_attrib_beginning ta_cache = { -1, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, 0 }; static int bg_cache; static int fg_cache; +#ifdef USE_FRIBIDI + static int last_xpos=999; + int rtl, aligned; +#endif int bg, fg; int i; + int opcx; struct link *link; struct point *pt; + if (l < 0) overalloc(); - /*printf("%d-", p->cx);for (i=0; icx);for (i=0; idata && p->data->cp==8) { + i=0; + if(RTL)while(!rtl && i=225)&&(c[i]<=251); + i++; + } + rtl=1; + } +#endif + while (par_format.align != AL_NO && p->cx == -1 && l && *c == ' ') c++, l--; + if (!l) return; if (c[0] != ' ' || (c[1] && c[1] != ' ')) { last_tag_for_newline = (void *)&p->data->tags; @@ -675,21 +705,126 @@ if (p->cx == par_format.leftmargin && *c == ' ' && par_format.align != AL_NO) c++, l--; if (p->y < p->cy + 1) p->y = p->cy + 1; if (nowrap && p->cx + l > rm(par_format)) return; +//fprintf(stderr, "set_h %i %i %i %c%c\n", p->cx, p->cy, l, c[0], c[1]); set_hline(p, p->cx, p->cy, l, c, (((fg&0x08)<<3)|(bg<<3)|(fg&0x07))<<8, 1); + opcx=p->cx; p->cx += l; nobreak = 0; - if (par_format.align != AL_NO) + if (par_format.align != AL_NO) { + int cont=1; + while (p->cx > rm(par_format) && p->cx > par_format.leftmargin) { int x; + cont=0; /*if (p->cx > p->x) { p->x = p->cx + par_format.rightmargin; if (c[l - 1] == ' ') p->x--; }*/ if (!(x = split_line(p))) break; /*if (LEN(p->cy-1) > p->x) p->x = LEN(p->cy-1);*/ +#ifdef USE_FRIBIDI + aligned=0; + if(rtl) { + aligned=align_line(p, p->cy - 1); + // p->cx+=aligned; + opcx+=aligned; +fprintf(stderr, "aligned %i\n", aligned); + } else +#endif align_line(p, p->cy - 1); + +#ifdef USE_FRIBIDI + if(rtl && p->data){ + unsigned char txt[1024]; + unsigned char utext[1024]; + int ll, j, i, start; + i=LEN(p->cy-1); + FriBidiCharType base = FRIBIDI_TYPE_ON; + + if(i<512) { + start=opcx; +fprintf(stderr, "A opcx=%i i=%i\n", opcx,i); + while(opcxcy-1)==' ')opcx++; + +fprintf(stderr, "A %4i text=", opcx); +for(j=opcx;jcy-1)); +fprintf(stderr, "]]]\n"); + if(opcxcy-1); + txt[j-opcx]=0; + + ll=fribidi_iso8859_8_to_unicode(txt, i-opcx, (FriBidiChar *)utext); + fribidi_log2vis( (FriBidiChar *)utext, ll, &base, + (FriBidiChar *)txt, NULL, NULL, NULL); + fribidi_unicode_to_iso8859_8((FriBidiChar *)txt, ll, utext); + for(j=opcx;jcy-1)=utext[j-opcx]; + } + if(start) { + /* two blocks - replace them */ + unsigned short t[1024]; + int j; +fprintf(stderr, "replace %i %i %i\n",last_xpos, start, i); + if(last_xposcy-1)!=' ')start++; + for (j=aligned;jcy-1); + for(j=start;jcy-1)=POS(j,p->cy-1); + for(j=i-start;jcy-1)=t[j-i+start+aligned]; + } + } + opcx=0; + } +#endif nobreak = x - 1; } + +#ifdef USE_FRIBIDI + if(!cont) { + opcx=0; + } + if(rtl && p->data) { + unsigned char txt[1024]; + unsigned char utext[1024]; + int ll, j, i, start; + i=LEN(p->cy); + FriBidiCharType base = FRIBIDI_TYPE_ON; + start=opcx; + + if(i<512) { +fprintf(stderr, "B opcx=%i i=%i\n", opcx,i); + while(opcxcy)==' ')opcx++; + +fprintf(stderr, "B %4i text=", opcx); +for(j=opcx;jcy)); +fprintf(stderr, "]]]\n"); + if(opcxcy); + txt[j-opcx]=0; + + ll=fribidi_iso8859_8_to_unicode(txt, i-opcx, (FriBidiChar *)utext); + fribidi_log2vis( (FriBidiChar *)utext, ll, &base, + (FriBidiChar *)txt, NULL, NULL, NULL); + fribidi_unicode_to_iso8859_8((FriBidiChar *)txt, ll, utext); + for(j=opcx;jcy)=utext[j-opcx]; + + if(start) { + /* two blocks - replace them */ + unsigned short t[1024]; + int j; +fprintf(stderr, "Breplace %i %i %i\n",last_xpos, start, i); + if(last_xposcy)!=' ')start++; + for (j=0;jcy); + for(j=start;jcy)=POS(j,p->cy); + for(j=i-start;jcy)=t[j-i+start]; + } + + last_xpos=i; +fprintf(stderr, "ll=%3i l_x=%3i\n",ll,last_xpos ); + } + } + } +#endif + } if ((p->xa += l) - (c[l-1] == ' ' && par_format.align != AL_NO) + par_format.leftmargin + par_format.rightmargin > p->xmax) p->xmax = p->xa - (c[l-1] == ' ' && par_format.align != AL_NO) + par_format.leftmargin + par_format.rightmargin; return; @@ -981,6 +1116,45 @@ parse_html(start, end, (void (*)(void *, unsigned char *, int)) put_chars_conv, (void (*)(void *)) line_break, (void *(*)(void *, int, ...)) html_special, part, head); /*if ((part->y -= line_breax) < 0) part->y = 0;*/ ) {}; +fprintf(stderr, "%08x %08x %ix%i\n", start, end, part->x, part->y); + if(part->data && part->x>0 && part->y>0) { + struct part *p=part; + int i,j,unreal; + unreal=0; + for(i=0;iy;i++) if(LEN(i)>part->x)unreal=1; + + if(!unreal)for(i=0;iy;i++) { + unsigned char t[1024], u[1024]; + FriBidiStrIndex q[1024]; + unsigned short v[1024]; + unsigned char conv[256]; + int x, l, j, ll; + FriBidiCharType base = FRIBIDI_TYPE_RTL; + + for(j=0;j<255;j++) conv[j]=j; + conv['(']=')'; + conv[')']='('; + conv['[']=']'; + conv[']']='['; + l=LEN(i); + x=0; + while(xy;i++) { + for(j=0;j +#endif + #ifdef G void t_redraw(struct graphics_device *, struct rect *); @@ -1030,6 +1034,19 @@ void print_text(struct terminal *t, int x, int y, int l, unsigned char *text, unsigned c) { +#ifdef USE_FRIBIDI + unsigned char txt[1024]; + unsigned char utext[1024]; + int ll; + FriBidiCharType base = FRIBIDI_TYPE_ON; + + ll=fribidi_iso8859_8_to_unicode(text, strlen(text), utext); + fribidi_log2vis( utext, ll, &base, + txt, NULL, NULL, NULL); + fribidi_unicode_to_iso8859_8(txt, ll, utext); + text=utext; +#endif + NO_GFX; for (; l-- && *text; text++, x++) set_char(t, x, y, *text + c); }