mk-arabic.tex /size: 10 Kb    last modification: 2023-12-21 09:43
1% language=us
2
3\startcomponent mk-arabic
4
5\environment mk-environment
6
7\disablemode[dynamic-arabic] % to be checked, we loose colors
8
9\definefontfeature
10  [arab-none]
11  [mode=node,language=dflt,script=arab]
12
13\definefontfeature
14  [arab-compose]
15  [mode=node,language=dflt,script=arab,
16   ccmp=yes]
17
18\definefontfeature
19  [arab-replace]
20  [mode=node,language=dflt,script=arab,
21   ccmp=yes,
22   init=yes,medi=yes,fina=yes,isol=yes]
23
24\definefontfeature
25  [arab-mark]
26  [mode=node,language=dflt,script=arab,
27   ccmp=yes,
28   init=yes,medi=yes,fina=yes,isol=yes,
29   mark=yes]
30
31\definefontfeature
32  [arab-mkmk]
33  [mode=node,language=dflt,script=arab,
34   ccmp=yes,
35   init=yes,medi=yes,fina=yes,isol=yes,
36   mark=yes,mkmk=yes]
37
38\definefontfeature
39  [arab-kern]
40  [mode=node,language=dflt,script=arab,
41   ccmp=yes,
42   init=yes,medi=yes,fina=yes,isol=yes,
43   mark=yes,mkmk=yes,
44   kern=yes]
45
46\definefontfeature[arab-context]
47  [mode=node,language=dflt,script=arab,
48   ccmp=yes,
49   init=yes,medi=yes,fina=yes,isol=yes,
50   mark=yes,mkmk=yes,
51   kern=yes,
52   calt=yes]
53
54\definefontfeature
55  [arab-ligs]
56  [mode=node,language=dflt,script=arab,
57   ccmp=yes,
58   init=yes,medi=yes,fina=yes,isol=yes,
59   liga=yes,dlig=yes,rlig=yes,clig=yes,
60   mkmk=yes,mark=yes,
61   kern=yes]
62
63\definefontfeature
64  [arab-curs]
65  [mode=node,language=dflt,script=arab,
66   ccmp=yes,
67   init=yes,medi=yes,fina=yes,isol=yes,
68   liga=yes,dlig=yes,rlig=yes,clig=yes,
69   mark=yes,mkmk=yes,
70   kern=yes,curs=yes]
71
72\definefontfeature
73  [arab-urdu]
74  [mode=node,language=urd,script=arab,
75   ccmp=yes,
76   init=yes,medi=yes,fina=yes,isol=yes,
77   liga=yes,dlig=yes,rlig=yes,clig=yes,
78   mark=yes,mkmk=yes,
79   kern=yes,curs=yes]
80
81\definefontfeature
82  [arab-default]
83  [mode=node,language=dflt,script=arab,
84   ccmp=yes,
85   init=yes,medi=yes,fina=yes,isol=yes,
86   liga=yes,dlig=yes,rlig=yes,clig=yes,
87   mark=yes,mkmk=yes,kern=yes,curs=yes]
88
89% \font \ArabNone    = arabtype*arab-none    at 48pt
90% \font \ArabCompose = arabtype*arab-compose at 48pt
91% \font \ArabReplace = arabtype*arab-replace at 48pt
92% \font \ArabMark    = arabtype*arab-mark    at 48pt
93% \font \ArabMkmk    = arabtype*arab-mkmk    at 48pt
94% \font \ArabKern    = arabtype*arab-kern    at 48pt
95% \font \ArabContext = arabtype*arab-context at 48pt
96% \font \ArabLigs    = arabtype*arab-ligs    at 48pt
97% \font \ArabCurs    = arabtype*arab-curs    at 48pt
98% \font \ArabUrdu    = arabtype*arab-urdu    at 48pt
99
100% \startbuffer[word]
101%     \char1604\char1616\char1604\char1617\char1648\char1607\char1616 % لِلّٰهِ
102% \stopbuffer
103
104\startbuffer[split-word]
105    \def\somechar #1{ \char#1\relax}%
106    \def\somevowel#1{ \char#1\relax}%
107    \dontleavehmode\ignorespaces\getbuffer[word]\removeunwantedspaces
108\stopbuffer
109
110\startbuffer[normal-word]
111    \def\somechar #1{\char#1\relax}%
112    \def\somevowel#1{\char#1\relax}%
113    \ignorespaces\getbuffer[word]\removeunwantedspaces
114\stopbuffer
115
116\startbuffer[word]
117    \somechar {1604}%
118    \somevowel{1616}%
119    \somechar {1604}%
120    \somevowel{1617}%
121    \somevowel{1648}%
122    \somechar {1607}%
123    \somevowel{1616}%
124    % لِلّٰهِ
125\stopbuffer
126
127\startbuffer[word]
128    \somechar {"644}%
129    \somevowel{"650}%
130    \somechar {"644}%
131    \somevowel{"651}%
132    \somevowel{"670}%
133    \somechar {"647}%
134    \somevowel{"650}%
135    % لِلّٰهِ
136\stopbuffer
137
138\startbuffer[paragraph]
139اَلْحَمْدُ لِلّٰهِ حَمْدَ مُعْتَرِفٍ بِحَمْدِهٖ، مُغْتَرِفٌ مِنْ بِحَارِ مَجْدِهٖ، بِلِسَانِ
140الثَّنَاۤءِ شَاكِرًا، وَلِحُسْنِ اٰلاۤئِهٖ نَاشِرًا؛ اَلَّذِيْ خَلَقَ الْمَوْتَ وَالْحَيٰوةَ، وَالْخَيْرَ
141وَالشَّرَّ، وَالنَّفْعَ وَالضَّرَّ، وَالسُّكُوْنَ وَالْحَرَكَةَ، وَالْأَرْوَاحَ
142وَالْأَجْسَامَ، وَالذِّكْرَ وَالنِّسْيَانَ.
143\stopbuffer
144
145\def\ArabSampleFont{arabtype}
146
147\def\ShowArabSample#1%
148  {\begingroup
149   \blank
150   \enabletrackers[otf.analyzing]
151   \doifmodeelse{dynamic-arabic}{
152        \font\ArabFont = \ArabSampleFont\space at 48pt
153   }{
154        \font\ArabFont = \ArabSampleFont*#1 at 48pt
155   }
156   \font\ArabFontX = \ArabSampleFont\space at 24pt
157   \startlinecorrection
158   \bTABLE[framecolor=red,rulethickness=1pt,offset=1ex]
159     \bTR
160       \bTD[width=.8\textwidth] % [ny=2]
161         \tttf\fontfeatureslist[#1][, ]%
162       \eTD
163       \bTD[width=.2\textwidth,align={lohi,middle},offset=0pt]%
164         \ArabFont\doifmode{dynamic-arabic}{\setfontfeature{#1}}\textdir TRT\relax
165         \getbuffer[normal-word]%
166       \eTD
167     \eTR
168%      \bTR
169%        \bTD[width=9em,align={lohi,middle},offset=0pt]%
170%          \ArabFontX\textdir TRT\relax
171%          \getbuffer[split-word]%
172%        \eTD
173%      \eTR
174   \eTABLE
175   \stoplinecorrection
176   \blank
177   \doifmodeelse{dynamic-arabic}{
178        \font\ArabFont = \ArabSampleFont\space at 24pt
179        \setfontfeature{#1}%
180   }{
181        \font\ArabFont = \ArabSampleFont*#1 at 24pt
182   }
183   \ArabFont
184   \pardir TRT\relax\textdir TRT\relax\getbuffer[paragraph]\endgraf
185   \disabletrackers[otf.analyzing]
186   \pardir TRT\relax\textdir TRT\relax\getbuffer[paragraph]\endgraf
187   \endgroup}
188
189\chapter{Arabic}
190
191Let's start with admitting that I don't speak or read Arabic, and the sample
192texts used here are part of what we use in the Oriental \TEX\ project for
193exploring advanced Arabic typesetting. This chapter will not discuss arab
194typesetting in much detail, but should be seen as complementing the \quote
195{Onthology on Arabic Typesetting} written by Idris. Here I will only show what
196the consequences are of applying features. Because we see glyphs but often still
197deal with characters when analyzing what to do, we will use these terms mixed.
198
199The font that we use here is the \quote {arabtype} font by MicroSoft. This font
200covers Latin scripts and Arabic and has a rich set of features. It's also a rather
201big font, so it is a nice torture test for \LUATEX.
202
203First we show what \MKIV\ does with a sequence of characters when no features
204are enabled by the user. We have turn on color tracing. This gives us some
205feedback about the how the analyze worked out. Analyzing for Arabic boils down
206to marking the initial, mid, final and isolated forms. We don't need to
207explicitly enable analyzing, it's on by default. The \type {mode} flag is set
208to \type {node} because we cannot use \TEX's default mechanism. When \LUATEX\
209and \MKIV\ are beyond beta stage, we will use that mode by default.
210
211\ShowArabSample {arab-none}
212
213Once these forms are identified, the \type {init}, \type {medi}, \type {fina}
214and \type {isol} features can be applied since they need this information. As
215you can see, different shapes show up. The vowels (marks in \OPENTYPE\ speak)
216are not affected. It may not be entirely clear here, but these vowels don't have
217width.
218
219\ShowArabSample {arab-compose}
220
221We start with some preparations with regards to combinations of marks. This
222is really needed in order to get the right output.
223
224\ShowArabSample {arab-replace}
225
226The order in which features are applied is dictated by the font and users don't
227need to bother about it. In the next example we enable the \type {mark} and
228\type {mkmk} features. As with other positioning related features, these are
229normally applied late in the feature chain.
230
231\ShowArabSample {arab-mark}
232
233The \type {mark} feature positions marks (vowels) relative to characters, also
234known as mark to base. The \type {mkmk} feature positions marks to basemarks.
235
236\ShowArabSample {arab-mkmk}
237
238Kerning depends on the font. Some fonts don't need kerning, others may need
239extensive relative positioning of characters (by now glyphs).
240
241\ShowArabSample {arab-kern}
242
243So far we only had rather straightforward replacements. More sophisticated
244replacements are those driven by the context. In principle all replacements
245can be context driven, but the \type {calt} and \type {clig} features are
246normally dedicated to the real complex ones that take preceding and following
247characters into account.
248
249\ShowArabSample {arab-context}
250
251Ligatures are often used to beautify Arabic typeset documents. Here we enable the
252whole lot.
253
254\ShowArabSample {arab-ligs}
255
256Kerning deals with horizontal displacements, but \type {curs} (cursive) goes one
257step further. As with marks, positioning is based on anchor points and resolving
258them involves a bit of trickery because one needs to take into account that
259characters may have vowels attached to them.
260
261\ShowArabSample {arab-curs}
262
263One script can serve multiple languages so let's see what happens when we switch to
264Urdu.
265
266\ShowArabSample {arab-urdu}
267
268In practice one will enable most of the features. In \MKIV\ one can define feature
269sets as follows:
270
271\starttyping
272\definefontfeature
273  [arab-default]
274  [mode=node,language=dflt,script=arab,
275   init=yes,medi=yes,fina=yes,isol=yes,
276   liga=yes,dlig=yes,rlig=yes,clig=yes,
277   mark=yes,mkmk=yes,kern=yes,curs=yes]
278\stoptyping
279
280Applying these features to fonts can be done in several ways, with as most basic
281one:
282
283\starttyping
284\font\ArabFont=arabtype*arab-default at 18pt
285\stoptyping
286
287Normally one will do something like
288
289\starttyping
290\definefont[ArabFont][arabtype*arab-default at 18pt]
291\stoptyping
292
293or use typescripts to set up ap proper font collection, in which case we end
294up with definitions that look like:
295
296\starttyping
297\definefontsynonym[ArabType][name:arabtype][features=arab-default]
298\definefontsynonym[Serif][ArabType]
299\stoptyping
300
301More information about typescripts can be found in manuals and on the
302\CONTEXT\ wiki.
303
304We end this chapter with showing two arabic fonts so that you can get a taste
305if the differences: arabtype by MicroSoft and Palatino which is designed by
306Herman Zapf for Linotype.
307
308\def\ArabSampleFont{arabtype} \ShowArabSample {arab-default}
309
310\def\ArabSampleFont{name:palatinoltarabic} \ShowArabSample {arab-default}
311
312These fonts are quite different in designsize:
313
314\def\Test{test} %  (\the\dimexpr1em\relax)}
315
316\starttabulate[|r|c|c|c|]
317\NC          \NC \bf arabtype                        \NC \bf palatino                                     \NC \NR
318\NC \bf 10pt \NC \definedfont[arabtype at 10pt]\Test \NC \definedfont[name:palatinoltarabic at 10pt]\Test \NC \NR
319\NC \bf 12pt \NC \definedfont[arabtype at 12pt]\Test \NC \definedfont[name:palatinoltarabic at 12pt]\Test \NC \NR
320\NC \bf 18pt \NC \definedfont[arabtype at 18pt]\Test \NC \definedfont[name:palatinoltarabic at 18pt]\Test \NC \NR
321\NC \bf 24pt \NC \definedfont[arabtype at 24pt]\Test \NC \definedfont[name:palatinoltarabic at 24pt]\Test \NC \NR
322\stoptabulate
323
324\stopcomponent
325