[links] BIDI support for links 2.1 (fwd)

Matan Ziv-Av <[email protected]> Wed, 23 Mar 2005 01:17:04 +0200 (IST)
Newsgroups gmane.comp.web.links.list
Message-ID <[email protected]>
Hello,

this patch (relative to links-2.1pre17) adds rudimentary support for displaying 
hebrew text in the correct direction.
It does not include the changes for the build system, since I can't run the 
configure generated on my system from configure.in.
For compiling and linking the new code, USE_FRIBIDI needs to be defined in 
config.h, and -lfribidi should be on the link command line. I think adding 
lines like:

cf_use_bidi=no
AC_MSG_CHECKING([if you want to use bidi])
AC_ARG_ENABLE(bidi, [  --enable-bidi           use bidi], 
cf_use_bidi=$enableval )
AC_MSG_RESULT($cf_use_bidi)

if test "$cf_use_bidi" = yes; then
     AC_DEFINE(USE_FRIBIDI)
     LIBS="$LIBS -lfribidi"
fi

to configure.in should do the trick, but I am not really sure.

-- 
Matan Ziv-Av.                         [email protected]

_______________________________________________
links-list mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/links-list
fribidi.patch (text/plain, 4.4 KB)
--- ../o/links-2.1pre17/html_r.c	2005-01-22 22:51:53.000000000 +0200
+++ html_r.c	2005-03-22 23:29:20.173549984 +0200
@@ -5,6 +5,10 @@
 
 #include "links.h"
 
+#ifdef USE_FRIBIDI
+#include <fribidi/fribidi.h>
+#endif
+ 
 #define format format_
 
 struct f_data *init_formatted(struct document_options *opt)
@@ -521,8 +525,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);
 	}
@@ -654,6 +660,7 @@
 
 	int bg, fg;
 	int i;
+	int opcx;
 	struct link *link;
 	struct point *pt;
 	if (l < 0) overalloc();
@@ -676,11 +683,15 @@
 	if (p->y < p->cy + 1) p->y = p->cy + 1;
 	if (nowrap && p->cx + l > rm(par_format)) return;
 	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--;
@@ -688,8 +699,50 @@
 			if (!(x = split_line(p))) break;
 			/*if (LEN(p->cy-1) > p->x) p->x = LEN(p->cy-1);*/
 			align_line(p, p->cy - 1);
+#ifdef USE_FRIBIDI
+		if(p->data){
+			unsigned char txt[1024];
+			unsigned char utext[1024];
+			int ll, j, i;
+			i=LEN(p->cy-1);
+			FriBidiCharType base = FRIBIDI_TYPE_ON;
+
+			for(j=opcx;j<i;j++)txt[j-opcx]=POS(j, p->cy-1);
+			txt[j-opcx]=0;
+			
+			ll=fribidi_iso8859_8_to_unicode(txt, i-opcx, utext);
+			fribidi_log2vis( utext, ll, &base,
+					txt, NULL, NULL, NULL);
+			fribidi_unicode_to_iso8859_8(txt, ll, utext);
+			for(j=opcx;j<i;j++)POS(j, p->cy-1)=utext[j-opcx];
+			opcx=0;
+		}
+#endif
 			nobreak = x - 1;
 		}
+			
+#ifdef USE_FRIBIDI 
+		if(!cont) {
+			opcx=0;
+		}
+		if(p->data) {
+			unsigned char txt[1024];
+			unsigned char utext[1024];
+			int ll, j, i;
+			i=LEN(p->cy);
+			FriBidiCharType base = FRIBIDI_TYPE_ON;
+
+			for(j=opcx;j<i;j++)txt[j-opcx]=POS(j, p->cy);
+			txt[j-opcx]=0;
+			
+			ll=fribidi_iso8859_8_to_unicode(txt, i-opcx, utext);
+			fribidi_log2vis( utext, ll, &base,
+					txt, NULL, NULL, NULL);
+			fribidi_unicode_to_iso8859_8(txt, ll, utext);
+			for(j=opcx;j<i;j++)POS(j, p->cy)=utext[j-opcx];
+		}
+#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;
 
--- ../o/links-2.1pre17/terminal.c	2005-01-02 22:17:26.000000000 +0200
+++ terminal.c	2005-03-22 18:05:54.568650344 +0200
@@ -5,6 +5,10 @@
 
 #include "links.h"
 
+#ifdef USE_FRIBIDI
+#include <fribidi/fribidi.h>
+#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);
 }
--- ../o/links-2.1pre17/dip.c	2005-01-02 22:17:25.000000000 +0200
+++ dip.c	2005-03-22 16:42:20.967833520 +0200
@@ -12,6 +12,10 @@
 
 #include "links.h"
 
+#ifdef USE_FRIBIDI
+#include <fribidi/fribidi.h>
+#endif
+
 #ifdef HAVE_MATH_H
 #include <math.h>
 #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 */