OSDN Git Service

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