Skip to content

Commit

Permalink
Adds an optional fix for right-to-left text
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
AlonTzarafi committed Nov 17, 2017
1 parent 3415d86 commit a8e7344
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
19 changes: 15 additions & 4 deletions calfw.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1729,23 +1738,25 @@ 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))
(cline . ,(cfw:rt
(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))))))

Expand Down
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a8e7344

Please sign in to comment.