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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
|
%
% lltjfont.sty: derived from plfonts.dtx in pLaTeX.
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{lltjfont}[2017/04/01 Patch to NFSS2 for LuaTeX-ja]
\def\ltj@chardef@text@cmd#1{%
\let\@ifdefinable\@@ifdefinable%
\edef\ltj@chardef@text@cmd@name{\expandafter\@gobble\string#1}%
\afterassignment\ltj@chardef@text@cmd@\ltj@tempcnta
}
\def\ltj@chardef@text@cmd@{%
\ifnum\ltj@tempcnta>"7F
\expandafter\edef\csname \ltj@chardef@text@cmd@name\endcsname{%
\noexpand\ltjalchar\the\ltj@tempcnta\space
}%
\else
\expandafter\chardef\csname \ltj@chardef@text@cmd@name\endcsname\ltj@tempcnta
\fi
}
\def\DeclareTextSymbol#1#2#3{%
\@dec@text@cmd\ltj@chardef@text@cmd#1{#2}#3\relax
}
\ifdefined\UnicodeEncodingName
\let\ltj@temp@DeclareTextComposite=\DeclareTextComposite
\def\DeclareTextComposite#1#2#3#4{}%
\input{tuenc.def}
\let\DeclareTextComposite=\ltj@temp@DeclareTextComposite
\expandafter\patchcmd\csname TU\string\textasteriskcentered\endcsname{\char}{\ltjalchar}{}{}
\fi
\let\k@encoding\@empty
\let\ck@encoding\@empty
% LuaTeX-ja uses JY3 and JT3 encodings.
\def\cy@encoding{JY3}\def\ct@encoding{JT3}
\let\k@family\@empty
\let\k@series\@empty
\let\k@shape\@empty
\def\curr@kfontshape{\k@encoding/\k@family/\k@series/\k@shape}
\def\rel@fontshape{\f@encoding/\f@family/\f@series/\f@shape}
\ifdefined\Cht\else\newdimen\Cht\fi
\ifdefined\cht\else\newdimen\cht\fi
\ifdefined\Cdp\else\newdimen\Cdp\fi
\ifdefined\cdp\else\newdimen\cdp\fi
\ifdefined\Cwd\else\newdimen\Cwd\fi
\ifdefined\cwd\else\newdimen\cwd\fi
\ifdefined\Cvs\else\newdimen\Cvs\fi
\ifdefined\cvs\else\newdimen\cvs\fi
\ifdefined\Chs\else\newdimen\Chs\fi
\ifdefined\chs\else\newdimen\chs\fi
\ifdefined\cHT\else\newdimen\cHT\fi
%\let\afont\font
\let\ystrutbox\strutbox
\newbox\dstrutbox
\newbox\tstrutbox
\newbox\zstrutbox
\def\strutbox{%
\ifnum\ltjgetparameter{direction}=1 \dstrutbox % dtou
\else\ifnum\ltjgetparameter{direction}=4 \ystrutbox % yoko
\else\tstrutbox % tate and utod
\fi\fi
}
\def\strut{\relax
\ifnum\ltjgetparameter{direction}=1 % dtou
\ifmmode\copy\dstrutbox\else\unhcopy\dstrutbox\fi
\else\ifnum\ltjgetparameter{direction}=4 % yoko
\ifmmode\copy\ystrutbox\else\unhcopy\ystrutbox\fi
\else % tate and utod
\ifmmode\copy\tstrutbox\else\unhcopy\tstrutbox\fi
\fi\fi
}
\def\ystrut{\relax\hbox{\yoko
\ifmmode\copy\ystrutbox\else\unhcopy\ystrutbox\fi}}
\def\tstrut{\relax\hbox{\tate
\ifmmode\copy\tstrutbox\else\unhcopy\tstrutbox\fi}}
\def\dstrut{\relax\hbox{\dtou
\ifmmode\copy\dstrutbox\else\unhcopy\dstrutbox\fi}}
\def\zstrut{\relax\hbox{\utod
\ifmmode\copy\zstrutbox\else\unhcopy\zstrutbox\fi}}
{%
\def\cdp@elt#1#2#3#4{%
\directlua{luatexja.jfont.add_fenc_list('\luatexluaescapestring{#1}')}}%
\cdp@list%
}
\def\DeclareFontEncoding{%
\begingroup
\nfss@catcodes
\expandafter\endgroup
\DeclareFontEncoding@}
\def\DeclareFontEncoding@#1#2#3{%
\expandafter
\ifx\csname T@#1\endcsname\relax
\def\cdp@elt{\noexpand\cdp@elt}%
\xdef\cdp@list{\cdp@list\cdp@elt{#1}%
{\default@family}{\default@series}%
{\default@shape}}%
\expandafter\let\csname#1-cmd\endcsname\@changed@cmd
\directlua{luatexja.jfont.add_fenc_list('\luatexluaescapestring{#1}')}%
\else
\@font@info{Redeclaring font encoding #1}%
\fi
\global\@namedef{T@#1}{#2}%
\global\@namedef{M@#1}{\default@M#3}%
\xdef\LastDeclaredEncoding{#1}%
}
\def\DeclareKanjiEncoding#1{%
\@latex@warning{%
The \string\DeclareKanjiEncoding\space is obsoleted command. Please use
\MessageBreak
the \string\DeclareTateKanjiEncoding\space for `Tate-kumi' encoding, and
\MessageBreak
the \string\DeclareYokoKanjiEncoding\space for `Yoko-kumi' encoding.
\MessageBreak
I treat the `#1' encoding as `Yoko-kumi'.}
\DeclareYokoKanjiEncoding{#1}%
}
\def\DeclareYokoKanjiEncoding{%
\begingroup
\nfss@catcodes
\expandafter\endgroup
\DeclareYokoKanjiEncoding@}
\def\DeclareYokoKanjiEncoding@#1#2#3{%
\expandafter\ifx\csname T@#1\endcsname\relax
\def\cdp@elt{\noexpand\cdp@elt}%
\xdef\cdp@list{\cdp@list\cdp@elt{#1}%
{\default@k@family}{\default@k@series}%
{\default@k@shape}}%
\expandafter\let\csname#1-cmd\endcsname\@changed@kcmd
\directlua{luatexja.jfont.add_kyenc_list('\luatexluaescapestring{#1}')}%
\else
\@font@info{Redeclaring KANJI (yoko) font encoding #1}%
\fi
\global\@namedef{T@#1}{#2}%
\global\@namedef{M@#1}{\default@KM#3}%
}
\def\DeclareTateKanjiEncoding{%
\begingroup
\nfss@catcodes
\expandafter\endgroup
\DeclareTateKanjiEncoding@}
\def\DeclareTateKanjiEncoding@#1#2#3{%
\expandafter\ifx\csname T@#1\endcsname\relax
\def\cdp@elt{\noexpand\cdp@elt}%
\xdef\cdp@list{\cdp@list\cdp@elt{#1}%
{\default@k@family}{\default@k@series}%
{\default@k@shape}}%
\expandafter\let\csname#1-cmd\endcsname\@changed@kcmd
\directlua{luatexja.jfont.add_ktenc_list('\luatexluaescapestring{#1}')}%
\else
\@font@info{Redeclaring KANJI (tate) font encoding #1}%
\fi
\global\@namedef{T@#1}{#2}%
\global\@namedef{M@#1}{\default@KM#3}%
}
\@onlypreamble\DeclareKanjiEncoding
\@onlypreamble\DeclareYokoKanjiEncoding
\@onlypreamble\DeclareYokoKanjiEncoding@
\@onlypreamble\DeclareTateKanjiEncoding
\@onlypreamble\DeclareTateKanjiEncoding@
\def\DeclareKanjiEncodingDefaults#1#2{%
\ifx\relax#1\else
\ifx\default@KT\@empty\else
\@font@info{Overwriting KANJI encoding scheme text defaults}%
\fi
\gdef\default@KT{#1}%
\fi
\ifx\relax#2\else
\ifx\default@KM\@empty\else
\@font@info{Overwriting KANJI encoding scheme math defaults}%
\fi
\gdef\default@KM{#2}%
\fi}
\let\default@KT\@empty
\let\default@KM\@empty
\@onlypreamble\DeclareKanjiEncodingDefaults
\def\DeclareFontFamily#1#2#3{%
\@ifundefined{T@#1}%
{\@latex@error{Encoding scheme `#1' unknown}\@eha}%
{\def\reserved@a{#3}%
\global
\expandafter\let\csname #1+#2\expandafter\endcsname
\ifx \reserved@a\@empty
\@empty
\else \reserved@a
\fi
\directlua{luatexja.jfont.add_ffam('\luatexluaescapestring{#2}')}%
}%
}
\def\DeclareKanjiFamily#1#2#3{%
\@ifundefined{T@#1}%
{\@latex@error{KANJI Encoding scheme `#1' unknown}\@eha}%
{\def\reserved@a{#3}%
\global
\expandafter\let\csname #1+#2\expandafter\endcsname
\ifx \reserved@a\@empty
\@empty
\else \reserved@a
\fi
\directlua{luatexja.jfont.add_kfam('\luatexluaescapestring{#2}')}%
}%
}
\def\DeclareKanjiSubstitution#1#2#3#4{%
\expandafter\ifx\csname T@#1\endcsname\relax
\@latex@error{KANJI Encoding scheme `#1' unknown}\@eha
\else
\begingroup
\def\reserved@a{#1}%
\toks@{}%
\def\cdp@elt##1##2##3##4{%
\def\reserved@b{##1}%
\ifx\reserved@a\reserved@b
\addto@hook\toks@{\cdp@elt{#1}{#2}{#3}{#4}}%
\else
\addto@hook\toks@{\cdp@elt{##1}{##2}{##3}{##4}}%
\fi}%
\cdp@list
\xdef\cdp@list{\the\toks@}%
\endgroup
\global\@namedef{D@#1}{\def\default@family{#2}%
\def\default@series{#3}%
\def\default@shape{#4}}%
\fi}
\def\DeclareErrorKanjiFont#1#2#3#4#5{%
\xdef\error@kfontshape{%
\noexpand\expandafter\noexpand\split@name\noexpand\string
\expandafter\noexpand\csname#1/#2/#3/#4/#5\endcsname
\noexpand\@nil}%
\gdef\default@k@family{#2}%
\gdef\default@k@series{#3}%
\gdef\default@k@shape{#4}%
\global\let\k@family\default@k@family
\global\let\k@series\default@k@series
\global\let\k@shape\default@k@shape
\gdef\f@size{#5}%
\gdef\f@baselineskip{#5pt}}
\@onlypreamble\DeclareKanjiSubstitution
\@onlypreamble\DeclareErrorKanjiFont
\def\DeclareFixedFont#1#2#3#4#5#6{%
\begingroup
\math@fontsfalse
\every@math@size{}%
\fontsize{#6}\z@
\directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{#2}')}\ifin@%
\usekanji{#2}{#3}{#4}{#5}%
\global\let#1\getjfont
\else
\directlua{luatexja.jfont.is_ktenc('\luatexluaescapestring{#2}')}\ifin@%
\usekanji{#2}{#3}{#4}{#5}%
\global\let#1\gettfont
\else
\useroman{#2}{#3}{#4}{#5}%
\global\expandafter\let\expandafter#1\the\font
\fi
\fi
\endgroup
}
\def\DLMfontsw@standard#1#2#3{#1{#2{#3}}}
\def\reDeclareMathAlphabet#1#2#3{%
\ifdefined#2
\@temptokena\expandafter{#2}%
\else
\@temptokena{#2}%
\fi
\ifdefined#3
\toks0\expandafter{#3}%
\else
\toks0{#3}%
\fi
\long\protected\edef#1{%
\noexpand\DLMfontsw@standard{\the\@temptokena}{\the\toks0}}%
}
\@onlypreamble\reDeclareMathAlphabet
\def\all@shape{all}%
\def\DeclareRelationFont#1#2#3#4#5#6#7#8{%
\def\rel@shape{#4}%
\ifx\rel@shape\@empty
\global
\expandafter\def\csname rel@#1/#2/#3/all\endcsname{%
\romanencoding{#5}\romanfamily{#6}%
\romanseries{#7}}%
\else
\global
\expandafter\def\csname rel@#1/#2/#3/#4\endcsname{%
\romanencoding{#5}\romanfamily{#6}%
\romanseries{#7}\romanshape{#8}}%
\fi
}
\def\SetRelationFont#1#2#3#4#5#6#7#8{%
\def\rel@shape{#4}%
\ifx\rel@shape\@empty
\expandafter\def\csname rel@#1/#2/#3/all\endcsname{%
\romanencoding{#5}\romanfamily{#6}%
\romanseries{#7}}%
\else
\expandafter\def\csname rel@#1/#2/#3/#4\endcsname{%
\romanencoding{#5}\romanfamily{#6}%
\romanseries{#7}\romanshape{#8}}%
\fi
}
\newif\if@knjcmd
\def\userelfont{\@knjcmdtrue}
\RequirePackage{everysel}
\let\ltj@@EverySelectfont@Init=\@EverySelectfont@Init
\expandafter\expandafter\expandafter\let
\expandafter\expandafter\csname ltj@@orig@selectfont\endcsname\csname selectfont\space\endcsname
\@EverySelectfont@Init
\def\@EverySelectfont@Init{%
\expandafter\let\csname selectfont\space \endcsname \ltj@@orig@selectfont
\ltj@@EverySelectfont@Init
}
\def\ltj@selectfont@patch{%
\directlua{luatexja.base.start_time_measure('selectfont')}%
\let\tmp@error@fontshape\error@fontshape
\let\error@fontshape\error@kfontshape
\directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{\k@encoding}')}\ifin@%
\let\cy@encoding\k@encoding
\edef\ct@encoding{\csname t@enc@\k@encoding\endcsname}%
\else
\directlua{luatexja.jfont.is_ktenc('\luatexluaescapestring{\k@encoding}')}\ifin@%
\let\ct@encoding\k@encoding
\edef\cy@encoding{\csname y@enc@\k@encoding\endcsname}%
\else
\@latex@error{KANJI Encoding scheme `\k@encoding' unknown}\@eha
\fi
\fi
%
\let\k@encoding\ct@encoding
\xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
\pickup@tfont
\font@name
\ltj@@does@alt@set{\curr@kfontshape}%
% alt fonts の定義
\directlua{luatexja.jfont.output_alt_font_cmd('t', '\luatexluaescapestring{\curr@kfontshape}')}%
% 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
\directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
\fi
%
\let\k@encoding\cy@encoding
\xdef\font@name{\csname\curr@kfontshape/\f@size\endcsname}%
\pickup@jfont
\font@name
\ltj@@does@alt@set{\curr@kfontshape}%
% alt fonts の定義
\directlua{luatexja.jfont.output_alt_font_cmd('y', '\luatexluaescapestring{\curr@kfontshape}')}%
% 定義した alt fonts のデータを \ltjdeclarealtfont に渡すのと同等の処理をする
\directlua{luatexja.jfont.pickup_alt_font_a('\f@size')}%
\fi
%
\edef\tmp@item{{\k@encoding}}\expandafter\def\expandafter\k@encoding\tmp@item
\kenc@update
\let\error@fontshape\tmp@error@fontshape
%
\if@knjcmd \@knjcmdfalse
\expandafter\ifx
\csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname\relax
\expandafter\ifx
\csname rel@\k@encoding/\k@family/\k@series/all\endcsname\relax
\else
\csname rel@\k@encoding/\k@family/\k@series/all\endcsname\selectfont
% 警告: 再び \selectfont を呼んでいる.無限ループの可能性あり
\fi
\else
\csname rel@\k@encoding/\k@family/\k@series/\k@shape\endcsname\selectfont
% 警告: 再び \selectfont を呼んでいる.無限ループの可能性あり
\fi
\fi
\directlua{luatexja.base.stop_time_measure('selectfont')}%
}
\EverySelectfont{\ltj@selectfont@patch}
\def\KanjiEncodingPair#1#2{\@namedef{t@enc@#1}{#2}\@namedef{y@enc@#2}{#1}}
\def\set@fontsize#1#2#3{%
\@defaultunits\@tempdimb#2pt\relax\@nnil
\edef\f@size{\strip@pt\@tempdimb}%
\@defaultunits\@tempskipa#3pt\relax\@nnil
\edef\f@baselineskip{\the\@tempskipa}%
\edef\f@linespread{#1}%
\let\baselinestretch\f@linespread
\def\size@update{%
\baselineskip\f@baselineskip\relax
\baselineskip\f@linespread\baselineskip
\normalbaselineskip\baselineskip
\adjustbaseline
\setbox\ystrutbox\hbox{\yoko
\vrule\@width\z@
\@height.7\baselineskip \@depth.3\baselineskip}%
\setbox\dstrutbox\hbox{\dtou
\vrule\@width\z@
\@height.7\baselineskip \@depth.3\baselineskip}%
\setbox\tstrutbox\hbox{\tate
\vrule\@width\z@
\@height.5\baselineskip \@depth.5\baselineskip}%
\setbox\zstrutbox\hbox{\utod
\vrule\@width\z@
\@height.7\baselineskip \@depth.3\baselineskip}%
\let\size@update\relax}}
\ifdefined\newluafunction
\newluafunction\ltj@@adjust@baseline@inner
\begingroup\catcode`\~=12
\directlua{%
local nulltable = {}
local t = lua.get_functions_table()
local getfont, dir_tate = font.getfont, luatexja.dir_table.dir_tate
local fmt, get_attr = luatexja.jfont.font_metric_table, tex.getattribute
local setdimen, set_attr = tex.setdimen, tex.setattribute
local dir = luatexja.unary_pars.direction
t[\the\ltj@@adjust@baseline@inner] = function()
local ft = fmt[get_attr('ltj@curtfnt')] or nulltable
ft = ft and ft.char_type or nulltable
local fk = ft and ft[0] or nulltable
local ht, dp, wd = fk.height or 0, fk.depth or 0,
fk.width or ft.zw or 0
local fm
= ((getfont(font.current()) or nulltable)
.characters or nulltable)[77] or nulltable %% 'M'
set_attr('ltj@tablshift',
0.5*((fm.height or 0)- (fm.depth or 0) - ht+ dp))
if dir() ~= dir_tate then
ft = fmt[get_attr('ltj@curjfnt')] or nulltable
ft = ft and ft.char_type or nulltable
fk = ft and ft[0] or nulltable
ht, dp, wd = fk.height or 0, fk.depth or 0,
fk.width or ft.zw or 0
end
setdimen('cht', ht); setdimen('cdp', dp)
setdimen('cwd', wd); setdimen('chs', wd)
setdimen('cHT', ht+dp)
end
}\endgroup
\def\adjustbaseline{\luafunction\ltj@@adjust@baseline@inner
\cvs\normalbaselineskip}
\else
\newbox\adjust@box
\newbox\adjust@box@aux
\newdimen\adjust@dimen
\def\adjustbaseline{%
\setbox\adjust@box\hbox{%
\ltj@ykblshift\z@\ltj@tkblshift\z@ 漢}%
\cht\ht\adjust@box
\cdp\dp\adjust@box
\cwd\wd\adjust@box
\cvs\normalbaselineskip
\chs\cwd
\cHT\cht \advance\cHT\cdp
\setbox\adjust@box@aux\hbox{\tate\ltj@tkblshift\z@ 漢}%
\setbox\adjust@box\hbox{\tate\ltj@tablshift\z@ M}%
\adjust@dimen\ht\adjust@box
\advance\adjust@dimen\dp\adjust@box
\advance\adjust@dimen-\ht\adjust@box@aux
\divide\adjust@dimen\tw@
\advance\adjust@dimen0.5\dp\adjust@box@aux
\advance\adjust@dimen-\dp\adjust@box
\ltj@tablshift=\adjust@dimen
}
\fi
\DeclareRobustCommand\romanencoding[1]{%
\expandafter\ifx\csname T@#1\endcsname\relax
\@latex@error{Encoding scheme `#1' unknown}\@eha
\else
\edef\f@encoding{#1}%
\ifx\cf@encoding\f@encoding
\let\enc@update\relax
\else
\let\enc@update\@@enc@update
\fi
\fi
}
\DeclareRobustCommand\kanjiencoding[1]{%
\expandafter\ifx\csname T@#1\endcsname\relax
\@latex@error{KANJI Encoding scheme `#1' unknown}\@eha
\else
\edef\k@encoding{#1}%
\ifx\ck@encoding\k@encoding
\let\kenc@update\relax
\else
\let\kenc@update\@@kenc@update
\fi
\fi
}
\DeclareRobustCommand\fontencoding[1]{%
\directlua{luatexja.jfont.is_kyenc('\luatexluaescapestring{#1}')}\ifin@%
\kanjiencoding{#1}\else\romanencoding{#1}\fi}
\def\@@kenc@update{%
\default@KT
\csname T@\k@encoding\endcsname
\csname D@\k@encoding\endcsname
\let\kenc@update\relax
\let\ck@encoding\k@encoding
\edef\tmp@enc{'\luatexluaescapestring{\k@encoding}'}%
\directlua{luatexja.jfont.is_kyenc(\tmp@enc)}\ifin@%
\let\cy@encoding\k@encoding
\else
\directlua{luatexja.jfont.is_ktenc(\tmp@enc)}\ifin@%
\let\ct@encoding\k@encoding
\else
\@latex@error{KANJI Encoding scheme `\k@encoding' unknown}\@eha
\fi
\fi
}
\let\kenc@update\relax
\def\@changed@kcmd#1#2{%
\ifx\protect\@typeset@protect
\@inmathwarn#1%
\expandafter\ifx\csname\ck@encoding\string#1\endcsname\relax
\expandafter\ifx\csname ?\string#1\endcsname\relax
\expandafter\def\csname ?\string#1\endcsname{%
\TextSymbolUnavailable#1%
}%
\fi
\global\expandafter\let
\csname\cf@encoding \string#1\expandafter\endcsname
\csname ?\string#1\endcsname
\fi
\csname\ck@encoding\string#1%
\expandafter\endcsname
\else
\noexpand#1%
\fi}
\newif\if@notkfam
\newif\if@notffam
\newif\if@tempswz
\def\@ltj@use@fd{true}
\DeclareRobustCommand\romanfamily[1]{\edef\f@family{#1}}
\DeclareRobustCommand\kanjifamily[1]{\edef\k@family{#1}}
\DeclareRobustCommand\fontfamily[1]{%
\@notkfamfalse\@notffamfalse
\edef\tmp@item{'\luatexluaescapestring{#1}'}%
%
\directlua{luatexja.jfont.search_kfam(\tmp@item, \@ltj@use@fd)}%
\ifin@\edef\k@family{#1}\else\@notkfamtrue\fi
%
% alphabetic fonts part
\directlua{luatexja.jfont.is_ffam(\tmp@item)}%
\ifin@\edef\f@family{#1}\else
% checking is_stored_ffam is not sufficient,
% since LuaTeX-ja doesn't know whats fonts are defined before LuaTeX-ja is loaded.
\ifcsname \f@encoding+#1\endcsname % easy case
\directlua{luatexja.jfont.add_ffam(\tmp@item)}\edef\f@family{#1}%
\else
\@tempswafalse
\def\cdp@elt##1{\ifcsname ##1+#1\endcsname\@tempswatrue\fi}%
\directlua{luatexja.jfont.search_ffam_declared()}%
\if@tempswz
\directlua{luatexja.jfont.add_ffam(\tmp@item)}\edef\f@family{#1}%
\else
% now we search Nffam_list and font definition files.
\directlua{luatexja.jfont.search_ffam_fd(\tmp@item)}%
\ifin@\edef\f@family{#1}\else\@notffamtrue\fi
\fi
\fi
\fi
%
\if@notkfam\if@notffam
\edef\k@family{#1}\edef\f@family{#1}%
\fi\fi
}
\DeclareRobustCommand\romanseries[1]{\edef\f@series{#1}}
\DeclareRobustCommand\kanjiseries[1]{\edef\k@series{#1}}
\DeclareRobustCommand\fontseries[1]{\kanjiseries{#1}\romanseries{#1}}
\DeclareRobustCommand\romanshape[1]{\edef\f@shape{#1}}
\DeclareRobustCommand\kanjishape[1]{\edef\k@shape{#1}}
\DeclareRobustCommand\fontshape[1]{\kanjishape{#1}\romanshape{#1}}
\def\usekanji#1#2#3#4{%
\kanjiencoding{#1}\kanjifamily{#2}\kanjiseries{#3}\kanjishape{#4}%
\selectfont\ignorespaces}
\def\useroman#1#2#3#4{%
\romanencoding{#1}\romanfamily{#2}\romanseries{#3}\romanshape{#4}%
\selectfont\ignorespaces}
\protected\def\usefont#1#2#3#4{%
\directlua{luatexja.jfont.is_kenc('\luatexluaescapestring{#1}')}\ifin@%
\usekanji{#1}{#2}{#3}{#4}%
\else\useroman{#1}{#2}{#3}{#4}%
\fi}
\DeclareRobustCommand\normalfont{%
\kanjiencoding{\kanjiencodingdefault}%
\kanjifamily{\kanjifamilydefault}%
\kanjiseries{\kanjiseriesdefault}%
\kanjishape{\kanjishapedefault}%
\romanencoding{\encodingdefault}%
\romanfamily{\familydefault}%
\romanseries{\seriesdefault}%
\romanshape{\shapedefault}%
\selectfont\ignorespaces}
\let\reset@font\normalfont
\DeclareRobustCommand\mcfamily
{\not@math@alphabet\mcfamily\mathmc
\kanjifamily\mcdefault\selectfont}
\DeclareRobustCommand\gtfamily
{\not@math@alphabet\gtfamily\mathgt
\kanjifamily\gtdefault\selectfont}
\let\romanprocess@table\process@table
\def\kanjiprocess@table{%
\kanjiencoding{\kanjiencodingdefault}%
\kanjifamily{\kanjifamilydefault}%
\kanjiseries{\kanjiseriesdefault}%
\kanjishape{\kanjishapedefault}%
}
\def\process@table{%
\romanprocess@table
\kanjiprocess@table
}
\@onlypreamble\romanprocess@table
\@onlypreamble\kanjiprocess@table
%%%%%% LuaTeX-ja specific
% #1 の展開結果から encoding 部分をとりだし,それが和文用かどうかの結果を \ifin@ に代入
\def\ltj@@IsFontJapanese#1{%
\directlua{luatexja.jfont.is_kenc(string.match(
'\luatexluaescapestring{#1}', '[^/]+'))}}
\let\extract@afont\extract@font
\def\pickup@jfont{%
\expandafter \ifx \font@name \relax
\let\extract@font\extract@jfont
\define@newfont
\let\extract@font\extract@afont
\fi
\let\getjfont\font@name}
\def\pickup@tfont{%
\expandafter \ifx \font@name \relax
\let\extract@font\extract@tfont
\define@newfont
\let\extract@font\extract@afont
\fi
\let\gettfont\font@name}
% 異なる和文 enc/fam/ser/shape からは異なるフォント番号が振られるように
% わざと「ゴミをつける」
\def\ltj@@patch@external@font#1 at{%
#1\directlua{luatexja.jfont.print_aftl_address()}\space at%
}
\def\extract@jfont{%
\get@external@font
\ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}%
\edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
\fi
\expandafter\globaljfont\font@name\external@font\relax% ここで時間がかかる
\font@name%\global\zw=\zw\global\zh=\zh
\csname \f@encoding+\f@family\endcsname
\csname\curr@fontshape\endcsname}
\def\extract@tfont{%
\get@external@font
\ltj@@does@alt@set{\f@encoding/\f@family/\f@series/\f@shape}%
\edef\external@font{\expandafter\ltj@@patch@external@font\external@font}%
\fi
\expandafter\globaltfont\font@name\external@font\relax
\font@name%\global\zw=\zw\global\zh=\zh
\csname \f@encoding+\f@family\endcsname
\csname\curr@fontshape\endcsname}
\let\ltj@@al@do@subst@correction=\do@subst@correction
\def\ltj@@ja@do@subst@correction{%
\xdef\subst@correction{%
\font@name
\global\expandafter\let\csname \curr@fontshape/\f@size\endcsname\font@name%
\relax}%
\aftergroup\subst@correction
}
\def\do@subst@correction{%
\ltj@@IsFontJapanese{\curr@fontshape}\ifin@%
\ltj@@ja@do@subst@correction
\else
\ltj@@al@do@subst@correction
\fi
}
\let\@@italiccorr=\/
%%%%%% Japanese font for math mode
% \M@<enc> から その <enc> が和文用か調べる
{\catcode`M=12%
\gdef\ltj@@mathJapaneseFonts#1M#2#3\relax{\ltj@@IsFontJapanese{#3}}}
\let\ltj@@al@getanddefine@fonts=\getanddefine@fonts
\def\ltj@@ja@getanddefine@fonts#1#2{%
\xdef\font@name{\csname \string#2/\tf@size\endcsname}%
\pickup@jfont\let\textfont@name\font@name
\xdef\font@name{\csname \string#2/\sf@size\endcsname}%
\pickup@jfont\let\scriptfont@name\font@name
\xdef\font@name{\csname \string#2/\ssf@size\endcsname}%
\pickup@jfont
\edef\math@fonts{\math@fonts\ltj@setpar@global%
\ltj@@set@stackfont#1,\textfont@name:{MJT}%
\ltj@@set@stackfont#1,\scriptfont@name:{MJS}%
\ltj@@set@stackfont#1,\font@name:{MJSS}%
}%
}
\def\getanddefine@fonts#1#2{%
\ltj@tempcnta=#1\ltj@@IsFontJapanese{\string#2}%
\ifin@\let\ltj@temp=\ltj@@ja@getanddefine@fonts%
\else \let\ltj@temp=\ltj@@al@getanddefine@fonts\fi
\ltj@temp{#1}{#2}%
}
\def\use@mathgroup#1#2{\relax\ifmmode
\math@bgroup
\expandafter\ifx\csname M@\f@encoding\endcsname#1\else
#1\fi\ltj@tempcnta=#2 \expandafter\ltj@@mathJapaneseFonts\string#1\relax%
\ifin@\jfam#2\relax\else\mathgroup#2\relax\fi
\expandafter\math@egroup\fi}%
%%%%%% Alternate Japanese Fonts
%%%% \DeclareAlternateKanjiFont<Benc><Bfam><Bser><Bshape><Aenc><Afam><Aser><Ashape><range>
% いつも global
\def\DeclareAlternateKanjiFont#1#2#3#4#5#6#7#8#9{%
\edef\@temp{#9}%
\ifx\@temp\@empty\else
{\def\ltj@temp@bfont{#1/#2/#3/#4}\def\ltj@temp@afont{#5/#6/#7/#8}%
\expandafter\ltj@@altfont@latex#9,,}\ignorespaces
\fi}
\def\ltj@@altfont@latex#1,{\def\ltj@temp{#1}%
\ifx\ltj@temp\empty\let\@next=\relax\else
\ltj@@altfont@latexA{#1}\let\@next=\ltj@@altfont@latex\fi\@next}
\def\ltj@@altfont@latexA#1{\ltj@@altfont@latexB#1--\@nil}
\def\ltj@@altfont@latexB#1-#2-#3\@nil{\def\ltj@temp{#3}%
\ifx\ltj@temp\empty
\ltj@tempcnta=#1\relax\ltj@tempcntb=\ltj@tempcnta
\else
\def\ltj@temp{#1}%
\ifx\ltj@temp\empty\ltj@tempcnta='200\else\ltj@tempcnta=#1\fi\relax
\def\ltj@temp{#2}%
\ifx\ltj@temp\empty\ltj@tempcntb="10FFFF\else\ltj@tempcntb=#2\fi\relax%"
\fi
\directlua{luatexja.jfont.set_alt_font_latex(
\the\ltj@tempcnta,\the\ltj@tempcntb,
'\luatexluaescapestring{\ltj@temp@afont}',
'\luatexluaescapestring{\ltj@temp@bfont}')}%
}
%%%% \ClearAlternateKanjiFont<Benc><Bfam><Bser><Bshape>
% いつも global
\def\ClearAlternateKanjiFont#1#2#3#4{%
\directlua{luatexja.jfont.clear_alt_font_latex('\luatexluaescapestring{#1/#2/#3/#4}')}}
\def\ltj@pickup@altfont@auxy#1{%
\begingroup\edef\font@name{\csname #1/\f@size\endcsname}\pickup@jfont\endgroup%
}
\def\ltj@pickup@altfont@auxt#1{%
\begingroup\edef\font@name{\csname #1/\f@size\endcsname}\pickup@tfont\endgroup%
}
\def\ltj@pickup@altfont@copy#1#2{%
\ltj@@getjfontnumber#1%
\directlua{luatexja.jfont.pickup_alt_font_b(\the\ltj@tempcntc,'\luatexluaescapestring{#2}')}%
}
\def\ltj@@does@alt@set#1{%
\directlua{luatexja.jfont.does_alt_set'\luatexluaescapestring{#1}'}}
%%%% patch \@text@composite because of {y,t}albaselineshift
% %% \pltx@isletter from plfonts.dtx
% \def\pltx@mark{\pltx@mark@}
% \let\pltx@scanstop\relax
% \long\def\pltx@cond#1\fi{%
% #1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
% \long\def\pltx@isletter#1{%
% \expandafter\pltx@isletter@i#1\pltx@scanstop}
% \long\def\pltx@isletter@i#1\pltx@scanstop{%
% \pltx@cond\ifx\pltx@mark#1\pltx@mark\fi{\@firstoftwo}%
% {\pltx@isletter@ii\pltx@scanstop#1\pltx@scanstop{}#1\pltx@mark}}
% \long\def\pltx@isletter@ii#1\pltx@scanstop#{%
% \pltx@cond\ifx\pltx@mark#1\pltx@mark\fi%
% {\pltx@isletter@iii}{\pltx@isletter@iv}}
% \long\def\pltx@isletter@iii#1\pltx@mark{\@secondoftwo}
% \long\def\pltx@isletter@iv#1#2#3\pltx@mark{%
% \pltx@cond\ifx\pltx@mark#3\pltx@mark\fi{%
% \pltx@cond{\ifnum0\ifcat A\noexpand#21\fi\ifcat=\noexpand#21\fi>\z@}\fi
% {\@firstoftwo}{\@secondoftwo}%
% }{\@secondoftwo}}
%
% \def\@text@composite@x#1#2{%
% \ifx#1\relax
% #2%
% \else\pltx@isletter{#1}{#1}{%
% \begingroup
% \setbox\z@\hbox\bgroup%
% \ltj@yablshift\z@ \ltj@tablshift\z@
% #1%
% \@tempcntb\directlua{luatexja.pltx_composite_last_node_char()}%)
% \xdef\pltx@composite@temp{\noexpand\@tempcntb=\the\@tempcntb\relax}%
% \aftergroup\pltx@composite@temp
% \egroup
% \ifnum\ltjgetparameter{direction}=3 %
% \@tempdima=\ltj@tablshift sp\else\@tempdima=\ltj@yablshift sp\fi
% \ifnum\@tempcntb<\z@\@tempcnta\z@\else
% \@tempcnta=\ltjgetparameter{jacharrange}{\ltjgetparameter{chartorange}{\@tempcntb}}\relax
% \ifnum\@tempcnta=\z@\@tempdima\z@\fi
% \fi
% \ifnum\@tempcnta>\z@
% \ifodd\ltjgetparameter{alxspmode}{\@tempcntb}\else\leavevmode\hbox{}\fi
% \begingroup\mathsurround\z@$%
% \hbox{\lower\@tempdima\box\z@}
% $\endgroup%
% \ifnum\ltjgetparameter{alxspmode}{\@tempcntb}<2\hbox{}\fi
% \else
% \ifdim\@tempdima=\z@{\ltj@yablshift\z@ \ltj@tablshift\z@#1}%
% \else\lower\@tempdima\box\z@\fi
% \fi
% \endgroup}%
% \fi
% }
\endinput
|