From a8e7344373e412f45b08c7d7606768604ab919b3 Mon Sep 17 00:00:00 2001 From: Alon Tzarafi Date: Sat, 18 Nov 2017 00:08:12 +0200 Subject: [PATCH] Adds an optional fix for right-to-left text Rtl text was disordering the calendar cells between columns. Added a setting to enable a fix. The fix is made optional because it depends on a special unicode character (the "LEFT-TO-RIGHT EMBEDDING" character). --- calfw.el | 19 +++++++++++++++---- readme.md | 11 +++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/calfw.el b/calfw.el index 9d190ee..ae3092f 100644 --- a/calfw.el +++ b/calfw.el @@ -206,6 +206,15 @@ for example `cfw:read-date-command-simple' or `cfw:org-read-date-command'." :group 'cfw :type 'boolean) +(defcustom cfw:fix-rtl-content nil + "If not-nil, calfw fixes right-to-left content in cells. +When using rtl content without this enabled, the order +of cells can be ruined e.g. the 2nd appears before the 1st. +This fixes it by adding a \"Left-to-right Embedding\" unicode +character to column separators." + :group 'cfw + :type 'boolean) + ;;; Faces (defface cfw:face-title @@ -1729,15 +1738,17 @@ algorithm defined at `cfw:render-line-breaker'." (cell-width (cfw:k 'cell-width param)) (columns (cfw:k 'columns param)) (num-cell-char - (/ cell-width (char-width cfw:fchar-horizontal-line)))) + (/ cell-width (char-width cfw:fchar-horizontal-line))) + (left-to-right-enforce-char "\x202a") + (rtl-column-fix (if cfw:fix-rtl-content left-to-right-enforce-char ""))) (append param - `((eol . ,EOL) (vl . ,(cfw:rt (make-string 1 cfw:fchar-vertical-line) 'cfw:face-grid)) + `((eol . ,EOL) (vl . ,(cfw:rt (concat (make-string 1 cfw:fchar-vertical-line) rtl-column-fix ) 'cfw:face-grid)) (hline . ,(cfw:rt (concat (loop for i from 0 below columns concat (concat - (make-string 1 (if (= i 0) cfw:fchar-top-left-corner cfw:fchar-top-junction)) + (make-string 1 (if (= i 0) cfw:fchar-top-left-corner cfw:fchar-top-junction)) rtl-column-fix (make-string num-cell-char cfw:fchar-horizontal-line))) (make-string 1 cfw:fchar-top-right-corner) EOL) 'cfw:face-grid)) @@ -1745,7 +1756,7 @@ algorithm defined at `cfw:render-line-breaker'." (concat (loop for i from 0 below columns concat (concat - (make-string 1 (if (= i 0) cfw:fchar-left-junction cfw:fchar-junction)) + (make-string 1 (if (= i 0) cfw:fchar-left-junction cfw:fchar-junction)) rtl-column-fix (make-string num-cell-char cfw:fchar-horizontal-line))) (make-string 1 cfw:fchar-right-junction) EOL) 'cfw:face-grid)))))) diff --git a/readme.md b/readme.md index d9f67f7..dc2f65d 100644 --- a/readme.md +++ b/readme.md @@ -326,6 +326,17 @@ In the current implementation, the Calfw has 3 strategies: none, simple and word - `cfw:render-line-breaker-wordwrap` - This strategy breaks lines with the emacs function `fill-region`. Although, the line breaking algorithm of the Emacs is not so smart as more complicated ones, such as Knuth/Plass algorithm, this strategy is better than the simple one. +### Right-to-left text + +Right-to-left events can disorder the cells' texts between columns. +If this happens you can fix it using: + +```el +(setq cfw:fix-rtl-content t) +``` + +(The fix adds a "Left-to-right Embedding" unicode character to column breaks) + ## Calfw framework details In this section, I would explain how to add a new calendar source and how to embed the calfw component in the other applications.