summaryrefslogtreecommitdiff
path: root/macros/xetex/latex/xepersian-hm/kashida-xepersian-hm.def
diff options
context:
space:
mode:
Diffstat (limited to 'macros/xetex/latex/xepersian-hm/kashida-xepersian-hm.def')
-rw-r--r--macros/xetex/latex/xepersian-hm/kashida-xepersian-hm.def132
1 files changed, 132 insertions, 0 deletions
diff --git a/macros/xetex/latex/xepersian-hm/kashida-xepersian-hm.def b/macros/xetex/latex/xepersian-hm/kashida-xepersian-hm.def
new file mode 100644
index 0000000000..ce3a9600dc
--- /dev/null
+++ b/macros/xetex/latex/xepersian-hm/kashida-xepersian-hm.def
@@ -0,0 +1,132 @@
+%%
+%% This is file `kashida-xepersian-hm.def'
+%%
+%% Copyright (c) Hossein Movahhedian 2020
+%%
+%% It may be distributed and/or modified under the LaTeX Project Public License,
+%% version 1.3c or higher (your choice). The latest version of
+%% this license is at: http://www.latex-project.org/lppl.txt
+%%
+%% Copyright notice: the following code is partly adapted from the code in
+%% 'kashida-xepersian.def' from xepersian package (v22.8).
+\ExplSyntaxOn
+\ProvidesExplFile {kashida-xepersian.def} {2018/01/04} {0.1} { Fixes~implementation~of~Kashida~in~xepersian~package }
+
+\int_const:Nn \c_xepersian_zwj_int {"200D} % zero-width joiner
+\int_const:Nn \c_xepersian_lrm_int {"200E} % left-right-mark
+\int_const:Nn \c_xepersian_two_int {2} % 2
+\int_const:Nn \c_xepersian_four_int {4} % 4
+\int_const:Nn \c_xepersian_ksh_int {"0640} % kashida
+\int_const:Nn \c_xepersian_d_int {10} % dual-joiner class
+\int_const:Nn \c_xepersian_l_int {11} % lam
+\int_const:Nn \c_xepersian_r_int {12} % right-joiner
+\int_const:Nn \c_xepersian_a_int {13} % alef
+\int_const:Nn \c_xepersian_h_int {14} % heh
+\int_const:Nn \c_xepersian_y_int {15} % yeh
+\int_const:Nn \c_xepersian_v_int {4096} % vowel or other combining mark (to be ignored)
+
+\bool_new:N \l_kashida_on_bool
+\bool_new:N \l_kashida_hm_fix_bool
+\bool_new:N \l_kashida_xb_fix_bool
+
+\tl_new:N \l_hskip_zero_tl
+\tl_new:N \l_hskip_default_tl
+
+\cs_new:Npn \xepersian_kashida #1
+ {
+ \bool_if:NT \l_kashida_on_bool
+ {
+ \c_xepersian_lrm_int\c_xepersian_zwj_int\tex_penalty:D 10000
+ \tex_leaders:D \tex_hrule:D height \XeTeXglyphbounds \c_xepersian_two_int
+ \int_use:N \XeTeXcharglyph \c_xepersian_ksh_int depth \XeTeXglyphbounds \c_xepersian_four_int
+ \int_use:N \XeTeXcharglyph \c_xepersian_ksh_int \skip_horizontal:n { #1 }
+ \c_xepersian_zwj_int
+ }
+ }
+
+\XeTeXinterchartokenstate = 1
+
+\clist_set:Nn \l_xepersian_a_clist { 0622,0623,0625,0627 } % ‏ا، إ، أ، آ‏
+\clist_map_inline:Nn \l_xepersian_a_clist
+ {
+ \XeTeXcharclass "#1 \c_xepersian_a_int
+ }
+
+\clist_set:Nn \l_xepersian_d_clist { 0626,0628,062A,062B,062C,062D,062E,0633,0634,0635,0636,0637,0638,0639,063A,0640,0641,0642,0643,0645,0646,0647,067E,0686,06A9,06AF } % ‏ئ,ب,ت,ث,ج,ح,خ,س,ش,ص,ض,ط,ظ,ع,غ,ـ,ف,ق,ك,م,ن,ه,پ,چ,ک,گ‏
+\clist_map_inline:Nn \l_xepersian_d_clist
+ {
+ \XeTeXcharclass "#1 \c_xepersian_d_int
+ }
+
+\clist_set:Nn \l_xepersian_l_clist { 0644 } % ‏ل‏
+\clist_map_inline:Nn \l_xepersian_l_clist
+ {
+ \XeTeXcharclass "#1 \c_xepersian_l_int
+ }
+
+\clist_set:Nn \l_xepersian_r_clist { 0624,0629,062F,0630,0631,0632,0648,0698 } % ‏ؤ,ة,د,ذ,ر,ز,و,ژ‏
+\clist_map_inline:Nn \l_xepersian_r_clist
+ {
+ \XeTeXcharclass "#1 \c_xepersian_r_int
+ }
+
+\clist_set:Nn \l_xepersian_v_clist { 064B,064C,064D,064E,064F,0650,0651,0652 } % ‏ً,ٌ,ٍ,َ,ُ,ِ,ّ,ْ‏
+\clist_map_inline:Nn \l_xepersian_v_clist
+ {
+ \XeTeXcharclass "#1 \c_xepersian_v_int
+ }
+
+\clist_set:Nn \l_xepersian_y_clist { 0649,064A,06CC }
+\clist_map_inline:Nn \l_xepersian_y_clist
+ {
+ \XeTeXcharclass "#1 \c_xepersian_y_int
+ }
+
+\XeTeXinterchartoks \c_xepersian_y_int \c_xepersian_y_int = {\bool_if:NTF \l_kashida_hm_fix_bool {\xepersian_kashida {\l_hskip_default_tl}} {\xepersian_kashida \l_hskip_zero_tl}}
+\XeTeXinterchartoks \c_xepersian_d_int \c_xepersian_y_int = {\bool_if:NTF \l_kashida_hm_fix_bool {\xepersian_kashida {\l_hskip_default_tl}} {\xepersian_kashida \l_hskip_zero_tl}}
+\XeTeXinterchartoks \c_xepersian_y_int \c_xepersian_d_int = {\xepersian_kashida \l_hskip_zero_tl}
+\XeTeXinterchartoks \c_xepersian_d_int \c_xepersian_d_int = {\xepersian_kashida \l_hskip_zero_tl}
+\XeTeXinterchartoks \c_xepersian_l_int \c_xepersian_d_int = {\xepersian_kashida \l_hskip_zero_tl}
+\XeTeXinterchartoks \c_xepersian_d_int \c_xepersian_l_int = {\xepersian_kashida \l_hskip_zero_tl}
+\XeTeXinterchartoks \c_xepersian_l_int \c_xepersian_l_int = {\xepersian_kashida \l_hskip_zero_tl}
+\XeTeXinterchartoks \c_xepersian_d_int \c_xepersian_r_int = {\xepersian_kashida \l_hskip_zero_tl}
+\XeTeXinterchartoks \c_xepersian_d_int \c_xepersian_a_int = {\xepersian_kashida \l_hskip_zero_tl}
+\XeTeXinterchartoks \c_xepersian_l_int \c_xepersian_r_int = {\xepersian_kashida \l_hskip_zero_tl}
+\XeTeXinterchartoks \c_xepersian_l_int \c_xepersian_a_int = {}
+
+\NewDocumentCommand \KashidaOn {} { \bool_set_true:N \l_kashida_on_bool }
+\NewDocumentCommand \KashidaOff {} { \bool_set_false:N \l_kashida_on_bool }
+
+\NewDocumentCommand \KashidaXBFixOn {} { \bool_set_true:N \l_kashida_xb_fix_bool }
+\NewDocumentCommand \KashidaXBFixOff {} { \bool_set_false:N \l_kashida_xb_fix_bool }
+
+\NewDocumentCommand \KashidaHMFixOn {} { \bool_set_true:N \l_kashida_hm_fix_bool }
+\NewDocumentCommand \KashidaHMFixOff {} { \bool_set_false:N \l_kashida_hm_fix_bool }
+
+\ExplSyntaxOff
+\makeatletter
+\newif\if@Kashida@on
+\newif\if@Kashida@XB@fix
+\makeatother
+\ExplSyntaxOn
+
+\KashidaHMFixOn
+
+\tl_set:Nn \l_hskip_zero_tl { 0 em plus 0.5 em }
+
+\bool_if:NTF \l_kashida_hm_fix_bool
+ {
+ \tl_if_empty:NT \l_hskip_default_tl { \tl_set:Nn \l_hskip_default_tl { 0.14 em plus 0.5 em } }
+ }
+ {
+ \tl_set:NV \l_hskip_default_tl \l_hskip_zero_tl
+ }
+
+\KashidaOn
+
+\ExplSyntaxOff
+\endinput
+
+%%
+%% END OF FILE
+%%