summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/mk/mk-arabic.tex
blob: a9f9e52d96aff6d727517e4f9c4011df2ceadd32 (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
319
320
321
322
323
324
% language=uk

\startcomponent mk-arabic

\environment mk-environment

\disablemode[dynamic-arabic] % to be checked, we loose colors

\definefontfeature
  [arab-none]
  [mode=node,language=dflt,script=arab]

\definefontfeature
  [arab-compose]
  [mode=node,language=dflt,script=arab,
   ccmp=yes]

\definefontfeature
  [arab-replace]
  [mode=node,language=dflt,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes]

\definefontfeature
  [arab-mark]
  [mode=node,language=dflt,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   mark=yes]

\definefontfeature
  [arab-mkmk]
  [mode=node,language=dflt,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   mark=yes,mkmk=yes]

\definefontfeature
  [arab-kern]
  [mode=node,language=dflt,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   mark=yes,mkmk=yes,
   kern=yes]

\definefontfeature[arab-context]
  [mode=node,language=dflt,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   mark=yes,mkmk=yes,
   kern=yes,
   calt=yes]

\definefontfeature
  [arab-ligs]
  [mode=node,language=dflt,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   liga=yes,dlig=yes,rlig=yes,clig=yes,
   mkmk=yes,mark=yes,
   kern=yes]

\definefontfeature
  [arab-curs]
  [mode=node,language=dflt,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   liga=yes,dlig=yes,rlig=yes,clig=yes,
   mark=yes,mkmk=yes,
   kern=yes,curs=yes]

\definefontfeature
  [arab-urdu]
  [mode=node,language=urd,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   liga=yes,dlig=yes,rlig=yes,clig=yes,
   mark=yes,mkmk=yes,
   kern=yes,curs=yes]

\definefontfeature
  [arab-default]
  [mode=node,language=dflt,script=arab,
   ccmp=yes,
   init=yes,medi=yes,fina=yes,isol=yes,
   liga=yes,dlig=yes,rlig=yes,clig=yes,
   mark=yes,mkmk=yes,kern=yes,curs=yes]

% \font \ArabNone    = arabtype*arab-none    at 48pt
% \font \ArabCompose = arabtype*arab-compose at 48pt
% \font \ArabReplace = arabtype*arab-replace at 48pt
% \font \ArabMark    = arabtype*arab-mark    at 48pt
% \font \ArabMkmk    = arabtype*arab-mkmk    at 48pt
% \font \ArabKern    = arabtype*arab-kern    at 48pt
% \font \ArabContext = arabtype*arab-context at 48pt
% \font \ArabLigs    = arabtype*arab-ligs    at 48pt
% \font \ArabCurs    = arabtype*arab-curs    at 48pt
% \font \ArabUrdu    = arabtype*arab-urdu    at 48pt

% \startbuffer[word]
%     \char1604\char1616\char1604\char1617\char1648\char1607\char1616 % لِلّٰهِ
% \stopbuffer

\startbuffer[split-word]
    \def\somechar #1{ \char#1\relax}%
    \def\somevowel#1{ \char#1\relax}%
    \dontleavehmode\ignorespaces\getbuffer[word]\removeunwantedspaces
\stopbuffer

\startbuffer[normal-word]
    \def\somechar #1{\char#1\relax}%
    \def\somevowel#1{\char#1\relax}%
    \ignorespaces\getbuffer[word]\removeunwantedspaces
\stopbuffer

\startbuffer[word]
    \somechar {1604}%
    \somevowel{1616}%
    \somechar {1604}%
    \somevowel{1617}%
    \somevowel{1648}%
    \somechar {1607}%
    \somevowel{1616}%
    % لِلّٰهِ
\stopbuffer

\startbuffer[word]
    \somechar {"644}%
    \somevowel{"650}%
    \somechar {"644}%
    \somevowel{"651}%
    \somevowel{"670}%
    \somechar {"647}%
    \somevowel{"650}%
    % لِلّٰهِ
\stopbuffer

\startbuffer[paragraph]
اَلْحَمْدُ لِلّٰهِ حَمْدَ مُعْتَرِفٍ بِحَمْدِهٖ، مُغْتَرِفٌ مِنْ بِحَارِ مَجْدِهٖ، بِلِسَانِ
الثَّنَاۤءِ شَاكِرًا، وَلِحُسْنِ اٰلاۤئِهٖ نَاشِرًا؛ اَلَّذِيْ خَلَقَ الْمَوْتَ وَالْحَيٰوةَ، وَالْخَيْرَ
وَالشَّرَّ، وَالنَّفْعَ وَالضَّرَّ، وَالسُّكُوْنَ وَالْحَرَكَةَ، وَالْأَرْوَاحَ
وَالْأَجْسَامَ، وَالذِّكْرَ وَالنِّسْيَانَ.
\stopbuffer

\def\ArabSampleFont{arabtype}

\def\ShowArabSample#1%
  {\begingroup
   \blank
   \enabletrackers[otf.analyzing]
   \doifmodeelse{dynamic-arabic}{
        \font\ArabFont = \ArabSampleFont\space at 48pt
   }{
        \font\ArabFont = \ArabSampleFont*#1 at 48pt
   }
   \font\ArabFontX = \ArabSampleFont\space at 24pt
   \startlinecorrection
   \bTABLE[framecolor=red,rulethickness=1pt,offset=1ex]
     \bTR
       \bTD[width=.8\textwidth] % [ny=2]
         \tttf\fontfeatureslist[#1][, ]%
       \eTD
       \bTD[width=.2\textwidth,align={lohi,middle},offset=0pt]%
         \ArabFont\doifmode{dynamic-arabic}{\setfontfeature{#1}}\textdir TRT\relax
         \getbuffer[normal-word]%
       \eTD
     \eTR
%      \bTR
%        \bTD[width=9em,align={lohi,middle},offset=0pt]%
%          \ArabFontX\textdir TRT\relax
%          \getbuffer[split-word]%
%        \eTD
%      \eTR
   \eTABLE
   \stoplinecorrection
   \blank
   \doifmodeelse{dynamic-arabic}{
        \font\ArabFont = \ArabSampleFont\space at 24pt
        \setfontfeature{#1}%
   }{
        \font\ArabFont = \ArabSampleFont*#1 at 24pt
   }
   \ArabFont
   \pardir TRT\relax\textdir TRT\relax\getbuffer[paragraph]\endgraf
   \disabletrackers[otf.analyzing]
   \pardir TRT\relax\textdir TRT\relax\getbuffer[paragraph]\endgraf
   \endgroup}

\chapter{Arabic}

Let's start with admitting that I don't speak or read Arabic, and the sample
texts used here are part of what we use in the Oriental \TEX\ project for
exploring advanced Arabic typesetting. This chapter will not discuss arab
typesetting in much detail, but should be seen as complementing the \quote
{Onthology on Arabic Typesetting} written by Idris. Here I will only show what
the consequences are of applying features. Because we see glyphs but often still
deal with characters when analyzing what to do, we will use these terms mixed.

The font that we use here is the \quote {arabtype} font by MicroSoft. This font
covers Latin scripts and Arabic and has a rich set of features. It's also a rather
big font, so it is a nice torture test for \LUATEX.

First we show what \MKIV\ does with a sequence of characters when no features
are enabled by the user. We have turn on color tracing. This gives us some
feedback about the how the analyze worked out. Analyzing for Arabic boils down
to marking the initial, mid, final and isolated forms. We don't need to
explicitly enable analyzing, it's on by default. The \type {mode} flag is set
to \type {node} because we cannot use \TEX's default mechanism. When \LUATEX\
and \MKIV\ are beyond beta stage, we will use that mode by default.

\ShowArabSample {arab-none}

Once these forms are identified, the \type {init}, \type {medi}, \type {fina}
and \type {isol} features can be applied since they need this information. As
you can see, different shapes show up. The vowels (marks in \OPENTYPE\ speak)
are not affected. It may not be entirely clear here, but these vowels don't have
width.

\ShowArabSample {arab-compose}

We start with some preparations with regards to combinations of marks. This
is really needed in order to get the right output.

\ShowArabSample {arab-replace}

The order in which features are applied is dictated by the font and users don't
need to bother about it. In the next example we enable the \type {mark} and
\type {mkmk} features. As with other positioning related features, these are
normally applied late in the feature chain.

\ShowArabSample {arab-mark}

The \type {mark} feature positions marks (vowels) relative to characters, also
known as mark to base. The \type {mkmk} feature positions marks to basemarks.

\ShowArabSample {arab-mkmk}

Kerning depends on the font. Some fonts don't need kerning, others may need
extensive relative positioning of characters (by now glyphs).

\ShowArabSample {arab-kern}

So far we only had rather straightforward replacements. More sophisticated
replacements are those driven by the context. In principle all replacements
can be context driven, but the \type {calt} and \type {clig} features are
normally dedicated to the real complex ones that take preceding and following
characters into account.

\ShowArabSample {arab-context}

Ligatures are often used to beautify Arabic typeset documents. Here we enable the
whole lot.

\ShowArabSample {arab-ligs}

Kerning deals with horizontal displacements, but \type {curs} (cursive) goes one
step further. As with marks, positioning is based on anchor points and resolving
them involves a bit of trickery because one needs to take into account that
characters may have vowels attached to them.

\ShowArabSample {arab-curs}

One script can serve multiple languages so let's see what happens when we switch to
Urdu.

\ShowArabSample {arab-urdu}

In practice one will enable most of the features. In \MKIV\ one can define feature
sets as follows:

\starttyping
\definefontfeature
  [arab-default]
  [mode=node,language=dflt,script=arab,
   init=yes,medi=yes,fina=yes,isol=yes,
   liga=yes,dlig=yes,rlig=yes,clig=yes,
   mark=yes,mkmk=yes,kern=yes,curs=yes]
\stoptyping

Applying these features to fonts can be done in several ways, with as most basic
one:

\starttyping
\font\ArabFont=arabtype*arab-default at 18pt
\stoptyping

Normally one will do something like

\starttyping
\definefont[ArabFont][arabtype*arab-default at 18pt]
\stoptyping

or use typescripts to set up ap proper font collection, in which case we end
up with definitions that look like:

\starttyping
\definefontsynonym[ArabType][name:arabtype][features=arab-default]
\definefontsynonym[Serif][ArabType]
\stoptyping

More information about typescripts can be found in manuals and on the
\CONTEXT\ wiki.

We end this chapter with showing two arabic fonts so that you can get a taste
if the differences: arabtype by MicroSoft and Palatino which is designed by
Herman Zapf for Linotype.

\def\ArabSampleFont{arabtype} \ShowArabSample {arab-default}

\def\ArabSampleFont{name:palatinoltarabic} \ShowArabSample {arab-default}

These fonts are quite different in designsize:

\def\Test{test} %  (\the\dimexpr1em\relax)}

\starttabulate[|r|c|c|c|]
\NC          \NC \bf arabtype                        \NC \bf palatino                                     \NC \NR
\NC \bf 10pt \NC \definedfont[arabtype at 10pt]\Test \NC \definedfont[name:palatinoltarabic at 10pt]\Test \NC \NR
\NC \bf 12pt \NC \definedfont[arabtype at 12pt]\Test \NC \definedfont[name:palatinoltarabic at 12pt]\Test \NC \NR
\NC \bf 18pt \NC \definedfont[arabtype at 18pt]\Test \NC \definedfont[name:palatinoltarabic at 18pt]\Test \NC \NR
\NC \bf 24pt \NC \definedfont[arabtype at 24pt]\Test \NC \definedfont[name:palatinoltarabic at 24pt]\Test \NC \NR
\stoptabulate

\stopcomponent