OSDN Git Service

removed debug code
[luatex-ja/luatexja.git] / src / addons / luatexja-preset.sty
1 % luatexja-preset.sty
2 \ProvidesPackage{luatexja-preset}[2019/02/25 Japanese font presets]
3
4 \RequirePackage{expl3,l3keys2e}
5 \RequirePackage{luatexja}
6 \ExplSyntaxOn
7
8 %% messages
9 \msg_new:nnn { luatexja-preset }{ ltj-fontspec }{
10   The~ luatexja-fontspec~ package~ is~ loaded~ already.~
11   Hence~ we~ ignore~ `nfssonly'~option.
12 }
13 \msg_new:nnn { luatexja-preset }{ no-font }{
14   Font~ #1~ (#2)~ is~ not~found.~ Hence~ I~ substitute~ #3~ (#4)~ for~ it.
15 }
16 \msg_new:nnn { luatexja-preset }{ scale }{
17   Japanese~fonts~will~be~scaled~by~#1.
18 }
19
20 \msg_new:nnn { luatexja-preset }{ exist-preset-nooverwrite }{
21   The~ preset~ `#1'~ is~ already~ defined.~
22   To~ redefine~ this~ preset,~ use~ \str_use:N \c_backslash_str ltjnewpreset*~ instead.
23 }
24 \msg_new:nnn { luatexja-preset }{ exist-preset-overwrite }{
25   The~ preset~ `#1'~ is~ redefined.
26 }
27
28 \msg_new:nnn { luatexja-preset }{ illegal-preset-name }{
29   The~ preset~ `#1'~ cannot~ be~ defined,~
30   since~ the~ luatexja-preset~ package~ an~ option~ with~ the~ same~ name.
31 }
32
33 \seq_new:N \g__ltjpreset_presets_seq
34
35 \keys_define:nn { luatexja-preset }{
36   unknown .code:n =
37     \keys_set_known:noN { ltjpreset-presets } { \tl_use:N \l_keys_tl } \l_tmpa_tl
38     \tl_if_empty:NT \l_tmpa_tl {
39       \PassOptionsToPackage { \l_tmpa_tl } { luatexja-fontspec }
40     },
41   scale .code:n  = \gdef\Cjascale{#1},
42   match .code: n =
43     \renewcommand\jttdefault{\gtdefault}\@ltj@match@familytrue
44     \PassOptionsToPackage { match } { luatexja-fontspec },
45   match .value_forbidden:n = true,
46   __custom  .bool_set:N = \g__ltjpreset_custom_bool,  __custom  .groups:n = { preset },
47   __office  .bool_set:N = \g__ltjpreset_office_bool,  __office  .groups:n = { preset },
48   __noembed .bool_set:N = \g__ltjpreset_noembed_bool, __noembed .groups:n = { preset },
49 }
50 \cs_new:Nn \__ltjpreset_declare_option:nn {
51   \keys_define:nn { luatexja-preset }{
52     #1 .code:n = { #2 },
53     #1 .value_forbidden:n = true
54   }
55 }
56 \cs_new:Nn \ltjpreset_declare_preset:nn {
57   \keys_define:nn { luatexja-preset }{
58     #1 .meta:n = { #2 },
59     #1 .value_forbidden:n = true, #1 .groups:n = { preset },
60   }
61   \seq_put_right:Nn \g__ltjpreset_presets_seq { #1 }
62 }
63 \cs_generate_variant:Nn \ltjpreset_declare_preset:nn {nx}
64 \cs_new:Nn \__ltjpreset_declare_bool_option:nn {
65   \bool_new:c { g__ltjpreset_#1_bool }
66   \bool_set_false:c { g__ltjpreset_#1_bool }
67   \keys_define:nn { luatexja-preset }{
68     #1 .bool_set:c =  { g__ltjpreset_#1_bool },
69     #2 .bool_set_inverse:c =  { g__ltjpreset_#1_bool },
70     #1 .default:n =  true, #2 .default:n =  true,
71   }
72 }
73
74 %%%%%%%% bool options
75 \__ltjpreset_declare_bool_option:nn { nfssonly }{ fontspec }
76 \__ltjpreset_declare_bool_option:nn { bold }{ nobold }
77 \__ltjpreset_declare_bool_option:nn { expert }{ noexpert }
78 \__ltjpreset_declare_bool_option:nn { deluxe }{ nodeluxe }
79
80 % JFM
81 \tl_new:N \__ltjpreset_use_jfm_yoko_tl % 使用する JFM(横)
82 \tl_set:Nn \__ltjpreset_use_jfm_yoko_tl {\ltj@stdyokojfm}
83 \tl_new:N \__ltjpreset_use_jfm_tate_tl % 使用する JFM(縦)
84 \tl_set:Nn \__ltjpreset_use_jfm_tate_tl {\ltj@stdtatejfm}
85 \__ltjpreset_declare_option:nn{jis}{\tl_set:Nn  \__ltjpreset_use_jfm_yoko_tl {jis}}     % jis
86 \__ltjpreset_declare_option:nn{ujis}{\tl_set:Nn  \__ltjpreset_use_jfm_yoko_tl {ujis}}   % ujis
87
88 % 漢字字形
89 \tl_new:N \l__ltjpreset_kanji_shape_tl
90 \__ltjpreset_declare_option:nn{90jis}{  \tl_set:Nn \l__ltjpreset_kanji_shape_tl { , CJKShape=JIS1990 }} % 90jis
91 \__ltjpreset_declare_option:nn{jis90}{  \tl_set:Nn \l__ltjpreset_kanji_shape_tl { , CJKShape=JIS1990 }} % 90jis
92 \__ltjpreset_declare_option:nn{jis2004}{\tl_set:Nn \l__ltjpreset_kanji_shape_tl { , CJKShape=JIS2004 }} % jis2004
93 \__ltjpreset_declare_option:nn{2004jis}{\tl_set:Nn \l__ltjpreset_kanji_shape_tl { , CJKShape=JIS2004 }} % jis2004
94
95 % font preset
96 \prop_new:N \g__ltjpreset_font_prop
97 \keys_define:nn { luatexja-preset } {
98   mc .code:n =
99      \prop_put:Nnn \g__ltjpreset_font_prop { mc-l } {#1}
100      \prop_put:Nnn \g__ltjpreset_font_prop { mc-m } {#1}
101      \prop_put:Nnn \g__ltjpreset_font_prop { mc-bx } {#1},
102   mc .groups:n = { preset }, mc .value_required:n = true,
103   gt .code:n =
104      \prop_put:Nnn \g__ltjpreset_font_prop { gt-u } {#1}
105      \prop_put:Nnn \g__ltjpreset_font_prop { gt-d } {#1}
106      \prop_put:Nnn \g__ltjpreset_font_prop { gt-bx } {#1}
107      \prop_put:Nnn \g__ltjpreset_font_prop { gt-eb } {#1},
108   gt-m .code:n = % gtfamily , medium series
109      \prop_put:Nnn \g__ltjpreset_font_prop { gt-u } {#1}
110      \prop_put:Nnn \g__ltjpreset_font_prop { gt-d } {#1},
111   % gt-d, gt-u は隠し
112   gt .groups:n = { preset },   gt .value_required:n = true,
113   gt-m .groups:n = { preset }, gt-m .value_required:n = true,
114 }
115 \cs_set:Nn \ltjpreset_define_preset_prop:n {
116   \keys_define:nn { luatexja-preset } {
117     #1 .code:n = \prop_put:Non \g__ltjpreset_font_prop { #1 } { ##1 },
118     #1 .groups:n = { preset }, #1 .value_required:n = true,
119   }
120 }
121 \ltjpreset_define_preset_prop:n { mc-l }
122 \ltjpreset_define_preset_prop:n { mc-m }
123 \ltjpreset_define_preset_prop:n { mc-bx }
124 \ltjpreset_define_preset_prop:n { gt-u }
125 \ltjpreset_define_preset_prop:n { gt-d }
126 \ltjpreset_define_preset_prop:n { gt-bx }
127 \ltjpreset_define_preset_prop:n { gt-eb}
128 \ltjpreset_define_preset_prop:n { mg-m }
129
130 \cs_new:Nn \__ltjpreset_set_uni:nn {
131   mc = #1, gt = #2, mc-bx = #2, mg-m = #2,
132   __custom = false, __office = false, __noembed = false,
133 }
134 \cs_new:Npn \__ltjpreset_set_office:nn #1 #2{
135   mc   = #1,         mc-bx = HGMinchoE ,
136   gt-d = HGGothicM , gt-bx = HGGothicE ,
137   gt-u = #2 ,        gt-eb = HGSoeiKakugothicUB ,
138   mg-m = HGMaruGothicMPRO,
139   __custom = false, __office = true, __noembed = false,
140 }
141
142 %%%%%%%% プリセット達
143
144 % カスタム指定
145  \keys_define:nn { luatexja-preset }{
146     custom .meta:n = { #1, __custom = true, }, 
147     custom .value_required:n = true,
148     jfm_yoko .tl_set:N = \__ltjpreset_use_jfm_yoko_tl,
149     jfm_tate .tl_set:N = \__ltjpreset_use_jfm_tate_tl,
150 }
151
152 % 小塚 (Adobe)
153 %% Pro
154 \ltjpreset_declare_preset:nx{kozuka-pro}{
155     mc-m =  KozMinPro-Regular, mc-bx = KozMinPro-Bold,
156     gt-d =  KozGoPro-Regular,  gt-bx = KozGoPro-Bold,
157     gt-u =  KozGoPro-Medium,   gt-eb = KozGoPro-Heavy,
158     mg-m =  KozGoPro-Heavy,    mc-l =  KozMinPro-Light,
159     __custom = false, __office = false, __noembed = false,
160 }
161 %% Pr6
162 \ltjpreset_declare_preset:nx{kozuka-pr6}{
163     mc-m =  KozMinProVI-Regular, mc-bx = KozMinProVI-Bold,
164     gt-d =  KozGoProVI-Regular,  gt-bx = KozGoProVI-Bold,
165     gt-u =  KozGoProVI-Medium,   gt-eb = KozGoProVI-Heavy,
166     mg-m =  KozGoProVI-Heavy,    mc-l =  KozMinProVI-Light,
167     __custom = false, __office = false, __noembed = false,
168 }
169 %% Pr6N
170 \ltjpreset_declare_preset:nx{kozuka-pr6n}{
171     mc-m =  KozMinPr6N-Regular, mc-bx = KozMinPr6N-Bold,
172     gt-d =  KozGoPr6N-Regular,  gt-bx = KozGoPr6N-Bold,
173     gt-u =  KozGoPr6N-Medium,   gt-eb = KozGoPr6N-Heavy,
174     mg-m =  KozGoPr6N-Heavy,    mc-l =  KozMinPr6N-Light,
175     __custom = false, __office = false, __noembed = false,
176 }
177
178 % ヒラギノ (OSX)
179 \ltjpreset_declare_preset:nx{hiragino-pro}{
180     mc-m = HiraMinPro-W3,  mc-bx = HiraMinPro-W6,
181     gt-d = HiraKakuPro-W3, gt-bx = HiraKakuPro-W6,
182     gt-u = HiraKakuPro-W6, gt-eb = HiraKakuStd-W8,
183     mg-m = HiraMaruPro-W4, mc-l =  HiraMinPro-W2,
184     __custom = false, __office = false, __noembed = false,
185 }
186 \ltjpreset_declare_preset:nx{hiragino-pron}{
187     mc-m = HiraMinProN-W3,  mc-bx = HiraMinProN-W6,
188     gt-d = HiraKakuProN-W3, gt-bx = HiraKakuProN-W6,
189     gt-u = HiraKakuProN-W6, gt-eb = HiraKakuStdN-W8,
190     mg-m = HiraMaruProN-W4, mc-l =  HiraMinProN-W2,
191     __custom = false, __office = false, __noembed = false,
192 }
193
194 % モリサワ
195 \ltjpreset_declare_preset:nx{morisawa-pro}{
196     mc =   A-OTF-RyuminPro-Light.otf,      mc-bx = A-OTF-FutoMinA101Pro-Bold.otf,
197     gt-d = A-OTF-GothicBBBPro-Medium.otf , gt-bx = A-OTF-FutoGoB101Pro-Bold.otf,
198     gt-u = A-OTF-GothicBBBPro-Medium.otf , gt-eb = A-OTF-MidashiGoPro-MB31.otf,
199     mg-m = A-OTF-Jun101Pro-Light.otf,
200     __custom = false, __office = false, __noembed = false,
201 }
202 \ltjpreset_declare_preset:nx{morisawa-pr6n}{
203     mc =   A-OTF-RyuminPr6N-Light.otf,      mc-bx = A-OTF-FutoMinA101Pr6N-Bold.otf,
204     gt-d = A-OTF-GothicBBBPr6N-Medium.otf , gt-bx = A-OTF-FutoGoB101Pr6N-Bold.otf,
205     gt-u = A-OTF-GothicBBBPr6N-Medium.otf , gt-eb = A-OTF-MidashiGoPr6N-MB31.otf,
206     mg-m = A-OTF-Jun101Pr6N-Light.otf,
207     __custom = false, __office = false, __noembed = false,
208 }
209
210 % 游明朝/游ゴシック (Win8.1)
211 \ltjpreset_declare_preset:nx{yu-win}{
212     mc-m = YuMincho-Regular, mc-bx = YuMincho-Demibold,
213     gt-d = YuGothic-Regular, gt-bx = YuGothic-Bold,
214     gt-u = YuGothic-Regular, gt-eb = YuGothic-Bold,
215     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light,
216     __custom = false, __office = false, __noembed = false,
217 }
218 % Win10
219 \ltjpreset_declare_preset:nx{yu-win10}{
220     mc-m = YuMincho-Regular, mc-bx = YuMincho-Demibold,
221     gt-d = YuGothic-Regular, gt-bx = YuGothic-Bold,
222     gt-u = YuGothic-Medium,  gt-eb = YuGothic-Bold,
223     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light,
224     __custom = false, __office = false, __noembed = false,
225 }
226
227 % Yu fonts in OSX
228 % according to http://support.apple.com/kb/HT5944
229 \ltjpreset_declare_preset:nx{yu-osx}{
230     mc =  YuMincho~Medium, mc-bx = YuMincho~Demibold,
231     gt-d =  YuGothic~Medium, gt-u =  YuGothic~Medium,
232     gt-bx = YuGothic~Bold,   gt-eb = YuGothic~Bold,
233     mg-m =  YuGothic~Bold,
234     __custom = false, __office = false, __noembed = false,
235 }
236
237 % moga-mobo
238 \ltjpreset_declare_preset:nx{moga-mobo}{
239     mc =   Moga90Mincho, mc-bx = Moga90Mincho~Bold,
240     gt-d = Moga90Gothic, gt-bx = Moga90Gothic~Bold,
241     gt-u = Moga90Gothic, gt-eb = Moga90Gothic~Bold,
242     mg-m = Mobo90Gothic,
243     __custom = false, __office = false, __noembed = false,
244 }
245 \ltjpreset_declare_preset:nx{moga-mobo-ex}{
246     mc =   MogaEx90Mincho, mc-bx = MogaEx90Mincho~Bold,
247     gt-d = MogaEx90Gothic, gt-bx = MogaEx90Gothic~Bold,
248     gt-u = MogaEx90Gothic, gt-eb = MogaEx90Gothic~Bold,
249     mg-m = MoboEx90Gothic,
250     __custom = false, __office = false, __noembed = false,
251 }
252
253 % Ume fones
254 \ltjpreset_declare_preset:nx{ume}{
255     mc = Ume~Mincho,
256     gt-d = Ume~Gothic,    gt-bx = Ume~Gothic~O5,
257     gt-u = Ume~Gothic~O5, gt-eb = Ume~Gothic~O5,
258     mg-m = Ume~Gothic~O4,
259     __custom = false, __office = false, __noembed = false,
260 }
261
262 % Source Han {Serif,Sans}
263 \ltjpreset_declare_preset:nx{sourcehan}{
264     mc-m =  Source~Han~Serif~Regular,
265     mc-bx = Source~Han~Serif~Bold,
266     gt-d =  Source~Han~Sans~Regular,
267     gt-bx = Source~Han~Sans~Bold,
268     gt-u =  Source~Han~Sans~Medium,
269     gt-eb = Source~Han~Sans~Heavy,
270     mg-m =  Source~Han~Sans~Heavy,
271     mc-l =  Source~Han~Serif~Light,
272     __custom = false, __office = false, __noembed = false,
273 }
274 \ltjpreset_declare_preset:nx{sourcehan-jp}{
275     mc-m =  Source~Han~Serif~JP~Regular,
276     mc-bx = Source~Han~Serif~JP~Bold,
277     gt-d =  Source~Han~Sans~JP~Regular,
278     gt-bx = Source~Han~Sans~JP~Bold,
279     gt-u =  Source~Han~Sans~JP~Medium,
280     gt-eb = Source~Han~Sans~JP~Heavy,
281     mg-m =  Source~Han~Sans~JP~Heavy,
282     mc-l =  Source~Han~Serif~JP~Light,
283     __custom = false, __office = false, __noembed = false,
284 }
285 \ltjpreset_declare_preset:nx{noto-otc}{
286     mc-m =  Noto~Serif~CJK~Regular,
287     mc-bx = Noto~Serif~CJK~Bold,
288     gt-d =  Noto~Sans~CJK~Regular,
289     gt-bx = Noto~Sans~CJK~Bold,
290     gt-u =  Noto~Sans~CJK~Medium,
291     gt-eb = Noto~Sans~CJK~Black,
292     mg-m =  Noto~Sans~CJK~Black,
293     mc-l =  Noto~Serif~CJK~Light,
294     __custom = false, __office = false, __noembed = false,
295 }
296 \ltjpreset_declare_preset:nx{noto-otf}{
297     mc-m =  Noto~Serif~CJK~JP~Regular,
298     mc-bx = Noto~Serif~CJK~JP~Bold,
299     gt-d =  Noto~Sans~CJK~JP~Regular,
300     gt-bx = Noto~Sans~CJK~JP~Bold,
301     gt-u =  Noto~Sans~CJK~JP~Medium,
302     gt-eb = Noto~Sans~CJK~JP~Black,
303     mg-m =  Noto~Sans~CJK~JP~Black,
304     mc-l =  Noto~Serif~CJK~JP~Light,
305     __custom = false, __office = false, __noembed = false,
306 }
307
308
309 % ipa, ipaex, ms
310 \ltjpreset_declare_preset:nx{ipa}{
311   \__ltjpreset_set_uni:nn { IPAMincho } { IPAGothic }
312 }
313 \ltjpreset_declare_preset:nx{ipaex}{
314   \__ltjpreset_set_uni:nn { IPAExMincho } { IPAExGothic }
315 }
316 \ltjpreset_declare_preset:nx{ms}{
317   \__ltjpreset_set_uni:nn { MS-Mincho } { MS-Gothic }
318 }
319
320 % {ipa,ipaex,ms}-dx % Office 付属フォントを利用
321 \ltjpreset_declare_preset:nx{ipaex-hg}{
322   \__ltjpreset_set_office:nn { IPAExMincho } { IPAExGothic }
323 }
324 \ltjpreset_declare_preset:nx{ipa-hg}{
325   \__ltjpreset_set_office:nn { IPAMincho } { IPAGothic }
326 }
327 \ltjpreset_declare_preset:nx{ms-hg}{
328   \__ltjpreset_set_office:nn { MS-Mincho } { MS-Gothic }
329 }
330
331
332 % 非埋込
333 \ltjpreset_declare_preset:nx{noembed}{
334   \__ltjpreset_set_uni:nn { Ryumin-Light } { GothicBBB-Medium },
335   __custom = false, __office = false, __noembed = true,
336 }
337
338 \keys_set:nn {luatexja-preset} { ipaex }
339 \ProcessKeysOptions { luatexja-preset }
340 \@ifpackageloaded{luatexja-fontspec}{
341   \bool_if:NT \g__ltjpreset_nfssonly_bool
342     { \msg_warning:nn { luatexja-preset }{ ltj-fontspec } }
343   \bool_set_false:N \g__ltjpreset_nfssonly_bool
344 }{}
345
346 %%%%%%%% main routine
347
348 \cs_new:Nn \__ltjpreset_extract_fonts: {
349   %% MogaMincho の場合は 90 をつける/はずす
350   \bool_if:NF \g__ltjpreset_custom_bool {
351     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
352     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
353       \tl_set:Nx \l_tmpb_tl { \prop_item:Nn \g__ltjpreset_font_prop { mc-m } }
354       \tl_if_in:NnT  \l_tmpb_tl { Moga90Mincho } {
355         \prop_clear:N \l_tmpa_prop
356         \prop_map_inline:Nn \g__ltjpreset_font_prop {
357            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
358           \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
359          } 
360          \prop_set_eq:NN \g__ltjpreset_font_prop \l_tmpa_prop
361        }
362        \tl_if_in:NnT  \l_tmpb_tl { MogaEx90Mincho } {
363          \prop_clear:N \l_tmpa_prop
364          \prop_map_inline:Nn \g__ltjpreset_font_prop {
365            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
366            \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
367          }
368          \prop_set_eq:NN \g__ltjpreset_font_prop \l_tmpa_prop
369        }
370     }
371   }
372   %%%%  リストからの展開
373   \cs_set:Nx \__ltjpreset_font_mc_l:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-l } }
374   \cs_set:Nx \__ltjpreset_font_mc_m:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-m } }
375   \cs_set:Nx \__ltjpreset_font_mc_bx: { \prop_item:Nn \g__ltjpreset_font_prop { mc-bx } }
376   \cs_set:Nx \__ltjpreset_font_gt_m:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-d } }
377   \cs_set:Nx \__ltjpreset_font_gt_u:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-u } }
378   \cs_set:Nx \__ltjpreset_font_gt_bx: { \prop_item:Nn \g__ltjpreset_font_prop { gt-bx } }
379   \cs_set:Nx \__ltjpreset_font_gt_eb: { \prop_item:Nn \g__ltjpreset_font_prop { gt-eb } }
380   \cs_set:Nx \__ltjpreset_font_mg_m:  { \prop_item:Nn \g__ltjpreset_font_prop { mg-m } }
381   %% HG 系フォント + JIS2004/90JIS のときはフォント名を置換
382   \bool_if:nT { !\g__ltjpreset_custom_bool && \g__ltjpreset_office_bool } {
383     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
384     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
385       \cs_set:Nx \__ltjpreset_font_mc_bx: { hgrme04.ttc }
386       \cs_set:Nx \__ltjpreset_font_gt_bx: { hgrge04.ttc }
387       \cs_set:Nx \__ltjpreset_font_gt_eb: { hgrsgu04.ttc }
388       \cs_set:Nx \__ltjpreset_font_mg_m:  { hgrsmp04.ttf }
389       \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_u:
390       % HG ゴシックM のときはそうはいかないので 1 ウェイト時のゴシック体を使う
391     }
392     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
393     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
394       \cs_set:Nx \__ltjpreset_font_mc_bx: { hgrme.ttc }
395       \cs_set:Nx \__ltjpreset_font_gt_bx: { hgrge.ttc }
396       \cs_set:Nx \__ltjpreset_font_gt_eb: { hgrsgu.ttc }
397       \cs_set:Nx \__ltjpreset_font_mg_m:  { hgrsmp.ttf }
398     }
399   }
400   % mc/l
401   \tl_set:Nx \l_tmpa_tl { \__ltjpreset_font_mc_l: }
402   \tl_if_empty:NT \l_tmpa_tl {\tl_set:Nn \l_tmpa_tl {~}}
403   \cs_set:Nx \__ltjpreset_font_mc_l: {
404     \tl_if_blank:nTF \l_tmpa_tl { \__ltjpreset_font_mc_m: } {\tl_use:N \l_tmpa_tl }
405   }
406   %% bold オプションの処理
407   \bool_if:NTF \g__ltjpreset_deluxe_bool {
408     \bool_if:NT \g__ltjpreset_bold_bool {
409       \cs_set_eq:NN \__ltjpreset_font_mc_bx: \__ltjpreset_font_gt_bx:
410     }
411   }{
412     \bool_if:NTF \g__ltjpreset_bold_bool
413       { \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_bx: }
414       { \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_u: }
415     \cs_set_eq:NN \__ltjpreset_font_gt_bx: \__ltjpreset_font_gt_m:
416     \cs_set_eq:NN \__ltjpreset_font_mc_bx: \__ltjpreset_font_gt_m:
417   }
418 }
419
420 %%%%%%%% 存在判定
421 \cs_new:Nn \__ltjpreset_substitute:nnnn {
422   \group_begin:
423     \suppressfontnotfounderror=1
424     \cs_if_exist:cT {ltjpreset_font_#1_#2:} {
425       \font \g__ltjpreset_font_test: = "\cs:w ltjpreset_font_#1_#2: \cs_end:"\relax
426       \ifx \g__ltjpreset_font_test: \nullfont
427         \msg_warning:nnxxxx { luatexja-preset }{ no-font }
428           { \cs:w ltjpreset_font_#1_#2: \cs_end: }{ #1/#2 }
429           { \cs:w ltjpreset_font_#3_#4: \cs_end: }{ #3/#4 }
430         \cs_gset_eq:cc { ltjpreset_font_#1_#2: } { ltjpreset_font_#3_#4: }
431       \fi
432     } { \cs_gset_eq:cc { ltjpreset_font_#1_#2: } { ltjpreset_font_#3_#4: } }
433   \group_end:
434 }
435
436 %%%%%%%% deluxe (\mgfamily はあとで定義)
437 \bool_if:NTF \g__ltjpreset_deluxe_bool {
438   \cs_new:Nn \__ltjpreset_check_deluxe_existence: {
439     \__ltjpreset_substitute:nnnn { gt } { eb } { gt } { bx }
440     \__ltjpreset_substitute:nnnn { mg } { m  } { gt } { bx }
441     \__ltjpreset_substitute:nnnn { mc } { l  } { mc } { m  }
442   }
443   \def\ltdefault{l}
444   \DeclareRobustCommand\ltseries { \not@math@alphabet\ltseries\relax\fontseries\ltdefault\selectfont }
445   \def\ebdefault{eb}
446   \DeclareRobustCommand\ebseries { \not@math@alphabet\ebseries\relax\fontseries\ebdefault\selectfont }
447   \DeclareRobustCommand\gtebfamily { \gtfamily\fontseries{\ebdefault}\selectfont }
448 } {
449   \cs_set_eq:NN \__ltjpreset_check_deluxe_existence: \prg_do_nothing:
450 }
451
452 \int_new:N \g__ltjpreset_applycount_int
453
454 \bool_if:NTF \g__ltjpreset_nfssonly_bool {
455 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 %%%%%%%% nfss only
457   \cs_if_exist:NF \Cjascale {
458     \group_begin:
459     \fontsize{16}{16}\selectfont
460     \cs_gset:Npx \Cjascale { \fp_to_decimal:n {\zw / 16} }
461     \group_end:
462   }
463
464   \msg_warning:nnx { luatexja-preset }{ scale }{ \Cjascale }
465
466   % {1: encoding}{2: family}{3: series}{4: shape}{5: fontname}{6: feature}{7: scale}
467   \cs_new:Nn \__ltjpreset_declare_font_shape:nnnnnnn {
468     \DeclareFontShape{#1}{#2}{#3}{#4}{ <-> s*[#7]
469       \bool_if:NT \g__ltjpreset_noembed_bool {psft:} #5
470       ;-kern \tl_use:N \l__ltjpreset_kanji_shape_tl; #6 } {}
471   }
472   \cs_new:Nn \__ltjpreset_define_family:nnn {
473     \__ltjpreset_declare_font_shape:nnnnnnn { JY3 }
474       { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { n }
475       { "#3" : jfm=\tl_use:N \__ltjpreset_use_jfm_yoko_tl }
476       { script=hani \bool_if:NT \g__ltjpreset_expert_bool { ;+hkna } }
477           { \Cjascale }
478     \__ltjpreset_declare_font_shape:nnnnnnn { JT3 }
479       { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { n }
480       { "#3" : jfm=\tl_use:N \__ltjpreset_use_jfm_tate_tl }
481       { script=hani \bool_if:NT \g__ltjpreset_expert_bool { ;+vkna } }
482           { \Cjascale }
483     \bool_if:NT \g__ltjpreset_expert_bool {
484       \__ltjpreset_declare_font_shape:nnnnnnn { JY3 }
485         { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { rb }
486         { "#3" : jfm=\tl_use:N \__ltjpreset_use_jfm_yoko_tl } { script=kana; +ruby }
487             { \Cjascale }
488       \__ltjpreset_declare_font_shape:nnnnnnn { JT3 }
489         { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { rb }
490         { "#3" : jfm=\tl_use:N \__ltjpreset_use_jfm_tate_tl } { script=kana; +ruby }
491             { \Cjascale }
492     }
493     \cs_if_exist:NT \ltjpreset_define_family_hook_nfssonly:nnn
494       { \ltjpreset_define_family_hook_nfssonly:nnn { #1 } { #2 } { #3 } }
495   }
496   \bool_if:NT \g__ltjpreset_deluxe_bool {
497     \let\mgfamily\undefined
498     \DeclareRobustCommand\mgfamily {
499       \not@math@alphabet\mgfamily\relax
500       \kanjifamily{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}\selectfont
501     }
502     \DeclareTextFontCommand{\textmg}{\mgfamily}
503   }
504   \bool_if:NT \g__ltjpreset_expert_bool {
505     \DeclareRobustCommand\rubyfamily { \kanjishape{rb}\selectfont }
506   }
507   %
508   \cs_new:Nn \__ltjpreset_do_fontset: { \group_begin:
509     % ======
510     \xdef\mcdefault{ltjpmc \int_to_arabic:n { \g__ltjpreset_applycount_int }}
511     \xdef\gtdefault{ltjpgt \int_to_arabic:n { \g__ltjpreset_applycount_int }}
512     \DeclareKanjiFamily{JY3}{\mcdefault}{}
513     \DeclareKanjiFamily{JT3}{\mcdefault}{}
514     \DeclareKanjiFamily{JY3}{\gtdefault}{}
515     \DeclareKanjiFamily{JT3}{\gtdefault}{}
516     \unless\ifltj@disablejfam
517       \SetSymbolFont{mincho}{normal}{JY3}{\mcdefault}{m}{n}
518       \SetSymbolFont{mincho}{bold}{JY3}{\mcdefault}{bx}{n}
519       \DeclareMathAlphabet{\mathgt}{JY3}{\gtdefault}{m}{n}
520     \fi
521     \bool_if:NT \g__ltjpreset_deluxe_bool {
522       \DeclareKanjiFamily{JY3}{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}{}
523       \DeclareKanjiFamily{JT3}{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}{}
524     }
525     % ======
526     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
527     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
528       \tl_set:Nn \l__ltjpreset_kanji_shape_tl { ;+jp90 }
529     }
530     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
531     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
532       \tl_set:Nx \l__ltjpreset_kanji_shape_tl { ;+jp04 }
533     }
534     \__ltjpreset_define_family:nnn {mc} {m}  {\__ltjpreset_font_mc_m:}
535     \__ltjpreset_define_family:nnn {mc} {bx} {\__ltjpreset_font_mc_bx:}
536     \__ltjpreset_define_family:nnn {mc} {b}  {\__ltjpreset_font_mc_bx:}
537     \__ltjpreset_define_family:nnn {gt} {m}  {\__ltjpreset_font_gt_m:}
538     \__ltjpreset_define_family:nnn {gt} {bx} {\__ltjpreset_font_gt_bx:}
539     \__ltjpreset_define_family:nnn {gt} {b}  {\__ltjpreset_font_gt_bx:}
540     \normalfont
541     \bool_if:NT \g__ltjpreset_deluxe_bool {
542       \__ltjpreset_define_family:nnn {mc}  {l} {\__ltjpreset_font_mc_l:}
543       \__ltjpreset_define_family:nnn {gt}  {eb} {\__ltjpreset_font_gt_eb:}
544       \__ltjpreset_define_family:nnn {mg} {m}  {\__ltjpreset_font_mg_m:}
545     }
546     \group_end:
547   }
548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
549 %%%%%%%% fontspec
550 } {
551   \RequirePackage{luatexja-fontspec}
552   % scale
553   \msg_warning:nnx { luatexja-preset }{ scale }{ \Cjascale }
554   \tl_new:N \l__ltjpreset_add_features_tl
555
556   \bool_if:NT \g__ltjpreset_expert_bool {
557     \cs_set:Npn \rubyfamily { \addjfontfeatures {
558       Style=Ruby , YokoFeatures={RawFeature=-hkna} , TateFeatures={RawFeature=-vkna}
559     } }
560   }
561   \addjfontfeature{ Kerning=Off }
562   % 実際の fontspec の呼びだし
563   \cs_new:Nn \__ltjpreset_do_fontset: { \group_begin:
564       \tl_gset:Nx \l__ltjpreset_add_features_tl {
565         \tl_use:N \l__ltjpreset_kanji_shape_tl,
566         YokoFeatures = { JFM = \tl_use:N \__ltjpreset_use_jfm_yoko_tl },
567         TateFeatures = { JFM = \tl_use:N \__ltjpreset_use_jfm_tate_tl },
568         Script=CJK, \bool_if:NT \g__ltjpreset_noembed_bool { , NoEmbed }
569       }
570     \group_end:
571     \bool_if:NT \g__ltjpreset_expert_bool {
572       \tl_put_left:Nn \l__ltjpreset_add_features_tl {
573         , YokoFeatures = {Style = HorizontalKana}, TateFeatures = {Style = VerticalKana}
574       }
575     }
576     \setmainjfont [
577       \bool_if:NT \g__ltjpreset_deluxe_bool {
578             FontFace={l}{n}{ Font = \__ltjpreset_font_mc_l:,
579           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
580             \ltjpreset_define_family_hook_fontspec:nnn
581                           { mc } { l } { \__ltjpreset_font_mc_l: }
582               }
583                 },
584           }
585       BoldFont = \__ltjpreset_font_mc_bx: \tl_use:N \l__ltjpreset_add_features_tl,
586       \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
587                 UprightFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
588                   { mc } { m } { \__ltjpreset_font_mc_m: } },
589                 BoldFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
590                   { mc } { bx } { \__ltjpreset_font_mc_bx: } },
591           }
592     ] { \__ltjpreset_font_mc_m: }
593     \setsansjfont [
594       \bool_if:NT \g__ltjpreset_deluxe_bool {
595                 FontFace={eb}{n}{ Font = \__ltjpreset_font_gt_eb:,
596           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
597             \ltjpreset_define_family_hook_fontspec:nnn
598                           { gt } { eb } { \__ltjpreset_font_gt_eb: }
599               }
600             },
601           }
602       BoldFont = \__ltjpreset_font_gt_bx: \tl_use:N \l__ltjpreset_add_features_tl,
603       \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
604                 UprightFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
605                   { gt } { m } { \__ltjpreset_font_gt_m: } },
606                 BoldFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
607                   { gt } { bx } { \__ltjpreset_font_gt_bx: } },
608           }
609     ] { \__ltjpreset_font_gt_m: }
610     \bool_if:NT \g__ltjpreset_deluxe_bool {
611       %% mg
612       \bool_if_exist:NTF \setfontfamily {
613         \setjfontfamily \mgfamily [
614           BoldFont = \__ltjpreset_font_mg_m: \tl_use:N \l__ltjpreset_add_features_tl,
615           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
616                     \ltjpreset_define_family_hook_fontspec:nnn
617                       { mg } { m } { \__ltjpreset_font_mg_m: },
618           }
619         ] { \__ltjpreset_font_mg_m: }
620       } {
621         \newjfontfamily \mgfamily [
622           BoldFont = \__ltjpreset_font_mg_m: \tl_use:N \l__ltjpreset_add_features_tl,
623           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
624                     \ltjpreset_define_family_hook_fontspec:nnn
625                       { mg } { m } { \__ltjpreset_font_mg_m: },
626           }
627         ] { \__ltjpreset_font_mg_m: }
628       }
629       \DeclareTextFontCommand{\textmg}{\mgfamily}
630     }
631   }
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
633 }
634
635 \def\ltjnewpreset{
636     \@ifstar{\__ltjpreset_new_preset:nnn{ true }}{\__ltjpreset_new_preset:nnn{ false }}}
637 \cs_set:Nn \__ltjpreset_new_preset:nnn {
638   \keys_if_exist:nnTF { luatexja-preset } { #2 } {
639     \seq_if_in:NnTF \g__ltjpreset_presets_seq { #2 } {
640       \bool_if:cTF { c_ #1 _bool } {
641         \msg_warning:nnn { luatexja-preset }{ exist-preset-overwrite } { #2 }
642         \keys_define:nn { luatexja-preset } {
643         #2 .meta:n = { #3, __custom = true, __noembed = false, __office = false, },
644         #2 .value_forbidden:n = true, #2 .groups:n = { preset },
645         }
646       } {
647         \msg_error:nnn { luatexja-preset }{ exist-preset-nooverwrite } { #2 }
648       }
649     } {
650       \msg_error:nnn { luatexja-preset }{ illegal-preset-name } { #2 }
651     }
652   } {
653     \keys_define:nn { luatexja-preset } {
654       #2 .meta:n = { #3, __custom = true, __noembed = false, __office = false, },
655       #2 .value_forbidden:n = true, #2 .groups:n = { preset },
656     }
657     \seq_put_right:Nn \g__ltjpreset_presets_seq { #2 }
658   }
659 }
660
661
662 \cs_set:Npn \ltjapplypreset #1 {
663   \int_gincr:N \g__ltjpreset_applycount_int
664   \keys_set_groups:nnn { luatexja-preset } { preset } { #1 }
665   % \prop_map_inline:Nn \g__ltjpreset_font_prop {\typeout{ [##1] = "##2" } }
666   \__ltjpreset_extract_fonts:
667   \__ltjpreset_check_deluxe_existence:
668   \__ltjpreset_do_fontset:
669   \normalfont
670 }
671
672 \ltjapplypreset {}
673
674 \@onlypreamble\ltjnewpreset
675 \@onlypreamble\ltjapplypreset
676
677 \ExplSyntaxOff
678
679 \endinput