summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/unicode-data/load-unicode-xetex-classes.tex
blob: c85726466980e2d449827bbd1fc97ae605693f01 (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
% File load-unicode-xetex-classes.tex
%
% Copyright 2015,2016 The LaTeX3 Project
%
% It may be distributed and/or modified under the conditions of
% the LaTeX Project Public License (LPPL), either version 1.3c of
% this license or (at your option) any later version. The latest
% version of this license is in the file
% http://www.latex-project.org/lppl.txt.
%
% Issues with this file should be reported at
% https://github.com/latex3/unicode-data
%
% This file parses EastAsianWidth.txt and LineBreak.txt, provided by the
% Unicode Consortium, and when used with XeTeX sets \XeTeXcharclass for
% the following classes of code point:
% - "ID" (ideographic)
% - "OP" (opener)
% - "CL" (closer)
% - "NS" (non-starter)
% - "EX" (exclamation)
% - "IS" (infix separator)
% - "CM" (combining marks)
%
% All code points of class "ID" are assigned to a \XeTeXcharclass, but for
% other classes this only occurs when they fall into east Asian width type
% "F", "H" or "W" (full-, half- and wide-width).
%
% The following mappings between Unicode and XeTeX classes occur
% - "ID" is class 1
% - "OP" is class 2
% - "CL", "NS", "EX", "IS" are class 3
% - "CM" is class 256 (ignored)
% as standard: these may be over-ridden by defining \XeTeXcharclass<class>
% as required.
%
% This file does _not_ activate XeTeX's inter-character token mechanism
% (\XeTeXinterchartokenstate is not set) nor does it install any material in
% the inter-character token registers.
%
% Note that this file is separate from the main loader as the data structure
% here may need more refinement at the macro level.
%
% =============================================================================
%
% The data loaded here can currently only be used by XeTeX: check for the
% appropriate primitive.
\ifx\XeTeXcharclass\undefined
  \expandafter\endinput
\fi
% Just in case, check for the e-TeX extensions.
\ifx\eTeXversion\undefined
  \expandafter\endinput
\fi
% This file can be loaded in IniTeX mode so the category codes of |{|, |}| and
% |#| may not be correct. Everything is done in a group so that only the
% settings we want to propagate are made available generally.
\begingroup
  \catcode`\{=1 %
  \catcode`\}=2 %
% Write some basic information to the log.
  \catcode`\^=7 %
  \newlinechar=`\^^J %
  \message{^^J}%
  \message{load-unicode-xetex-classes.tex v1.1 (2016-01-04)^^J}%
  \message{Reading Unicode east Asian character class data^^J}%
% A string version of |#| will be needed to look for comment lines in the
% source. Once that is done proper parsing can begin.
  \catcode`\#=12 %
  \def\hash{#}%
  \catcode`\#=6 %
  \def\firsttoken#1#2\relax{#1}%
  \def\parseunicodedataI#1\relax{%
    \unless\if\hash\firsttoken#1?\relax
      \parseunicodedataII#1\relax
    \fi
  }%
% Both files to be parsed here have potential ranges of code points: find the
% first entry and search for the second.
  \def\parseunicodedataII#1;#2 #3\relax{%
    \parseunicodedataIII#1....\relax{#2}%
  }%
% From plain: may not be defined (yet).
  \def\loop#1\repeat{\def\body{#1}\iterate}%
  \def\iterate{%
    \body
      \let\next\iterate
    \else
      \let\next\relax
    \fi
    \next
  }%
  \let\repeat\fi
% For the East Asian width data, save the class of the current token.
  \def\parseunicodedataIII#1..#2..#3\relax#4{%
    \expandafter\def\csname EAW@\number"#1\endcsname{#4}%
    \ifx\relax#2\relax
    \else
      \count0="#1 %
      \loop
        \ifnum\count0<"#2 %
          \advance\count0 by 1 %
          \expandafter\def\csname EAW@\number\count0\endcsname{#4}%
      \repeat
    \fi
  }%
% A shared routine for reading the data files: only one part of the parser
% has to be altered.
  \def\storedpar{\par}%
  \def\readandparse#1{%
    \openin0=#1.txt %
% Read two lines from the source file to extract the version information
    \catcode`\#=12 %
    \read0 to \unicodedataline
    \message{\unicodedataline ^^J}%
    \read0 to \unicodedataline
    \message{\unicodedataline ^^J}%
    \loop\unless\ifeof0 %
      \read0 to \unicodedataline
      \unless\ifx\unicodedataline\storedpar
        \expandafter\parseunicodedataI\unicodedataline\relax
      \fi
    \repeat
    \catcode`\#=6 %
    \closein0 %
  }%
% Read the east Asian width data: no settings are made at this stage.
  \readandparse{EastAsianWidth}%
% Set up the different line break classes recognised.
  \ifdefined\XeTeXcharclassID
  \else
    \chardef\XeTeXcharclassID=1 %
  \fi
  \ifdefined\XeTeXcharclassOP
  \else
    \chardef\XeTeXcharclassOP=2 %
  \fi
  \ifdefined\XeTeXcharclassCL
  \else
    \chardef\XeTeXcharclassCL=3 %
  \fi
  \ifdefined\XeTeXcharclassEX
  \else
    \chardef\XeTeXcharclassEX=3 %
  \fi
  \ifdefined\XeTeXcharclassIS
  \else
    \chardef\XeTeXcharclassIS=3 %
  \fi
  \ifdefined\XeTeXcharclassNS
  \else
    \chardef\XeTeXcharclassNS=3 %
  \fi
  \ifdefined\XeTeXcharclassCM
  \else
    \chardef\XeTeXcharclassCM=256 %
  \fi
% Check the line break class and if necessary the east Asian width for the
% current code point. For code points of class |ID| there may be a range to
% set, and these are always recorded. In other cases check the east Asian width
% and set the class if appropriate.
  \def\ID{ID}%
  \def\parseunicodedataIII#1..#2..#3\relax#4{%
    \def\temp{#4}%
    \ifx\temp\ID
      \ifx\relax#2\relax
        \parseunicodedataIV{#1}{#1}%
      \else
        \parseunicodedataIV{#1}{#2}%
      \fi
    \else
      \ifnum 0%
        \if F\csname EAW@\number"#1\endcsname 1\fi
        \if H\csname EAW@\number"#1\endcsname 1\fi
        \if W\csname EAW@\number"#1\endcsname 1\fi
         >0 %
       \global\XeTeXcharclass"#1=\csname XeTeXcharclass#4\endcsname
      \fi
    \fi
  }%
% As we are inside a loop already, there needs to be a group here to preserve
% the iterator.
  \def\parseunicodedataIV#1#2{%
    \begingroup
      \count0="#1 %
      \loop
        \ifnum\count0<"#2 %
          \global\XeTeXcharclass\count0=1 %
          \advance\count0 by 1 %
      \repeat
    \endgroup
  }%
  \readandparse{LineBreak}%
\endgroup