summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/xelatex/xepersian-hm/xepersian-hm.sty
blob: 0911eb29982c943b3e04da892e99927152b19800 (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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
%%
%% 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-08-05} {1.0d} { Fixes~issues~in~xepersian~package }

\box_new:N \l_xephm_ksh_box

\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_font_full_tl
\tl_new:N \l_xephm_font_name_tl

\tl_new:N \l_xephm_skip_default_tl

\tl_new:N \l_xephm_active_ligs_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_ligature_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_leaders_glyph_tl { leaders+glyph }
\tl_set:Nn \l_xephm_stretch_leaders_hrule_tl { leaders+hrule }
\tl_set:Nn \l_xephm_stretch_off_tl { Off }
\tl_set:Nn \l_xephm_stretch_on_tl { On }

\tl_set:Nn \l_xephm_fnt_kayhan_tl       { kayhan }
\tl_set:Nn \l_xephm_fnt_kayhannavaar_tl { kayhannavaar }
\tl_set:Nn \l_xephm_fnt_kayhanpook_tl   { kayhanpook }
\tl_set:Nn \l_xephm_fnt_kayhansayeh_tl  { kayhansayeh }
\tl_set:Nn \l_xephm_fnt_khoramshahr_tl  { khoramshahr }
\tl_set:Nn \l_xephm_fnt_khorramshahr_tl { khorramshahr }
\tl_set:Nn \l_xephm_fnt_niloofar_tl     { niloofar }
\tl_set:Nn \l_xephm_fnt_paatch_tl       { paatch }
\tl_set:Nn \l_xephm_fnt_riyaz_tl        { riyaz }
\tl_set:Nn \l_xephm_fnt_roya_tl         { roya }
\tl_set:Nn \l_xephm_fnt_shafigh_tl      { shafigh }
\tl_set:Nn \l_xephm_fnt_shafighKurd_tl  { shafighKurd }
\tl_set:Nn \l_xephm_fnt_shafighUzbek_tl { shafighUzbek }
\tl_set:Nn \l_xephm_fnt_shiraz_tl       { shiraz }
\tl_set:Nn \l_xephm_fnt_sols_tl         { sols }
\tl_set:Nn \l_xephm_fnt_tabriz_tl       { tabriz }
\tl_set:Nn \l_xephm_fnt_titr_tl         { titr }
\tl_set:Nn \l_xephm_fnt_titre_tl        { titre }
\tl_set:Nn \l_xephm_fnt_traffic_tl      { traffic }
\tl_set:Nn \l_xephm_fnt_vahid_tl        { vahid }
\tl_set:Nn \l_xephm_fnt_vosta_tl        { vosta }
\tl_set:Nn \l_xephm_fnt_yaghut_tl       { yaghut }
\tl_set:Nn \l_xephm_fnt_yagut_tl        { yagut }
\tl_set:Nn \l_xephm_fnt_yas_tl          { yas }
\tl_set:Nn \l_xephm_fnt_yekan_tl        { yekan }
\tl_set:Nn \l_xephm_fnt_yermook_tl      { yermook }
\tl_set:Nn \l_xephm_fnt_zar_tl          { zar }
\tl_set:Nn \l_xephm_fnt_ziba_tl         { ziba }
\tl_set:Nn \l_xephm_fnt_default_tl      { default }
\tl_set:Nn \l_xephm_fnt_noskip_tl       { noskip }

\tl_set:Nn \l_xephm_lig_aalt_tl    { aalt } % Access All Alternatives
\tl_set:Nn \l_xephm_lig_ccmp_tl    { ccmp } % Glyph Composition/Decomposition
\tl_set:Nn \l_xephm_lig_dlig_tl    { dlig } % Discretionary Ligatures
\tl_set:Nn \l_xephm_lig_fina_tl    { fina } % Final (Terminal) Forms
\tl_set:Nn \l_xephm_lig_init_tl    { init } % Initial Forms
\tl_set:Nn \l_xephm_lig_locl_tl    { locl } % Localized Forms
\tl_set:Nn \l_xephm_lig_medi_tl    { medi } % Medial Forms
\tl_set:Nn \l_xephm_lig_rlig_tl    { rlig } % Required Ligatures
\tl_set:Nn \l_xephm_lig_default_tl { default }

\clist_set:Nn \l_xephm_lig_aalt_clist    { } % Access All Alternatives
\clist_set:Nn \l_xephm_lig_ccmp_clist    { } % Glyph Composition/Decomposition
\clist_set:Nn \l_xephm_lig_dlig_clist    { FDF2 = الله , FDF3 = اکبر , FDFB = جلجلاله } % Discretionary Ligatures
\clist_set:Nn \l_xephm_lig_fina_clist    { } % Final (Terminal) Forms
\clist_set:Nn \l_xephm_lig_init_clist    { } % Initial Forms
\clist_set:Nn \l_xephm_lig_locl_clist    { } % Localized Forms
\clist_set:Nn \l_xephm_lig_medi_clist    { } % Medial Forms
\clist_set:Nn \l_xephm_lig_rlig_clist    { } % Required Ligatures
\clist_set:Nn \l_xephm_lig_default_clist { }

\clist_set:Nn \l_xephm_lig_names_clist
  {
    \l_xephm_lig_aalt_tl , { \l_xephm_lig_aalt_clist } ,
    \l_xephm_lig_ccmp_tl , { \l_xephm_lig_ccmp_clist } ,
    \l_xephm_lig_dlig_tl , { \l_xephm_lig_dlig_clist } ,
    \l_xephm_lig_fina_tl , { \l_xephm_lig_fina_clist } ,
    \l_xephm_lig_init_tl , { \l_xephm_lig_init_clist } ,
    \l_xephm_lig_locl_tl , { \l_xephm_lig_locl_clist } ,
    \l_xephm_lig_medi_tl , { \l_xephm_lig_medi_clist } ,
    \l_xephm_lig_rlig_tl , { \l_xephm_lig_rlig_clist } ,
  }

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

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

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

\msg_new:nnn { xepersian-hm } { warning-experimental-feature }
  {
    Please~ note~ that~ the~ feature~ `#1'~ is~ still~ experimental~
    and~ is~ not~ regarded~ as~ stable.
  }

\msg_new:nnn { xepersian-hm } { hm-series-font-not-found }
  {
    Either~ the~ font~`#1'~ is~ not~ installed~ on~ your~ system~ or~ does~ not~
    belong~ to~ HM~Series~fonts.~
    Please~ note~ that~ the~ option~ `Kashida=leaders+glyph'~ is~ currently~ only~
    supported~ by~ HM~Series~fonts.~
    If~ you~ know~ of~ any~ other~ font~ that~ supports~ this~ option,~ please~
    let~ me~ know~ to~ add~ it~ to~ the~ list~ of~ corresponding~ fonts.~
  }

\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
              {
                \msg_warning:nnn { xepersian-hm } { warning-experimental-feature } { Kashida=glyph }
                \tl_set:Nx \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 { \XeTeXcharglyph \c_xephm_ksh_int }
                    \int_compare:nT { \l_xephm_kashida_slot_int = \c_zero_int }
                      {
                        \msg_error:nnx { xepersian-hm } { error-kashida-character-is-not-available-in-the-main-font } { \l_xephm_main_font_name_tl }
                      }
                  }
                \bool_set_true:N \l_xephm_kashida_hm_fix_bool
              }
            \l_xephm_stretch_leaders_glyph_tl
              {
                \tl_set:Nx \l_xephm_gap_filler_tl { \l_xephm_stretch_leaders_glyph_tl }
                \bool_set_true:N \l_xephm_kashida_hm_fix_bool
              }
            \l_xephm_stretch_leaders_hrule_tl
              {
                \tl_set:Nx \l_xephm_gap_filler_tl { \l_xephm_stretch_leaders_hrule_tl }
                \bool_set_true:N \l_xephm_kashida_hm_fix_bool
              }
            \l_xephm_stretch_off_tl
              {
                \tl_set:Nx \l_xephm_gap_filler_tl { \l_xephm_stretch_off_tl }
                \bool_set_false:N \l_xephm_kashida_hm_fix_bool
              }
            \l_xephm_stretch_on_tl
              {
                \tl_set:Nx \l_xephm_gap_filler_tl { \l_xephm_stretch_leaders_glyph_tl }
                \bool_set_true:N \l_xephm_kashida_hm_fix_bool
              }
          } { } { \tl_set:Nx \l_xephm_gap_filler_tl { #1 } }
        \tl_if_empty:NT \l_xephm_gap_filler_tl { \msg_error:nn { xepersian-hm } { error-specify-value-for-kashida-option } }
      } ,

    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_tmpa_tl { #1 }
        \tl_case:NnTF \l_tmpa_tl
          {
             \l_xephm_fnt_kayhan_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.14  em plus 0.5 em } }
             \l_xephm_fnt_kayhannavaar_tl { \tl_set:Nn \l_xephm_skip_default_tl { 0.129 em plus 0.5 em } }
             \l_xephm_fnt_kayhanpook_tl   { \tl_set:Nn \l_xephm_skip_default_tl { 0.133 em plus 0.5 em } }
             \l_xephm_fnt_kayhansayeh_tl  { \tl_set:Nn \l_xephm_skip_default_tl { 0.135 em plus 0.5 em } }
             \l_xephm_fnt_khoramshahr_tl  { \tl_set:Nn \l_xephm_skip_default_tl { 0.128 em plus 0.5 em } }
             \l_xephm_fnt_khorramshahr_tl { \tl_set:Nn \l_xephm_skip_default_tl { 0.13  em plus 0.5 em } }
             \l_xephm_fnt_niloofar_tl     { \tl_set:Nn \l_xephm_skip_default_tl { 0.132 em plus 0.5 em } }
             \l_xephm_fnt_paatch_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.127 em plus 0.5 em } }
             \l_xephm_fnt_riyaz_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.125 em plus 0.5 em } }
             \l_xephm_fnt_roya_tl         { \tl_set:Nn \l_xephm_skip_default_tl { 0.142 em plus 0.5 em } }
             \l_xephm_fnt_shafigh_tl      { \tl_set:Nn \l_xephm_skip_default_tl { 0.143 em plus 0.5 em } }
             \l_xephm_fnt_shafighKurd_tl  { \tl_set:Nn \l_xephm_skip_default_tl { 0.126 em plus 0.5 em } }
             \l_xephm_fnt_shafighUzbek_tl { \tl_set:Nn \l_xephm_skip_default_tl { 0.123 em plus 0.5 em } }
             \l_xephm_fnt_shiraz_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.122 em plus 0.5 em } }
             \l_xephm_fnt_sols_tl         { \tl_set:Nn \l_xephm_skip_default_tl { 0.124 em plus 0.5 em } }
             \l_xephm_fnt_tabriz_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.119 em plus 0.5 em } }
             \l_xephm_fnt_titr_tl         { \tl_set:Nn \l_xephm_skip_default_tl { 0.12  em plus 0.5 em } }
             \l_xephm_fnt_titre_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.121 em plus 0.5 em } }
             \l_xephm_fnt_traffic_tl      { \tl_set:Nn \l_xephm_skip_default_tl { 0.124 em plus 0.5 em } }
             \l_xephm_fnt_vahid_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.134 em plus 0.5 em } }
             \l_xephm_fnt_vosta_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.136 em plus 0.5 em } }
             \l_xephm_fnt_yaghut_tl       { \tl_set:Nn \l_xephm_skip_default_tl { 0.138 em plus 0.5 em } }
             \l_xephm_fnt_yagut_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.137 em plus 0.5 em } }
             \l_xephm_fnt_yas_tl          { \tl_set:Nn \l_xephm_skip_default_tl { 0.126 em plus 0.5 em } }
             \l_xephm_fnt_yekan_tl        { \tl_set:Nn \l_xephm_skip_default_tl { 0.141 em plus 0.5 em } }
             \l_xephm_fnt_yermook_tl      { \tl_set:Nn \l_xephm_skip_default_tl { 0.139 em plus 0.5 em } }
             \l_xephm_fnt_zar_tl          { \tl_set:Nn \l_xephm_skip_default_tl { 0.116 em plus 0.5 em } }
             \l_xephm_fnt_ziba_tl         { \tl_set:Nn \l_xephm_skip_default_tl { 0.119 em plus 0.5 em } }
             \l_xephm_fnt_default_tl      { \tl_set:Nn \l_xephm_skip_default_tl { 0.14  em plus 0.5 em } }
             \l_xephm_fnt_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 } ,

    ligatures .code:n =
      {
        \tl_set:Nn \l_tmpa_tl { #1 }
        \tl_case:NnTF \l_tmpa_tl
          {
            \l_xephm_lig_aalt_tl    { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_aalt_tl } }
            \l_xephm_lig_ccmp_tl    { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_ccmp_tl } }
            \l_xephm_lig_dlig_tl    { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_dlig_tl } }
            \l_xephm_lig_fina_tl    { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_fina_tl } }
            \l_xephm_lig_init_tl    { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_init_tl } }
            \l_xephm_lig_locl_tl    { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_locl_tl } }
            \l_xephm_lig_medi_tl    { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_medi_tl } }
            \l_xephm_lig_rlig_tl    { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_rlig_tl } }
            \l_xephm_lig_default_tl { \tl_set:Nx \l_xephm_active_ligs_tl { \l_xephm_lig_default_tl } }
          } { } { \tl_set:Nn \l_xephm_active_ligs_tl { #1 } }
        \bool_set_true:N \l_xephm_ligature_bool
      } ,
    ligatures .default:n = \tl_set:Nn \l_xephm_active_ligs_tl { \l_xephm_lig_default_tl } ,
  }

\ProcessKeysOptions { xepersian-hm }

\bool_if:NT \l_xephm_kashida_hm_fix_bool
  {
    \tex_input:D { kashida-xepersian-hm.def }
  }

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