OSDN Git Service

luatexja-preset: trying to add \ltjnewpreset (however, THIS PACKAGE does not work)
[luatex-ja/luatexja.git] / src / addons / luatexja-preset.sty
1 % luatexja-preset.sty
2 \ProvidesPackage{luatexja-preset}[2017/08/17 Japanese font presets]
3
4 \RequirePackage{expl3,l3keys2e}
5 \RequirePackage{luatexja}
6 \ExplSyntaxOn
7
8 \fp_new:N \l_ltjpreset_scale_fp
9 \group_begin:
10 \fontsize{10}{10}\selectfont
11 \fp_gset:Nn \l_ltjpreset_scale_fp {\zw / 10}
12 \group_end:
13
14 %% messages
15 \msg_new:nnn { luatexja-preset }{ ltj-fontspec }{
16   The~ luatexja-fontspec~ package~ is~ loaded~ already.~
17   Hence~ we~ ignore~ `nfssonly'~option.
18 }
19 \msg_new:nnn { luatexja-preset }{ no-font }{
20   Font~ #1~ (#2)~ is~ not~found.~ Hence~ I~ substitute~ #3~ (#4)~ for~ it.
21 }
22 \msg_new:nnn { luatexja-preset }{ scale }{
23   Japanese~fonts~will~be~scaled~by~#1.
24 }
25
26 %% keys are diveded into three categories:
27 %% <preset>  : \usepackage[], \ltjnewpreset
28 %% <fontface>:                \ltjnewpreset, custom
29 %% (no group): \usepackage[]
30 \keys_define:nn { luatexja-preset }{
31   unknown .code:n =
32     \keys_set_known:noN { ltjpreset-presets } { \tl_use:N \l_keys_tl } \l_tmpa_tl
33     \tl_if_empty:NT \l_tmpa_tl {
34       \PassOptionsToPackage { \l_tmpa_tl } { luatexja-fontspec }
35     },
36   scale .fp_gset:N = \l_ltjpreset_scale_fp,
37   match .code: n =
38     \renewcommand\jttdefault{\gtdefault}\@ltj@match@familytrue
39     \PassOptionsToPackage { match } { luatexja-fontspec },
40   match .value_forbidden:n = true
41 }
42 \cs_new:Nn \ltjpreset_declare_option:nn {
43   \keys_define:nn { luatexja-preset }{
44     #1 .code:n = { #2 },
45     #1 .value_forbidden:n = true
46   }
47 }
48 \cs_new:Nn \ltjpreset_declare_preset:nn {
49   \keys_define:nn { ltjpreset-presets }{
50     #1 .code:n = { #2 },
51     #1 .value_forbidden:n = true,
52   }
53 }
54 \cs_new:Nn \ltjpreset_declare_bool_option:nn {
55   \bool_new:c { l_ltjpreset_#1_bool }
56   \bool_set_false:c { l_ltjpreset_#1_bool }
57   \keys_define:nn { luatexja-preset }{
58     #1 .bool_set:c =  { l_ltjpreset_#1_bool },
59     #2 .bool_set_inverse:c =  { l_ltjpreset_#1_bool },
60     #1 .default:n =  true,
61     #2 .default:n =  true,
62   }
63 }
64
65 %%%%%%%% bool options
66 \bool_new:N \l_ltjpreset_office_bool  % MS Office の HG 系フォントを使っているか
67 \bool_new:N \l_ltjpreset_noembed_bool % 非埋込か
68 \bool_new:N \l_ltjpreset_custom_bool
69 \bool_new:N \l_ltjpreset_shape_nlck_bool
70 \ltjpreset_declare_bool_option:nn { nfssonly }{ fontspec }
71 \ltjpreset_declare_bool_option:nn { bold }{ nobold }
72 \ltjpreset_declare_bool_option:nn { expert }{ noexpert }
73 \ltjpreset_declare_bool_option:nn { deluxe }{ nodeluxe }
74
75 % JFM
76 \tl_new:N \ltjpreset_use_jfm_yoko_tl % 使用する JFM(横)
77 \tl_set:Nn \ltjpreset_use_jfm_yoko_tl {ujis}
78 \tl_new:N \ltjpreset_use_jfm_tate_tl % 使用する JFM(縦)
79 \tl_set:Nn \ltjpreset_use_jfm_tate_tl {ujisv}
80 \ltjpreset_declare_option:nn{jis}{\tl_set:Nn  \ltjpreset_use_jfm_yoko_tl {jis}}     % jis
81 \ltjpreset_declare_option:nn{ujis}{\tl_set:Nn  \ltjpreset_use_jfm_yoko_tl {ujis}}   % ujis
82
83 % 漢字字形
84 \tl_new:N \l_ltjpreset_kanji_shape_tl
85 \ltjpreset_declare_option:nn{90jis}{  \tl_set:Nn \l_ltjpreset_kanji_shape_tl { , CJKShape=JIS1990 }} % 90jis
86 \ltjpreset_declare_option:nn{jis2004}{\tl_set:Nn \l_ltjpreset_kanji_shape_tl { , CJKShape=JIS2004 }} % jis2004
87
88 % font preset
89 \prop_new:N \l_ltjpreset_font_prop
90 \keys_define:nn { ltjpreset-fontlist } {
91   mc .code:n =
92      \prop_gput:Nnn \l_ltjpreset_font_prop { mc-l } {#1}
93      \prop_gput:Nnn \l_ltjpreset_font_prop { mc-m } {#1}
94      \prop_gput:Nnn \l_ltjpreset_font_prop { mc-bx } {#1},
95   gt .code:n =
96      \prop_gput:Nnn \l_ltjpreset_font_prop { gt-u } {#1}
97      \prop_gput:Nnn \l_ltjpreset_font_prop { gt-m } {#1}
98      \prop_gput:Nnn \l_ltjpreset_font_prop { gt-bx } {#1}
99      \prop_gput:Nnn \l_ltjpreset_font_prop { gt-eb } {#1},
100 }
101 \cs_set:Nn \l_ltjpreset_tmp_cs:n {
102   \keys_define:nn { ltjpreset-fontlist } {
103     #1 .code:n = { \prop_gput:Non \l_ltjpreset_font_prop { #1 } { ##1 } }
104   }
105 }
106 \l_ltjpreset_tmp_cs:n { mc-l }
107 \l_ltjpreset_tmp_cs:n { mc-m }
108 \l_ltjpreset_tmp_cs:n { mc-bx }
109 \l_ltjpreset_tmp_cs:n { gt-u }
110 \l_ltjpreset_tmp_cs:n { gt-m }
111 \l_ltjpreset_tmp_cs:n { gt-bx }
112 \l_ltjpreset_tmp_cs:n { gt-eb}
113 \l_ltjpreset_tmp_cs:n { mg-m }
114 \cs_undefine:N \l_ltjpreset_tmp_cs:n
115
116 \cs_new:Nn \ltjpreset_set_uni:nn {
117   \group_begin: \keys_set:nn { ltjpreset-fontlist } {
118     mc = #1, gt = #2, mc-bx = #2, mg-m = #2,
119   } \group_end:
120   \bool_set_false:N \l_ltjpreset_custom_bool
121 }
122 \cs_new:Nn \ltjpreset_set_multi:n {
123   \keys_set_known:nnN { ltjpreset-presets } { #1 } \l_tmpa_tl
124   \keys_set_known:nn { ltjpreset-fontlist } { \l_tmpa_tl }
125   \prop_show:N \l_ltjpreset_font_prop
126   \bool_set_false:N \l_ltjpreset_custom_bool
127   \bool_set_false:N \l_ltjpreset_office_bool
128   \bool_set_false:N \l_ltjpreset_noembed_bool
129 }
130 \cs_new:Npn \ltjpreset_set_office:nn #1 #2{
131   \ltjpreset_set_multi:n {
132     mc-m = #1,         mc-bx = HGMinchoE ,
133     gt-m = HGGothicM , gt-bx = HGGothicE ,
134     gt-u = #2 ,        gt-eb = HGSoeiKakugothicUB ,
135     mg-m = HGMaruGothicMPRO
136   }
137   \bool_set_false:N \l_ltjpreset_custom_bool
138   \bool_set_true:N \l_ltjpreset_office_bool
139 }
140
141
142 %%%%%%%% プリセット達
143
144 % カスタム指定
145  \keys_define:nn { luatexja-preset }{
146     custom .code:n = \ltjpreset_set_multi:n { #1 } \bool_set_true:N \l_ltjpreset_custom_bool,
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:nn{kozuka-pro}{
155   \ltjpreset_set_multi:n {
156     mc-m =  KozMinPro-Regular, mc-bx = KozMinPro-Bold,
157     gt-m =  KozGoPro-Regular,  gt-bx = KozGoPro-Bold,
158     gt-u =  KozGoPro-Medium,   gt-eb = KozGoPro-Heavy,
159     mg-m =  KozGoPro-Heavy,    mc-l =  KozMinPro-Light,
160   }
161 }
162 %% Pr6
163 \ltjpreset_declare_preset:nn{kozuka-pr6}{
164   \ltjpreset_set_multi:n {
165     mc-m =  KozMinProVI-Regular, mc-bx = KozMinProVI-Bold,
166     gt-m =  KozGoProVI-Regular,  gt-bx = KozGoProVI-Bold,
167     gt-u =  KozGoProVI-Medium,   gt-eb = KozGoProVI-Heavy,
168     mg-m =  KozGoProVI-Heavy,    mc-l =  KozMinProVI-Light,
169   }
170 }
171 %% Pr6N
172 \ltjpreset_declare_preset:nn{kozuka-pr6n}{
173   \ltjpreset_set_multi:n {
174     mc-m =  KozMinPr6N-Regular, mc-bx = KozMinPr6N-Bold,
175     gt-m =  KozGoPr6N-Regular,  gt-bx = KozGoPr6N-Bold,
176     gt-u =  KozGoPr6N-Medium,   gt-eb = KozGoPr6N-Heavy,
177     mg-m =  KozGoPr6N-Heavy,    mc-l =  KozMinPr6N-Light,
178   }
179 }
180
181 % ヒラギノ (OSX)
182 \ltjpreset_declare_preset:nn{hiragino-pro}{
183   \ltjpreset_set_multi:n {
184     mc-m = HiraMinPro-W3,  mc-bx = HiraMinPro-W6,
185     gt-m = HiraKakuPro-W3, gt-bx = HiraKakuPro-W6,
186     gt-u = HiraKakuPro-W6, gt-eb = HiraKakuStd-W8,
187     mg-m = HiraMaruPro-W4, mc-l =  HiraMinPro-W2,
188   }
189 }
190 \ltjpreset_declare_preset:nn{hiragino-pron}{
191   \ltjpreset_set_multi:n {
192     mc-m = HiraMinProN-W3,  mc-bx = HiraMinProN-W6,
193     gt-m = HiraKakuProN-W3, gt-bx = HiraKakuProN-W6,
194     gt-u = HiraKakuProN-W6, gt-eb = HiraKakuStdN-W8,
195     mg-m = HiraMaruProN-W4, mc-l =  HiraMinProN-W2,
196   }
197 }
198
199 % モリサワ
200 \ltjpreset_declare_preset:nn{morisawa-pro}{
201   \ltjpreset_set_multi:n {
202     mc =   A-OTF-RyuminPro-Light.otf,      mc-bx = A-OTF-FutoMinA101Pro-Bold.otf,
203     gt-m = A-OTF-GothicBBBPro-Medium.otf , gt-bx = A-OTF-FutoGoB101Pro-Bold.otf,
204     gt-u = A-OTF-GothicBBBPro-Medium.otf , gt-eb = A-OTF-MidashiGoPro-MB31.otf,
205     mg-m = A-OTF-Jun101Pro-Light.otf,
206   }
207 }
208 \ltjpreset_declare_preset:nn{morisawa-pr6n}{
209   \ltjpreset_set_multi:n {
210     mc =   A-OTF-RyuminPr6N-Light.otf,      mc-bx = A-OTF-FutoMinA101Pr6N-Bold.otf,
211     gt-m = A-OTF-GothicBBBPr6N-Medium.otf , gt-bx = A-OTF-FutoGoB101Pr6N-Bold.otf,
212     gt-u = A-OTF-GothicBBBPr6N-Medium.otf , gt-eb = A-OTF-MidashiGoPr6N-MB31.otf,
213     mg-m = A-OTF-Jun101Pr6N-Light.otf,
214   }
215 }
216
217 % 游明朝/游ゴシック (Win8.1)
218 \ltjpreset_declare_preset:nn{yu-win}{
219   \ltjpreset_set_multi:n {
220     mc-m = YuMincho-Regular, mc-bx = YuMincho-Demibold,
221     gt-m = YuGothic-Regular, gt-bx = YuGothic-Bold,
222     gt-u = YuGothic-Regular, gt-eb = YuGothic-Bold,
223     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light
224   }
225 }
226 % Win10
227 \ltjpreset_declare_preset:nn{yu-win10}{
228   \ltjpreset_set_multi:n {
229     mc-m = YuMincho-Regular, mc-bx = YuMincho-Demibold,
230     gt-m = YuGothic-Regular, gt-bx = YuGothic-Bold,
231     gt-u = YuGothic-Medium,  gt-eb = YuGothic-Bold,
232     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light
233   }
234 }
235
236 % Yu fonts in OSX
237 % according to http://support.apple.com/kb/HT5944
238 \ltjpreset_declare_preset:nn{yu-osx}{
239   \ltjpreset_set_multi:n {
240     mc =  YuMincho~Medium, mc-bx = YuMincho~Demibold,
241     gt-m =  YuGothic~Medium, gt-u =  YuGothic~Medium,
242     gt-bx = YuGothic~Bold,   gt-eb = YuGothic~Bold,
243     mg-m =  YuGothic~Bold
244   }
245 }
246
247 % moga-mobo
248 \ltjpreset_declare_preset:nn{moga-mobo}{
249   \ltjpreset_set_multi:n {
250     mc =   Moga90Mincho, mc-bx = Moga90Mincho~Bold,
251     gt-m = Moga90Gothic, gt-bx = Moga90Gothic~Bold,
252     gt-u = Moga90Gothic, gt-eb = Moga90Gothic~Bold,
253     mg-m = Mobo90Gothic
254   }
255 }
256 \ltjpreset_declare_preset:nn{moga-mobo-ex}{
257   \ltjpreset_set_multi:n {
258     mc =   MogaEx90Mincho, mc-bx = MogaEx90Mincho~Bold,
259     gt-m = MogaEx90Gothic, gt-bx = MogaEx90Gothic~Bold,
260     gt-u = MogaEx90Gothic, gt-eb = MogaEx90Gothic~Bold,
261     mg-m = MoboEx90Gothic
262   }
263 }
264
265 % Ume fones
266 \ltjpreset_declare_preset:nn{ume}{
267   \ltjpreset_set_multi:n {
268     mc = Ume~Mincho,
269     gt-m = Ume~Gothic,    gt-bx = Ume~Gothic~O5,
270     gt-u = Ume~Gothic~O5, gt-eb = Ume~Gothic~O5,
271     mg-m = Ume~Gothic~O4
272   }
273 }
274
275 % Source Han {Serif,Sans}
276 \ltjpreset_declare_preset:nn{sourcehan}{
277   \ltjpreset_set_multi:n {
278     mc-m =  Source~Han~Serif~Regular,
279     mc-bx = Source~Han~Serif~Bold,
280     gt-m =  Source~Han~Sans~Regular,
281     gt-bx = Source~Han~Sans~Bold,
282     gt-u =  Source~Han~Sans~Medium,
283     gt-eb = Source~Han~Sans~Heavy,
284     mg-m =  Source~Han~Sans~Heavy,
285     mc-l =  Source~Han~Serif~Light,
286   }
287 }
288 \ltjpreset_declare_preset:nn{sourcehan-jp}{
289   \ltjpreset_set_multi:n {
290     mc-m =  Source~Han~Serif~JP~Regular,
291     mc-bx = Source~Han~Serif~JP~Bold,
292     gt-m =  Source~Han~Sans~JP~Regular,
293     gt-bx = Source~Han~Sans~JP~Bold,
294     gt-u =  Source~Han~Sans~JP~Medium,
295     gt-eb = Source~Han~Sans~JP~Heavy,
296     mg-m =  Source~Han~Sans~JP~Heavy,
297     mc-l =  Source~Han~Serif~JP~Light,
298   }
299 }
300 \ltjpreset_declare_preset:nn{noto-otc}{
301   \ltjpreset_set_multi:n {
302     mc-m =  Noto~Serif~CJK~Regular,
303     mc-bx = Noto~Serif~CJK~Bold,
304     gt-m =  Noto~Sans~CJK~Regular,
305     gt-bx = Noto~Sans~CJK~Bold,
306     gt-u =  Noto~Sans~CJK~Medium,
307     gt-eb = Noto~Sans~CJK~Black,
308     mg-m =  Noto~Sans~CJK~Black,
309     mc-l =  Noto~Serif~CJK~Light,
310   }
311 }
312 \ltjpreset_declare_preset:nn{noto-otf}{
313   \ltjpreset_set_multi:n {
314     mc-m =  Noto~Serif~CJK~JP~Regular,
315     mc-bx = Noto~Serif~CJK~JP~Bold,
316     gt-m =  Noto~Sans~CJK~JP~Regular,
317     gt-bx = Noto~Sans~CJK~JP~Bold,
318     gt-u =  Noto~Sans~CJK~JP~Medium,
319     gt-eb = Noto~Sans~CJK~JP~Black,
320     mg-m =  Noto~Sans~CJK~JP~Black,
321     mc-l =  Noto~Serif~CJK~JP~Light,
322   }
323 }
324
325
326 % ipa, ipaex, ms
327 \ltjpreset_declare_preset:nn{ipa}{
328   \ltjpreset_set_uni:nn { IPAMincho } { IPAGothic }
329 }
330 \ltjpreset_declare_preset:nn{ipaex}{
331   \ltjpreset_set_uni:nn { IPAExMincho } { IPAExGothic }
332 }
333 \ltjpreset_declare_preset:nn{ms}{
334   \ltjpreset_set_uni:nn { MS-Mincho } { MS-Gothic }
335 }
336
337 % {ipa,ipaex,ms}-dx % Office 付属フォントを利用
338 \ltjpreset_declare_preset:nn{ipaex-hg}{
339   \ltjpreset_set_office:nn { IPAExMincho } { IPAExGothic }
340 }
341 \ltjpreset_declare_preset:nn{ipa-hg}{
342   \ltjpreset_set_office:nn { IPAMincho } { IPAGothic }
343 }
344 \ltjpreset_declare_preset:nn{ms-hg}{
345   \ltjpreset_set_office:nn { MS-Mincho } { MS-Gothic }
346 }
347
348
349 % 非埋込
350 \ltjpreset_declare_preset:nn{noembed}{
351   \ltjpreset_set_uni:nn { Ryumin-Light } { GothicBBB-Medium }
352   \bool_set_true:N \l_ltjpreset_noembed_bool
353 }
354
355 \ProcessKeysOptions { luatexja-preset }
356 \@ifpackageloaded{luatexja-fontspec}{
357   \bool_if:NT \l_ltjpreset_nfssonly_bool
358     { \msg_warning:nn { luatexja-preset }{ ltj-fontspec } }
359   \bool_set_false:N \l_ltjpreset_nfssonly_bool
360 }{}
361
362 %%%%%%%% main routine
363
364 \cs_new:Nn \ltjpreset_extract_fonts: {
365   %% KozMinPr6N, HiraMinProN-W3 の場合はjp04 feature がないので,nlck にする
366   %% MogaMincho の場合は 90 をつける/はずす
367   \bool_if:NF \l_ltjpreset_custom_bool {
368     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
369     \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
370       \tl_set:Nx \l_tmpb_tl { \prop_item:Nn \l_ltjpreset_font_prop { mc-m } }
371       \tl_if_in:NnT  \l_tmpb_tl { KozMinPr6N-Regular }
372         { \bool_set_true:N \l_ltjpreset_shape_nlck_bool }
373       \tl_if_in:NnT  \l_tmpb_tl { HiraMinProN-W3 }
374         { \bool_set_true:N \l_ltjpreset_shape_nlck_bool }
375       \tl_if_in:NnT  \l_tmpb_tl { Moga90Mincho } {
376         \prop_clear:N \l_tmpa_prop
377         \prop_map_inline:Nn \l_ltjpreset_font_prop {
378            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
379           \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
380          } 
381          \prop_set_eq:NN \l_ltjpreset_font_prop \l_tmpa_prop
382        }
383        \tl_if_in:NnT  \l_tmpb_tl { MogaEx90Mincho } {
384          \prop_clear:N \l_tmpa_prop
385          \prop_map_inline:Nn \l_ltjpreset_font_prop {
386            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
387            \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
388          }
389          \prop_set_eq:NN \l_ltjpreset_font_prop \l_tmpa_prop
390        }
391     }
392   }
393   %%%%  リストからの展開
394   \cs_set:Nx \ltjpreset_font_mc_l:  { \prop_item:Nn \l_ltjpreset_font_prop { mc-l } }
395   \cs_set:Nx \ltjpreset_font_mc_m:  { \prop_item:Nn \l_ltjpreset_font_prop { mc-m } }
396   \cs_set:Nx \ltjpreset_font_mc_bx: { \prop_item:Nn \l_ltjpreset_font_prop { mc-bx } }
397   \cs_set:Nx \ltjpreset_font_gt_m:  { \prop_item:Nn \l_ltjpreset_font_prop { gt-m } }
398   \cs_set:Nx \ltjpreset_font_gt_u:  { \prop_item:Nn \l_ltjpreset_font_prop { gt-u } }
399   \cs_set:Nx \ltjpreset_font_gt_bx: { \prop_item:Nn \l_ltjpreset_font_prop { gt-bx } }
400   \cs_set:Nx \ltjpreset_font_gt_eb: { \prop_item:Nn \l_ltjpreset_font_prop { gt-eb } }
401   \cs_set:Nx \ltjpreset_font_mg_m:  { \prop_item:Nn \l_ltjpreset_font_prop { mg-m } }
402   %% HG 系フォント + JIS2004/90JIS のときはフォント名を置換
403   \bool_if:nT { !\l_ltjpreset_custom_bool && \l_ltjpreset_office_bool } {
404     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
405     \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
406       \cs_set:Nx \ltjpreset_font_mc_bx: { hgrme04.ttc }
407       \cs_set:Nx \ltjpreset_font_gt_bx: { hgrge04.ttc }
408       \cs_set:Nx \ltjpreset_font_gt_eb: { hgrsgu04.ttc }
409       \cs_set:Nx \ltjpreset_font_mg_m:  { hgrsmp04.ttf }
410       \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_u:
411       % HG ゴシックM のときはそうはいかないので 1 ウェイト時のゴシック体を使う
412     }
413     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
414     \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
415       \cs_set:Nx \ltjpreset_font_mc_bx: { hgrme.ttc }
416       \cs_set:Nx \ltjpreset_font_gt_bx: { hgrge.ttc }
417       \cs_set:Nx \ltjpreset_font_gt_eb: { hgrsgu.ttc }
418       \cs_set:Nx \ltjpreset_font_mg_m:  { hgrsmp.ttf }
419     }
420   }
421   % mc/l
422   \tl_set:Nx \l_tmpa_tl { \ltjpreset_font_mc_l: }
423   \tl_if_empty:NT \l_tmpa_tl {\tl_set:Nn \l_tmpa_tl {~}}
424   \cs_set:Nx \ltjpreset_font_mc_l: {
425     \tl_if_blank:nTF \l_tmpa_tl { \ltjpreset_font_mc_m: } {\tl_use:N \l_tmpa_tl }
426   }
427   %% bold オプションの処理
428   \bool_if:NTF \l_ltjpreset_deluxe_bool {
429     \bool_if:NT \l_ltjpreset_bold_bool {
430       \cs_set_eq:NN \ltjpreset_font_mc_bx: \ltjpreset_font_gt_bx:
431     }
432   }{
433     \cs_set_eq:Nc \ltjpreset_font_gt_m: {
434       \ltj_preset_font_gt_ \bool_if:NTF \l_ltjpreset_bold_bool { bx } { u } :
435     }{
436       \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_u:
437     }
438     \cs_set_eq:NN \ltjpreset_font_gt_bx: \ltjpreset_font_gt_m:
439     \cs_set_eq:NN \ltjpreset_font_mc_bx: \ltjpreset_font_gt_m:
440   }
441 }
442
443 %%%%%%%% 存在判定
444 \cs_new:Nn \ltjpreset_substitute:nnnn {
445   \group_begin:
446     \suppressfontnotfounderror=1
447     \font \l_ltjpreset_font_test: = "\cs:w ltjpreset_font_#1_#2: \cs_end:"\relax
448     \ifx \l_ltjpreset_font_test: \nullfont
449       \msg_warning:nnxxxx { luatexja-preset }{ no-font }
450         { \cs:w ltjpreset_font_#1_#2: \cs_end: }{ #1/#2 }
451         { \cs:w ltjpreset_font_#3_#4: \cs_end: }{ #3/#4 }
452       \cs_gset_eq:cc { ltjpreset_font_#1_#2: } { ltjpreset_font_#3_#4: }
453     \fi
454   \group_end:
455 }
456
457 %%%%%%%% deluxe (\mgfamily はあとで定義)
458 \bool_if:NTF \l_ltjpreset_deluxe_bool {
459   \cs_new:Nn \ltjpreset_check_deluxe_existence: {
460     \ltjpreset_substitute:nnnn { gt } { eb } { gt } { bx }
461     \ltjpreset_substitute:nnnn { mg } { m  } { gt } { bx }
462     \ltjpreset_substitute:nnnn { mc } { l  } { mc } { m  }
463   }
464   \def\ltdefault{l}
465   \DeclareRobustCommand\ltseries { \not@math@alphabet\ltseries\relax\fontseries\ltdefault\selectfont }
466   \def\ebdefault{eb}
467   \DeclareRobustCommand\ebseries { \not@math@alphabet\ebseries\relax\fontseries\ebdefault\selectfont }
468   \DeclareRobustCommand\gtebfamily { \gtfamily\fontseries{\ebdefault}\selectfont }
469 } {
470   \cs_let:NN \ltjpreset_check_deluxe_existence: \do_nothing:
471 }
472
473 \bool_if:NTF \l_ltjpreset_nfssonly_bool {
474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
475 %%%%%%%% nfss only
476   \msg_warning:nnx { luatexja-preset }{ scale }{ \fp_use:N \l_ltjpreset_scale_fp }
477
478   \cs_new:Nn \ltj_preset_define_family:nnn {
479     \DeclareFontShape{JY3}{#1}{#2}{n}{ <-> s*[\fp_use:N \l_ltjpreset_scale_fp] {
480       \bool_if:NT \l_ltjpreset_noembed_bool {psft:} "#3"
481       : jfm=\tl_use:N \ltjpreset_use_jfm_yoko_tl ;-kern;\tl_use:N \l_ltjpreset_kanji_shape_tl
482       ; script=hani \bool_if:NT \l_ltjpreset_expert_bool { ;+hkna }}
483     } {}
484     \DeclareFontShape{JT3}{#1}{#2}{n}{ <-> s*[\fp_use:N \l_ltjpreset_scale_fp] {
485       \bool_if:NT \l_ltjpreset_noembed_bool {psft:} "#3"
486       : jfm=\tl_use:N \ltjpreset_use_jfm_tate_tl ;-kern;\tl_use:N \l_ltjpreset_kanji_shape_tl
487       ; script=hani \bool_if:NT \l_ltjpreset_expert_bool { ;+vkna }}
488     } {}
489     \bool_if:NT \l_ltjpreset_expert_bool {
490       \DeclareFontShape{JY3}{#1}{#2}{rb}{ <-> s*[\fp_use:N \l_ltjpreset_scale_fp] {
491         \bool_if:NT \l_ltjpreset_noembed_bool {psft:} "#3"
492         : jfm=\tl_use:N \ltjpreset_use_jfm_yoko_tl ;-kern;\tl_use:N \l_ltjpreset_kanji_shape_tl
493         ; +ruby ; script=kana}
494       } {}
495       \DeclareFontShape{JT3}{#1}{#2}{rb}{ <-> s*[\fp_use:N \l_ltjpreset_scale_fp] {
496         \bool_if:NT \l_ltjpreset_noembed_bool {psft:} "#3"
497         : jfm=\tl_use:N \ltjpreset_use_jfm_tate_tl ;-kern;\tl_use:N \l_ltjpreset_kanji_shape_tl
498         ; +ruby ; script=kana}
499       } {}
500     }
501   }
502
503   \DeclareKanjiFamily{JY3}{ltjpm}{}\DeclareKanjiFamily{JT3}{ltjpm}{}
504   \DeclareKanjiFamily{JY3}{ltjpg}{}\DeclareKanjiFamily{JT3}{ltjpg}{}
505   \def\mcdefault{ltjpm}\def\gtdefault{ltjpg}
506   \SetSymbolFont{mincho}{normal}{JY3}{ltjpm}{m}{n}
507   \SetSymbolFont{mincho}{bold}{JY3}{ltjpm}{bx}{n}
508   \DeclareMathAlphabet{\mathgt}{JY3}{ltjpg}{m}{n}
509   \bool_if:NT \l_ltjpreset_expert_bool {
510     \DeclareRobustCommand\rubyfamily { \kanjishape{rb}\selectfont }
511   }
512
513   \bool_if:NT \l_ltjpreset_deluxe_bool {
514     \DeclareKanjiFamily{JY3}{ltjpmg}{}\DeclareKanjiFamily{JT3}{ltjpmg}{}
515     \DeclareRobustCommand\mgfamily {
516       \not@math@alphabet\mgfamily\relax\kanjifamily{ltjpmg}\selectfont
517     }
518     \DeclareTextFontCommand{\textmg}{\mgfamily}
519   }
520   %
521   \cs_new:Nn \ltjpreset_do_fontset: { \group_begin:
522     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
523     \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
524       \tl_set:Nn \l_ltjpreset_kanji_shape_tl { +jp90 }
525     }
526     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
527     \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
528       \tl_set:Nx \l_ltjpreset_kanji_shape_tl {
529         \bool_if:NTF \l_ltjpreset_shape_nlck_bool { +nlck } { +jp04 }
530       }
531     }
532     \ltj_preset_define_family:nnn {ltjpm} {m}  {\ltjpreset_font_mc_m:}
533     \ltj_preset_define_family:nnn {ltjpm} {bx} {\ltjpreset_font_mc_bx:}
534     \ltj_preset_define_family:nnn {ltjpg} {m}  {\ltjpreset_font_gt_m:}
535     \ltj_preset_define_family:nnn {ltjpg} {bx} {\ltjpreset_font_gt_bx:}
536     \normalfont
537     \bool_if:NT \l_ltjpreset_deluxe_bool {
538       \ltj_preset_define_family:nnn {ltjpm}  {l} {\ltjpreset_font_mc_l:}
539       \ltj_preset_define_family:nnn {ltjpg}  {eb} {\ltjpreset_font_gt_eb:}
540       \ltj_preset_define_family:nnn {ltjpmg} {m}  {\ltjpreset_font_mg_m:}
541     }
542     \group_end:
543   }
544 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
545 %%%%%%%% fontspec
546 } {
547   \PassOptionsToPackage { scale = \fp_use:N \l_ltjpreset_scale_fp } { luatexja-fontspec }
548   \RequirePackage{luatexja-fontspec}
549   % scale
550   \msg_warning:nnx { luatexja-preset }{ scale }{ \fp_use:N \g_ltj_fontspec_scale_fp }
551   \tl_new:N \l_ltjpreset_add_features_tl
552
553   \bool_if:NT \l_ltjpreset_expert_bool {
554     \cs_set:Npn \rubyfamily { \addjfontfeatures {
555       Style=Ruby , YokoFeatures={RawFeature=-hkna} , TateFeatures={RawFeature=-vkna}
556     } }
557   }
558   \addjfontfeature{ Kerning=Off }
559   % 実際の fontspec の呼びだし
560   \cs_new:Nn \ltjpreset_do_fontset: { \group_begin:
561       \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
562       \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
563         \bool_if:NT \l_ltjpreset_shape_nlck_bool
564           { \tl_set:Nn \l_ltjpreset_kanji_shape_tl { , CJKShape=NLC } }
565       }
566       \tl_gset:Nx \l_ltjpreset_add_features_tl {
567         \tl_use:N \l_ltjpreset_kanji_shape_tl,
568         YokoFeatures = { JFM = \tl_use:N \ltjpreset_use_jfm_yoko_tl },
569         TateFeatures = { JFM = \tl_use:N \ltjpreset_use_jfm_tate_tl },
570         Script=CJK, \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed },
571       }
572     \group_end:
573     \bool_if:NT \l_ltjpreset_expert_bool {
574       \tl_put_left:Nn \l_ltjpreset_add_features_tl {
575         YokoFeatures = {Style = HorizontalKana}, TateFeatures = {Style = VerticalKana},
576       }
577     }
578     \setmainjfont [
579       \bool_if:NT \l_ltjpreset_deluxe_bool { FontFace={l}{n}{\ltjpreset_font_mc_l:}, }
580       BoldFont = \ltjpreset_font_mc_bx: \tl_use:N \l_ltjpreset_add_features_tl
581     ] { \ltjpreset_font_mc_m: }
582     \setsansjfont [
583       \bool_if:NT \l_ltjpreset_deluxe_bool { FontFace={eb}{n}{\ltjpreset_font_gt_eb:}, }
584       BoldFont = \ltjpreset_font_gt_bx: \tl_use:N \l_ltjpreset_add_features_tl
585     ] { \ltjpreset_font_gt_m: }
586     \bool_if:NT \l_ltjpreset_deluxe_bool {
587       %% mg
588       \newjfontfamily \mgfamily [
589         BoldFont = \ltjpreset_font_mg_m: \tl_use:N \l_ltjpreset_add_features_tl
590       ] { \ltjpreset_font_mg_m: }
591       \DeclareTextFontCommand{\textmg}{\mgfamily}
592     }
593   }
594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
595 }
596
597 \cs_set:Npn \ltjnewpreset #1 #2 {
598   \keys_define:nn { ltjpreset-presets } {
599     #1 .code:n =
600       { \ltjpreset_set_multi:n { #2 } \bool_set_true:N \l_ltjpreset_custom_bool },
601     #1 .value_forbidden:n = true,
602   }
603 }
604
605 \tl_new:N \l_ltjpreset_residue_tl
606 \cs_set:Npn \ltjapplypreset #1 {
607   \keys_set:nn { ltjpreset-presets } { #1 }
608   \prop_show:N \l_ltjpreset_font_prop
609   \ltjpreset_extract_fonts:
610   \ltjpreset_check_deluxe_existence:
611   \ltjpreset_do_fontset:
612 }
613
614
615 \ltjapplypreset { ipaex }
616
617
618 \ExplSyntaxOff
619 \endinput