OSDN Git Service

Fix ticket #36913
[luatex-ja/luatexja.git] / src / addons / luatexja-adjust.sty
1 %
2 % luatexja-adjust.sty
3 %
4
5 %% Avoid multiple loading.
6 \csname\if11luatexjaadjustLoaded\fi\endcsname
7 \edef\x{%
8 \catcode32=\the\catcode32%
9 \catcode33=\the\catcode33%
10 \catcode35=\the\catcode35%
11 \catcode40=\the\catcode40%
12 \catcode41=\the\catcode41%
13 \catcode42=\the\catcode42%
14 \catcode43=\the\catcode43%
15 \catcode44=\the\catcode44%
16 \catcode45=\the\catcode45%
17 \catcode46=\the\catcode46%
18 \catcode58=\the\catcode58%
19 \catcode59=\the\catcode59%
20 \catcode60=\the\catcode60%
21 \catcode61=\the\catcode61%
22 \catcode62=\the\catcode62%
23 \catcode64=\the\catcode64%
24 \catcode91=\the\catcode91%
25 \catcode93=\the\catcode93%
26 \catcode94=\the\catcode94%
27 \catcode95=\the\catcode95%
28 \catcode126=\the\catcode126%
29 \endlinechar=\the\endlinechar
30 \relax}
31 \catcode32=10 %< >
32 \catcode33=12 %<">
33 \catcode35=6  %<#>
34 \catcode40=12 %<(>
35 \catcode41=12 %<)>
36 \catcode42=12 %<*>
37 \catcode43=12 %<+>
38 \catcode44=12 %<,>
39 \catcode45=12 %<->
40 \catcode46=12 %<.>
41 \catcode58=12 %<:>
42 \catcode59=12 %<;>
43 \catcode60=12 %<<>
44 \catcode61=12 %<=>
45 \catcode62=12 %<>>
46 \catcode64=11 %<@>
47 \catcode91=12 %<[>
48 \catcode93=12 %<]>
49 \catcode94=7  %<^>
50 \catcode95=8  %<_>
51 \catcode126=13 %<~>
52 \endlinechar=-1 %
53
54 \edef\ltj@adjust@AtEnd{\x
55   \noexpand\let\noexpand\ltj@adjust@AtEnd\relax}
56 \def\luatexjaadjustLoaded{\endinput}
57
58 %% Check if LaTeX is used.
59 \begingroup\expandafter\expandafter\expandafter\endgroup
60 \expandafter\ifx\csname RequirePackage\endcsname\relax %<*!LaTeX>
61   \expandafter\let\csname ifltj@in@latex\expandafter\endcsname
62     \csname iffalse\endcsname
63 \else                           %<*LaTeX>
64   \expandafter\let\csname ifltj@in@latex\expandafter\endcsname
65     \csname iftrue\endcsname
66   \NeedsTeXFormat{LaTeX2e}
67   \ProvidesPackage{luatexja-adjust}[2016/05/15]
68 \fi                             %</LaTeX>
69
70 % Load core module if not yet.
71 % xkeyval.sty is already required in luatexja.sty.
72 \ifx\luatexjacoreLoaded\@undefined
73   \ifltj@in@latex                 %<*LaTeX>
74     \RequirePackage{luatexja}[2016/05/15]
75   \else                           %<*!LaTeX>
76     \input luatexja.sty %
77   \fi                             %</LaTeX>
78 \fi
79
80 %% When environment check fails, exit now.
81 \ifx\LuaTeXjaAvailable\@undefined
82   \ltj@otf@AtEnd
83 \expandafter\endinput\fi\relax
84
85 %%------------------
86
87 %! Main part of luatexja-adjust
88 \ifnum\luatexversion>90
89   \RequireLuaTeXjaSubmodule{adjust}
90 \else
91   \RequireLuaTeXjaSubmodule{adjust_85}
92 \fi
93
94
95 \newcount\ltjadj@status@le
96 \newcount\ltjadj@status@pr
97 \let\ltj@adjust@temp=\relax
98 \define@choicekey[ltj]{adjust}{lineend}[\@@temp\ltj@adjust@temp]%
99 {false,true,extended}[true]{%
100   \ifnum\ltj@adjust@temp=-1 \else\ltjadj@status@le=\ltj@adjust@temp\fi\relax}
101 \define@boolkey[ltj]{adjust}{priority}[true]{%
102   \ltjadj@status@pr=\ifltj@adjust@priority1\else0\fi\relax}
103 \protected\def\@@ltjenableadjust[#1]{%
104    \setkeys[ltj]{adjust}{#1}%
105    \directlua{luatexja.adjust.enable_cb(\the\ltjadj@status@le, \the\ltjadj@status@pr)}\ignorespaces
106 }
107 \protected\def\ltjdisableadjust{\ltjenableadjust[lineend=false,priority=false]}
108 \protected\def\ltjenableadjust{%
109    \ltx@ifnextchar[{\@@ltjenableadjust}{\@@ltjenableadjust[lineend,priority]}}%]
110
111 \ltjenableadjust
112
113 %%% 優先順位の設定
114 \define@key[ltj]{adjpri}{kanjiskip}{%
115   \directlua{luatexja.adjust.priority_table[\the\count@][1] = token.scan_int()}#1\relax}
116 \define@key[ltj]{adjpri}{xkanjiskip}{%
117   \directlua{luatexja.adjust.priority_table[\the\count@][2] = token.scan_int()}#1\relax}
118 \define@key[ltj]{adjpri}{others}{%
119   \directlua{luatexja.adjust.priority_table[\the\count@][3] = token.scan_int()}#1\relax}
120 \define@key[ltj]{japaram}{stretch_priority}{%
121   \begingroup\count@=1 \setkeys[ltj]{adjpri}{#1}\relax
122   \directlua{luatexja.adjust.make_priority_table(1)}\endgroup}
123 \define@key[ltj]{japaram}{shrink_priority}{%
124   \begingroup\count@=2 \setkeys[ltj]{adjpri}{#1}\relax
125   \directlua{luatexja.adjust.make_priority_table(2)}\endgroup}
126 \ltjsetparameter{%
127   stretch_priority={kanjiskip=-35, xkanjiskip=-25, others=50},
128    shrink_priority={kanjiskip=-35, xkanjiskip=-25, others=50},
129 }
130
131
132 %%------------------ all done
133 \ltj@adjust@AtEnd
134 \endinput
135 %% EOF