sent-bidi-20220622-9ed2713.diff (3347B)
1 From 9ed271353ddeadd66e6550aa79065b601b3d6cf4 Mon Sep 17 00:00:00 2001 2 From: Mahdi Mirzadeh <mahdi@mirzadeh.pro> 3 Date: Wed, 22 Jun 2022 02:55:13 +0430 4 Subject: [PATCH] Added support for RTL languages (Farsi, Arabic and Hebrew 5 using the FriBiDi library) to sent 6 7 --- 8 config.mk | 13 ++++++++----- 9 sent.c | 28 ++++++++++++++++++++++++++-- 10 2 files changed, 34 insertions(+), 7 deletions(-) 11 12 diff --git a/config.mk b/config.mk 13 index d61c554..8e74aee 100644 14 --- a/config.mk 15 +++ b/config.mk 16 @@ -10,14 +10,17 @@ MANPREFIX = ${PREFIX}/share/man 17 X11INC = /usr/X11R6/include 18 X11LIB = /usr/X11R6/lib 19 20 +BDINC = /usr/include/fribidi 21 +BDLIBS = -lfribidi 22 + 23 # includes and libs 24 -INCS = -I. -I/usr/include -I/usr/include/freetype2 -I${X11INC} 25 -LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 26 +INCS = -I. -I/usr/include -I/usr/include/freetype2 -I${X11INC} -I$(BDINC) 27 +LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 $(BDLIBS) 28 # OpenBSD (uncomment) 29 -#INCS = -I. -I${X11INC} -I${X11INC}/freetype2 30 +#INCS = -I. -I${X11INC} -I${X11INC}/freetype2 -I$(BDINC) 31 # FreeBSD (uncomment) 32 -#INCS = -I. -I/usr/local/include -I/usr/local/include/freetype2 -I${X11INC} 33 -#LIBS = -L/usr/local/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 34 +#INCS = -I. -I/usr/local/include -I/usr/local/include/freetype2 -I${X11INC} -I/usr/local/include/fribidi 35 +#LIBS = -L/usr/local/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 $(BDLIBS) 36 37 # flags 38 CPPFLAGS = -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=600 39 diff --git a/sent.c b/sent.c 40 index 9534fca..a03475b 100644 41 --- a/sent.c 42 +++ b/sent.c 43 @@ -18,6 +18,7 @@ 44 #include <X11/Xlib.h> 45 #include <X11/Xutil.h> 46 #include <X11/Xft/Xft.h> 47 +#include <fribidi.h> 48 49 #include "arg.h" 50 #include "util.h" 51 @@ -117,6 +118,7 @@ static void configure(XEvent *); 52 53 /* Globals */ 54 static const char *fname = NULL; 55 +static char fribidi_text[BUFSIZ] = ""; 56 static Slide *slides = NULL; 57 static int idx = 0; 58 static int slidecount = 0; 59 @@ -134,6 +136,26 @@ static void (*handler[LASTEvent])(XEvent *) = { 60 [KeyPress] = kpress, 61 }; 62 63 +static void 64 +apply_fribidi(char *str) 65 +{ 66 + FriBidiStrIndex len = strlen(str); 67 + FriBidiChar logical[BUFSIZ]; 68 + FriBidiChar visual[BUFSIZ]; 69 + FriBidiParType base = FRIBIDI_PAR_ON; 70 + FriBidiCharSet charset; 71 + fribidi_boolean result; 72 + 73 + fribidi_text[0] = 0; 74 + if (len>0) 75 + { 76 + charset = fribidi_parse_charset("UTF-8"); 77 + len = fribidi_charset_to_unicode(charset, str, len, logical); 78 + result = fribidi_log2vis(logical, len, &base, visual, NULL, NULL, NULL); 79 + len = fribidi_unicode_to_charset(charset, visual, len, fribidi_text); 80 + } 81 +} 82 + 83 int 84 filter(int fd, const char *cmd) 85 { 86 @@ -528,15 +550,17 @@ xdraw() 87 88 if (!im) { 89 drw_rect(d, 0, 0, xw.w, xw.h, 1, 1); 90 - for (i = 0; i < slides[idx].linecount; i++) 91 + for (i = 0; i < slides[idx].linecount; i++) { 92 + apply_fribidi(slides[idx].lines[i]); 93 drw_text(d, 94 (xw.w - width) / 2, 95 (xw.h - height) / 2 + i * linespacing * d->fonts->h, 96 width, 97 d->fonts->h, 98 0, 99 - slides[idx].lines[i], 100 + fribidi_text, 101 0); 102 + } 103 drw_map(d, xw.win, 0, 0, xw.w, xw.h); 104 } else { 105 if (!(im->state & SCALED)) 106 -- 107 2.35.2 108