From 9e0f57b4182864026818ae1c0aa2ab4868c47d16 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 1 Dec 2015 14:30:09 +0100 Subject: [PATCH] Output renderer: Reverse the order of table columns when in RTL locale When operating in a RTL locale, the last column of a table should be rendered "first" (ie. leftmost). This change achieves that. In order to determine if the locale is a RTL locale, a new translatable string is introduced. This string must be localised by the translator of the .po file for RTL locales. LTR locales can leave it untranslated. Reported by: Mohammad Haghighat --- src/output/render.c | 32 ++++++++++++++++++++++++++++++++ src/output/render.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/output/render.c b/src/output/render.c index c50e1121e7..b3eb6c93d4 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -33,6 +33,9 @@ #include "gl/minmax.h" #include "gl/xalloc.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + /* This file uses TABLE_HORZ and TABLE_VERT enough to warrant abbreviating. */ #define H TABLE_HORZ #define V TABLE_VERT @@ -966,6 +969,23 @@ is_rule (int z) return !(z & 1); } +bool +render_direction_rtl (void) +{ + /* TRANSLATORS: Do not translate this string. If the script of your language + reads from right to left (eg Persian, Arabic, Hebrew etc), then replace + this string with "output-direction-rtl". Otherwise either leave it + untranslated or copy it verbatim. */ + const char *dir = _("output-direction-ltr"); + if ( 0 == strcmp ("output-direction-rtl", dir)) + return true; + + if ( 0 != strcmp ("output-direction-ltr", dir)) + fprintf (stderr, "This localisation has been incorrectly translated. Complain to the translator.\n"); + + return false; +} + static void render_rule (const struct render_page *page, const int ofs[TABLE_N_AXES], const int d[TABLE_N_AXES]) @@ -1009,6 +1029,12 @@ render_rule (const struct render_page *page, const int ofs[TABLE_N_AXES], bb[H][0] = ofs[H] + page->cp[H][d[H]]; bb[H][1] = ofs[H] + page->cp[H][d[H] + 1]; + if (render_direction_rtl ()) + { + int temp = bb[H][0]; + bb[H][0] = page->params->size[H] - bb[H][1]; + bb[H][1] = page->params->size[H] - temp; + } bb[V][0] = ofs[V] + page->cp[V][d[V]]; bb[V][1] = ofs[V] + page->cp[V][d[V] + 1]; page->params->draw_line (page->params->aux, bb, styles); @@ -1025,6 +1051,12 @@ render_cell (const struct render_page *page, const int ofs[TABLE_N_AXES], bb[H][0] = clip[H][0] = ofs[H] + page->cp[H][cell->d[H][0] * 2 + 1]; bb[H][1] = clip[H][1] = ofs[H] + page->cp[H][cell->d[H][1] * 2]; + if (render_direction_rtl ()) + { + int temp = bb[H][0]; + bb[H][0] = clip[H][0] = page->params->size[H] - bb[H][1]; + bb[H][1] = clip[H][1] = page->params->size[H] - temp; + } bb[V][0] = clip[V][0] = ofs[V] + page->cp[V][cell->d[V][0] * 2 + 1]; bb[V][1] = clip[V][1] = ofs[V] + page->cp[V][cell->d[V][1] * 2]; diff --git a/src/output/render.h b/src/output/render.h index 3e9d8a83ad..ed5bb1eaf4 100644 --- a/src/output/render.h +++ b/src/output/render.h @@ -145,4 +145,7 @@ void render_pager_draw_region (const struct render_pager *, int render_pager_get_size (const struct render_pager *, enum table_axis); int render_pager_get_best_breakpoint (const struct render_pager *, int height); +bool render_direction_rtl (void); + + #endif /* output/render.h */ -- 2.30.2