summaryrefslogtreecommitdiff
blob: 91aa55c1f12dbe3494b43da5a6007ad2ed704899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
From 800fc7caa9728cebafee86d841ac23b6ffaa896b Mon Sep 17 00:00:00 2001
From: Brian Bidulock <bidulock@openss7.org>
Date: Wed, 5 Nov 2014 03:25:44 -0700
Subject: [PATCH] fribidi support (gentoo icewm-1.3.9-fribidi.patch)

  Also fixes several problems with the gentoo patch:

  1) the patch modifies CORE_CFLAGS and CORE_LIBS before they
     are first defined, confusing later PKG_CONFIG([CORE], ...)
     so I moved it later in configure.ac

  2) the patch uses the deprecated fribidi_log2vis, so I modified
     src/yfontxft.cc to disabled deprecated symbols (because I
     always test build with -Werror).

  3) the patch ignores the return value of fribidi_log2vis()
     causing another warning which -Werror turns into an error.
     Changed to "if (fribidi_log2vis(...)) ;" to disable that.

  4) fixed the configure.ac macro check for fribidi to only warn
     when the library is not present but the feature has not
     been disabled

  5) add fribidi to configure.ac features list shown at end of
     ./configure run (added xrandr and xinerama too...)
---
 configure.ac    | 17 +++++++++++++++--
 src/yfontxft.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index dce4f1e..63d362f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -158,7 +158,8 @@ if test x$enable_xrandr != xno; then
     PKG_CHECK_MODULES([XRANDR],[xrandr],[
 	CORE_CFLAGS="$XRANDR_CFLAGS $CORE_CFLAGS"
 	CORE_LIBS="$XRANDR_LIBS $CORE_LIBS"
-	AC_DEFINE([CONFIG_XRANDR],[1],[Define to enable XRANDR extension.])],
+	AC_DEFINE([CONFIG_XRANDR],[1],[Define to enable XRANDR extension.])
+	features="$features xrandr"],
 	[AC_MSG_WARN([XRANDR not supported.])])
 fi
 
@@ -270,10 +271,22 @@ if test x$enable_xinerama != xno ; then
     PKG_CHECK_MODULES([XINERAMA],[xinerama],[
 	CORE_CFLAGS="$XINERAMA_CFLAGS $CORE_CFLAGS"
 	CORE_LIBS="$XINERAMA_LIBS $CORE_LIBS"
-	AC_DEFINE([XINERAMA],[1],[Define to enable Xinerama support.])],
+	AC_DEFINE([XINERAMA],[1],[Define to enable Xinerama support.])
+	features="$features xinerama"],
 	[AC_MSG_WARN([XINERAMA is not supported.])])
 fi
 
+AC_ARG_ENABLE([fribidi],
+    AC_HELP_STRING([--disable-fribidi],[Disable right to left support.]))
+if test "$enable_fribidi" != "no" && test "$enable_i18n" != "no"; then
+    PKG_CHECK_MODULES([FRIBIDI], [fribidi],[
+	CORE_CFLAGS="$FRIBIDI_CFLAGS $CORE_CFLAGS"
+	CORE_LIBS="$FRIBIDI_LIBS $CORE_LIBS"
+	AC_DEFINE([CONFIG_FRIBIDI],[1],[Define to enable fribidi support.])
+	features="$features fribidi"],
+	[AC_MSG_WARN([FRIBIDI is not supported.])])
+fi
+
 AC_ARG_ENABLE([prefs],
     AC_HELP_STRING([--disable-prefs],[Disable configurable preferences.]))
 if test x$enable_prefs = xno ; then
diff --git a/src/yfontxft.cc b/src/yfontxft.cc
index c200dc6..01b52f9 100644
--- a/src/yfontxft.cc
+++ b/src/yfontxft.cc
@@ -6,6 +6,18 @@
 #include "ypaint.h"
 #include "yxapp.h"
 #include "intl.h"
+#include <stdio.h>
+
+#ifdef CONFIG_FRIBIDI
+	// remove deprecated warnings for now...
+	#include <fribidi/fribidi-config.h>
+	#if FRIBIDI_USE_GLIB+0
+		#include <glib.h>
+		#undef G_GNUC_DEPRECATED
+		#define G_GNUC_DEPRECATED
+	#endif
+	#include <fribidi/fribidi.h>
+#endif
 
 /******************************************************************************/
 
@@ -69,10 +81,45 @@ class XftGraphics {
                            char_t * str, size_t len)
     {
         XftColor *c = *g.color();
+
+#ifdef CONFIG_FRIBIDI
+
+#define STATIS_STRING_SIZE	256
+
+		// Based around upstream (1.3.2) patch with some optimization
+		//   on my end. (reduce unnecessary memory allocation)
+		// - Gilboa
+
+		char_t static_str[STATIS_STRING_SIZE];
+		char_t *vis_str = static_str;
+
+		if (len >= STATIS_STRING_SIZE)
+		{
+			vis_str = new char_t[len+1];
+			if (!vis_str)
+				return;
+		}
+
+		FriBidiCharType pbase_dir = FRIBIDI_TYPE_N;
+		if (fribidi_log2vis(str, len, &pbase_dir, //input
+						vis_str, // output
+						NULL, NULL, NULL // "statistics" that we don't need
+						)) ;
+		str = vis_str;
+#endif
+
         XftDrawString(g.handleXft(), c, font,
                       x - g.xorigin(),
                       y - g.yorigin(),
                       str, len);
+
+#ifdef CONFIG_FRIBIDI
+
+		if (vis_str != static_str)
+			delete[] str;
+
+#endif
+
     }
 
     static void textExtents(XftFont * font, char_t * str, size_t len,