summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/xelatex/xepersian-hm/xepersian-hm.sty
blob: 2f16673d9dfc18f8f3a59f46d8c9ee0f8d70a9cd (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
%%
%% This is file `xepersian-hm.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xepersian-hm.dtx  (with options: `xepersian-hm-sty')
%% 
%% Copyright (C) 2020 Hossein Movahhedian
%% 
%% 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
%% 
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}[2020-03-06]
\@ifpackagelater{expl3}{2020-03-06}
  {}
  {%
    \PackageError{xepersian-hm}{Support package l3kernel too old}
      {%
        Please install an up to date version of l3kernel\MessageBreak
        using your TeX package manager or from CTAN.\MessageBreak
        \MessageBreak
        Loading xtemplate will abort!%
      }%
    \endinput
  }
\RequirePackage{l3keys2e}
\RequirePackage{graphicx}[2019-11-30]
\RequirePackage{zref-savepos}[2020-03-03]
\RequirePackage{xepersian}
\ExplSyntaxOn
\ProvidesExplPackage {xepersian-hm} {2020-05-07} {0.5d} { Fixes~issues~in~xepersian~package }

\int_const:Nn \c_xephm_ksh_int {"0640} % kashida
\int_const:Nn \c_xephm_lrm_int {"200E} % left-right-mark
\int_const:Nn \c_xephm_zwj_int {"200D} % zero-width joiner

\int_const:Nn \c_xephm_two_int {2} % 2
\int_const:Nn \c_xephm_four_int {4} % 4

\tl_const:Nn \c_xephm_skip_a_tl { 0 em plus 0.5 em }
\tl_const:Nn \c_xephm_skip_b_tl { 0.14 em plus 5.5 em }

\int_new:N \l_xephm_counter_int

\int_new:N \l_xephm_kashida_slot_int

\int_new:N \l_xephm_line_break_penalty_int

\int_new:N \l_xephm_min_penalty_int
\int_new:N \l_xephm_low_penalty_int
\int_new:N \l_xephm_med_penalty_int
\int_new:N \l_xephm_high_penalty_int
\int_new:N \l_xephm_max_penalty_int

\tl_new:N \l_xephm_line_break_tl

\tl_new:N \l_xephm_main_font_full_tl
\tl_new:N \l_xephm_main_font_name_tl

\tl_new:N \l_xephm_skip_default_tl

\tl_new:N \l_xephm_gap_filler_tl

\dim_new:N \l_xephm_diff_pos_dim

\bool_set_false:N \l_xephm_kashida_hm_fix_bool
\bool_set_false:N \l_xephm_linebreakpenalty_bool

\int_set:Nn \l_xephm_min_penalty_int { 0 }
\int_set:Nn \l_xephm_low_penalty_int { 8 }
\int_set:Nn \l_xephm_med_penalty_int { 15 }
\int_set:Nn \l_xephm_high_penalty_int { 25 }
\int_set:Nn \l_xephm_max_penalty_int { 10000 }

\tl_set:Nn \l_xephm_stretch_glyph_tl { glyph }
\tl_set:Nn \l_xephm_stretch_hrule_tl { hrule }

\tl_set:Nn \l_xephm_kayhan_tl       { kayhan }
\tl_set:Nn \l_xephm_khorramshahr_tl { khorramshahr }
\tl_set:Nn \l_xephm_kayhannavaar_tl { kayhannavaar }
\tl_set:Nn \l_xephm_kayhanpook_tl   { kayhanpook }
\tl_set:Nn \l_xephm_kayhansayeh_tl  { kayhansayeh }
\tl_set:Nn \l_xephm_khoramshahr_tl  { khoramshahr }
\tl_set:Nn \l_xephm_khorramshahr_tl { khorramshahr }
\tl_set:Nn \l_xephm_niloofar_tl     { niloofar }
\tl_set:Nn \l_xephm_paatch_tl       { paatch }
\tl_set:Nn \l_xephm_riyaz_tl        { riyaz }
\tl_set:Nn \l_xephm_roya_tl         { roya }
\tl_set:Nn \l_xephm_shafigh_tl      { shafigh }
\tl_set:Nn \l_xephm_shafighKurd_tl  { shafighKurd }
\tl_set:Nn \l_xephm_shafighUzbek_tl { shafighUzbek }
\tl_set:Nn \l_xephm_shiraz_tl       { shiraz }
\tl_set:Nn \l_xephm_sols_tl         { sols }
\tl_set:Nn \l_xephm_tabriz_tl       { tabriz }
\tl_set:Nn \l_xephm_titr_tl         { titr }
\tl_set:Nn \l_xephm_titre_tl        { titre }
\tl_set:Nn \l_xephm_traffic_tl      { traffic }
\tl_set:Nn \l_xephm_vahid_tl        { vahid }
\tl_set:Nn \l_xephm_vosta_tl        { vosta }
\tl_set:Nn \l_xephm_yaghut_tl       { yaghut }
\tl_set:Nn \l_xephm_yagut_tl        { yagut }
\tl_set:Nn \l_xephm_yas_tl          { yas }
\tl_set:Nn \l_xephm_yekan_tl        { yekan }
\tl_set:Nn \l_xephm_yermook_tl      { yermook }
\tl_set:Nn \l_xephm_zar_tl          { zar }
\tl_set:Nn \l_xephm_ziba_tl         { ziba }
\tl_set:Nn \l_xephm_default_tl      { default }
\tl_set:Nn \l_xephm_noskip_tl       { noskip }

\msg_new:nnn { xepersian-hm } { kashida-character-is-not-available-in-the-main-font }
  {
    Sorry,~ kashida~ character~ is~ not~ available~ in~ the~ main~ font~!
  }

\msg_new:nnn { xepersian-hm } { value-not-available-for-kashida-option }
  {
    Sorry,~ value~ `#1'~ is~ not~ available~ for~ `Kashida'~ option~ yet~!
  }

\msg_new:nnn { xepersian-hm } { specify-value-for-kashida-option }
  {
    Sorry,~ you~ must~ specify~ a~ value~ for~ `Kashida'~ option~ yet~!
  }

\keys_define:nn { xepersian-hm }
  {
    Kashida .code:n =
      {
        \tl_set:Nn \l_tmpa_tl { #1 }
        \tl_case:NnTF \l_tmpa_tl
          {
            \l_xephm_stretch_glyph_tl
              {
                \tl_set:Nn \l_xephm_gap_filler_tl { \l_xephm_stretch_glyph_tl }
                \AtBeginDocument
                  {
                    \tl_set:Nx \l_xephm_main_font_full_tl { \tex_fontname:D \tex_the:D \tex_font:D }
                    \tl_set:Nx \l_xephm_main_font_name_tl { \l_xephm_main_font_full_tl }
                    \regex_replace_once:nnN { ^"([^/]+)/.* } { \1 } \l_xephm_main_font_name_tl
                    \int_set:Nn \l_xephm_kashida_slot_int { \xetex_charglyph:D \c_xephm_ksh_int }
                    \int_compare:nT { \l_xephm_kashida_slot_int = \c_zero_int }
                      {
                        \msg_error:nn { xepersian-hm } { kashida-character-is-not-available-in-the-main-font }
                      }
                  }
              }
            \l_xephm_stretch_hrule_tl
              {
                \tl_set:Nn \l_xephm_gap_filler_tl { \l_xephm_stretch_hrule_tl }
              }
          } { } { \tl_set:Nx \l_xephm_gap_filler_tl { #1 } }
        \tl_if_empty:NT \l_xephm_gap_filler_tl { \msg_error:nn { xepersian-hm } { specify-value-for-kashida-option } }
        \bool_set_true:N \l_xephm_kashida_hm_fix_bool
        \tex_input:D { kashida-xepersian-hm.def }
      } ,

    linebreakpenalty .code:n =
      {
        \int_set:Nn \l_tmpa_int { #1 }
        \int_case:nnTF \l_tmpa_int
          {
            \l_xephm_min_penalty_int { \int_set:Nn \l_xephm_line_break_penalty_int { \l_xephm_min_penalty_int } }
            \l_xephm_low_penalty_int { \int_set:Nn \l_xephm_line_break_penalty_int { \l_xephm_low_penalty_int } }
            \l_xephm_med_penalty_int { \int_set:Nn \l_xephm_line_break_penalty_int { \l_xephm_med_penalty_int } }
            \l_xephm_high_penalty_int { \int_set:Nn \l_xephm_line_break_penalty_int { \l_xephm_high_penalty_int } }
            \l_xephm_max_penalty_int { \int_set:Nn \l_xephm_line_break_penalty_int { \l_xephm_max_penalty_int } }
          } { } { \int_set:Nn \l_xephm_line_break_penalty_int { #1 } }
        \bool_set_true:N \l_xephm_linebreakpenalty_bool
      } ,

    kashidastretch .code:n =
      {
        \tl_set:Nn \l_tmpb_tl { #1 }
        \tl_case:NnTF \l_tmpb_tl
          {
             \l_xephm_kayhan_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.14  em plus 0.5 em } }
             \l_xephm_khorramshahr_tl { \tl_set:Nn \l_xephm_skip_default_tl { 0.131 em plus 0.5 em } }
             \l_xephm_kayhannavaar_tl { \tl_set:Nn \l_xephm_skip_default_tl { 0.129 em plus 0.5 em } }
             \l_xephm_kayhanpook_tl   { \tl_set:Nn \l_xephm_skip_default_tl { 0.133 em plus 0.5 em } }
             \l_xephm_kayhansayeh_tl  { \tl_set:Nn \l_xephm_skip_default_tl { 0.135 em plus 0.5 em } }
             \l_xephm_khoramshahr_tl  { \tl_set:Nn \l_xephm_skip_default_tl { 0.128 em plus 0.5 em } }
             \l_xephm_khorramshahr_tl { \tl_set:Nn \l_xephm_skip_default_tl { 0.13  em plus 0.5 em } }
             \l_xephm_niloofar_tl     { \tl_set:Nn \l_xephm_skip_default_tl { 0.132 em plus 0.5 em } }
             \l_xephm_paatch_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.127 em plus 0.5 em } }
             \l_xephm_riyaz_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.125 em plus 0.5 em } }
             \l_xephm_roya_tl         { \tl_set:Nn \l_xephm_skip_default_tl { 0.142 em plus 0.5 em } }
             \l_xephm_shafigh_tl      { \tl_set:Nn \l_xephm_skip_default_tl { 0.143 em plus 0.5 em } }
             \l_xephm_shafighKurd_tl  { \tl_set:Nn \l_xephm_skip_default_tl { 0.126 em plus 0.5 em } }
             \l_xephm_shafighUzbek_tl { \tl_set:Nn \l_xephm_skip_default_tl { 0.123 em plus 0.5 em } }
             \l_xephm_shiraz_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.122 em plus 0.5 em } }
             \l_xephm_sols_tl         { \tl_set:Nn \l_xephm_skip_default_tl { 0.124 em plus 0.5 em } }
             \l_xephm_tabriz_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.119 em plus 0.5 em } }
             \l_xephm_titr_tl         { \tl_set:Nn \l_xephm_skip_default_tl { 0.12  em plus 0.5 em } }
             \l_xephm_titre_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.121 em plus 0.5 em } }
             \l_xephm_traffic_tl      { \tl_set:Nn \l_xephm_skip_default_tl { 0.124 em plus 0.5 em } }
             \l_xephm_vahid_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.134 em plus 0.5 em } }
             \l_xephm_vosta_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.136 em plus 0.5 em } }
             \l_xephm_yaghut_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.138 em plus 0.5 em } }
             \l_xephm_yagut_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.137 em plus 0.5 em } }
             \l_xephm_yas_tl          { \tl_set:Nn \l_xephm_skip_default_tl { 0.126 em plus 0.5 em } }
             \l_xephm_yekan_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.141 em plus 0.5 em } }
             \l_xephm_yermook_tl      { \tl_set:Nn \l_xephm_skip_default_tl { 0.139 em plus 0.5 em } }
             \l_xephm_zar_tl          { \tl_set:Nn \l_xephm_skip_default_tl { 0.116 em plus 0.5 em } }
             \l_xephm_ziba_tl         { \tl_set:Nn \l_xephm_skip_default_tl { 0.119 em plus 0.5 em } }
             \l_xephm_default_tl      { \tl_set:Nn \l_xephm_skip_default_tl { 0.14  em plus 0.5 em } }
             \l_xephm_noskip_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0     em plus 0.5 em } }
          } { } { \tl_set:Nn \l_xephm_skip_default_tl { #1 } }
      } ,
    kashidastretch .default:n = \tl_set:Nn \l_xephm_skip_default_tl { 0 em plus 0.5 em } ,
  }

\ProcessKeysOptions { xepersian-hm }

\ExplSyntaxOff
 \endinput
%% 
%%
%% End of file `xepersian-hm.sty'.