OSDN Git Service

lltjp-listings.sty: fix #38541
[luatex-ja/luatexja.git] / src / addons / luatexja-preset.sty
1 % luatexja-preset.sty
2 \ProvidesPackage{luatexja-preset}[2018/08/01 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 {ujis}
83 \tl_new:N \ltjpreset_use_jfm_tate_tl % 使用する JFM(縦)
84 \tl_set:Nn \ltjpreset_use_jfm_tate_tl {ujisv}
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-m } {#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 .groups:n = { preset }, gt .value_required:n = true,
109 }
110 \cs_set:Nn \g_ltjpreset_tmp_cs:n {
111   \keys_define:nn { luatexja-preset } {
112     #1 .code:n = \prop_put:Non \g_ltjpreset_font_prop { #1 } { ##1 },
113     #1 .groups:n = { preset }, #1 .value_required:n = true,
114   }
115 }
116 \g_ltjpreset_tmp_cs:n { mc-l }
117 \g_ltjpreset_tmp_cs:n { mc-m }
118 \g_ltjpreset_tmp_cs:n { mc-bx }
119 \g_ltjpreset_tmp_cs:n { gt-u }
120 \g_ltjpreset_tmp_cs:n { gt-m }
121 \g_ltjpreset_tmp_cs:n { gt-bx }
122 \g_ltjpreset_tmp_cs:n { gt-eb}
123 \g_ltjpreset_tmp_cs:n { mg-m }
124 \cs_undefine:N \g_ltjpreset_tmp_cs:n
125
126 \cs_new:Nn \ltjpreset_set_uni:nn {
127   mc = #1, gt = #2, mc-bx = #2, mg-m = #2,
128   __custom = false, __office = false, __noembed = false,
129 }
130 \cs_new:Npn \ltjpreset_set_office:nn #1 #2{
131   mc   = #1,         mc-bx = HGMinchoE ,
132   gt-m = HGGothicM , gt-bx = HGGothicE ,
133   gt-u = #2 ,        gt-eb = HGSoeiKakugothicUB ,
134   mg-m = HGMaruGothicMPRO,
135   __custom = false, __office = true, __noembed = false,
136 }
137
138 %%%%%%%% プリセット達
139
140 % カスタム指定
141  \keys_define:nn { luatexja-preset }{
142     custom .meta:n = { #1, __custom = true, }, 
143     custom .value_required:n = true,
144     jfm_yoko .tl_set:N = \ltjpreset_use_jfm_yoko_tl,
145     jfm_tate .tl_set:N = \ltjpreset_use_jfm_tate_tl,
146 }
147
148 % 小塚 (Adobe)
149 %% Pro
150 \ltjpreset_declare_preset:nx{kozuka-pro}{
151     mc-m =  KozMinPro-Regular, mc-bx = KozMinPro-Bold,
152     gt-m =  KozGoPro-Regular,  gt-bx = KozGoPro-Bold,
153     gt-u =  KozGoPro-Medium,   gt-eb = KozGoPro-Heavy,
154     mg-m =  KozGoPro-Heavy,    mc-l =  KozMinPro-Light,
155     __custom = false, __office = false, __noembed = false,
156 }
157 %% Pr6
158 \ltjpreset_declare_preset:nx{kozuka-pr6}{
159     mc-m =  KozMinProVI-Regular, mc-bx = KozMinProVI-Bold,
160     gt-m =  KozGoProVI-Regular,  gt-bx = KozGoProVI-Bold,
161     gt-u =  KozGoProVI-Medium,   gt-eb = KozGoProVI-Heavy,
162     mg-m =  KozGoProVI-Heavy,    mc-l =  KozMinProVI-Light,
163     __custom = false, __office = false, __noembed = false,
164 }
165 %% Pr6N
166 \ltjpreset_declare_preset:nx{kozuka-pr6n}{
167     mc-m =  KozMinPr6N-Regular, mc-bx = KozMinPr6N-Bold,
168     gt-m =  KozGoPr6N-Regular,  gt-bx = KozGoPr6N-Bold,
169     gt-u =  KozGoPr6N-Medium,   gt-eb = KozGoPr6N-Heavy,
170     mg-m =  KozGoPr6N-Heavy,    mc-l =  KozMinPr6N-Light,
171     __custom = false, __office = false, __noembed = false,
172 }
173
174 % ヒラギノ (OSX)
175 \ltjpreset_declare_preset:nx{hiragino-pro}{
176     mc-m = HiraMinPro-W3,  mc-bx = HiraMinPro-W6,
177     gt-m = HiraKakuPro-W3, gt-bx = HiraKakuPro-W6,
178     gt-u = HiraKakuPro-W6, gt-eb = HiraKakuStd-W8,
179     mg-m = HiraMaruPro-W4, mc-l =  HiraMinPro-W2,
180     __custom = false, __office = false, __noembed = false,
181 }
182 \ltjpreset_declare_preset:nx{hiragino-pron}{
183     mc-m = HiraMinProN-W3,  mc-bx = HiraMinProN-W6,
184     gt-m = HiraKakuProN-W3, gt-bx = HiraKakuProN-W6,
185     gt-u = HiraKakuProN-W6, gt-eb = HiraKakuStdN-W8,
186     mg-m = HiraMaruProN-W4, mc-l =  HiraMinProN-W2,
187     __custom = false, __office = false, __noembed = false,
188 }
189
190 % モリサワ
191 \ltjpreset_declare_preset:nx{morisawa-pro}{
192     mc =   A-OTF-RyuminPro-Light.otf,      mc-bx = A-OTF-FutoMinA101Pro-Bold.otf,
193     gt-m = A-OTF-GothicBBBPro-Medium.otf , gt-bx = A-OTF-FutoGoB101Pro-Bold.otf,
194     gt-u = A-OTF-GothicBBBPro-Medium.otf , gt-eb = A-OTF-MidashiGoPro-MB31.otf,
195     mg-m = A-OTF-Jun101Pro-Light.otf,
196     __custom = false, __office = false, __noembed = false,
197 }
198 \ltjpreset_declare_preset:nx{morisawa-pr6n}{
199     mc =   A-OTF-RyuminPr6N-Light.otf,      mc-bx = A-OTF-FutoMinA101Pr6N-Bold.otf,
200     gt-m = A-OTF-GothicBBBPr6N-Medium.otf , gt-bx = A-OTF-FutoGoB101Pr6N-Bold.otf,
201     gt-u = A-OTF-GothicBBBPr6N-Medium.otf , gt-eb = A-OTF-MidashiGoPr6N-MB31.otf,
202     mg-m = A-OTF-Jun101Pr6N-Light.otf,
203     __custom = false, __office = false, __noembed = false,
204 }
205
206 % 游明朝/游ゴシック (Win8.1)
207 \ltjpreset_declare_preset:nx{yu-win}{
208     mc-m = YuMincho-Regular, mc-bx = YuMincho-Demibold,
209     gt-m = YuGothic-Regular, gt-bx = YuGothic-Bold,
210     gt-u = YuGothic-Regular, gt-eb = YuGothic-Bold,
211     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light,
212     __custom = false, __office = false, __noembed = false,
213 }
214 % Win10
215 \ltjpreset_declare_preset:nx{yu-win10}{
216     mc-m = YuMincho-Regular, mc-bx = YuMincho-Demibold,
217     gt-m = YuGothic-Regular, gt-bx = YuGothic-Bold,
218     gt-u = YuGothic-Medium,  gt-eb = YuGothic-Bold,
219     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light,
220     __custom = false, __office = false, __noembed = false,
221 }
222
223 % Yu fonts in OSX
224 % according to http://support.apple.com/kb/HT5944
225 \ltjpreset_declare_preset:nx{yu-osx}{
226     mc =  YuMincho~Medium, mc-bx = YuMincho~Demibold,
227     gt-m =  YuGothic~Medium, gt-u =  YuGothic~Medium,
228     gt-bx = YuGothic~Bold,   gt-eb = YuGothic~Bold,
229     mg-m =  YuGothic~Bold,
230     __custom = false, __office = false, __noembed = false,
231 }
232
233 % moga-mobo
234 \ltjpreset_declare_preset:nx{moga-mobo}{
235     mc =   Moga90Mincho, mc-bx = Moga90Mincho~Bold,
236     gt-m = Moga90Gothic, gt-bx = Moga90Gothic~Bold,
237     gt-u = Moga90Gothic, gt-eb = Moga90Gothic~Bold,
238     mg-m = Mobo90Gothic,
239     __custom = false, __office = false, __noembed = false,
240 }
241 \ltjpreset_declare_preset:nx{moga-mobo-ex}{
242     mc =   MogaEx90Mincho, mc-bx = MogaEx90Mincho~Bold,
243     gt-m = MogaEx90Gothic, gt-bx = MogaEx90Gothic~Bold,
244     gt-u = MogaEx90Gothic, gt-eb = MogaEx90Gothic~Bold,
245     mg-m = MoboEx90Gothic,
246     __custom = false, __office = false, __noembed = false,
247 }
248
249 % Ume fones
250 \ltjpreset_declare_preset:nx{ume}{
251     mc = Ume~Mincho,
252     gt-m = Ume~Gothic,    gt-bx = Ume~Gothic~O5,
253     gt-u = Ume~Gothic~O5, gt-eb = Ume~Gothic~O5,
254     mg-m = Ume~Gothic~O4,
255     __custom = false, __office = false, __noembed = false,
256 }
257
258 % Source Han {Serif,Sans}
259 \ltjpreset_declare_preset:nx{sourcehan}{
260     mc-m =  Source~Han~Serif~Regular,
261     mc-bx = Source~Han~Serif~Bold,
262     gt-m =  Source~Han~Sans~Regular,
263     gt-bx = Source~Han~Sans~Bold,
264     gt-u =  Source~Han~Sans~Medium,
265     gt-eb = Source~Han~Sans~Heavy,
266     mg-m =  Source~Han~Sans~Heavy,
267     mc-l =  Source~Han~Serif~Light,
268     __custom = false, __office = false, __noembed = false,
269 }
270 \ltjpreset_declare_preset:nx{sourcehan-jp}{
271     mc-m =  Source~Han~Serif~JP~Regular,
272     mc-bx = Source~Han~Serif~JP~Bold,
273     gt-m =  Source~Han~Sans~JP~Regular,
274     gt-bx = Source~Han~Sans~JP~Bold,
275     gt-u =  Source~Han~Sans~JP~Medium,
276     gt-eb = Source~Han~Sans~JP~Heavy,
277     mg-m =  Source~Han~Sans~JP~Heavy,
278     mc-l =  Source~Han~Serif~JP~Light,
279     __custom = false, __office = false, __noembed = false,
280 }
281 \ltjpreset_declare_preset:nx{noto-otc}{
282     mc-m =  Noto~Serif~CJK~Regular,
283     mc-bx = Noto~Serif~CJK~Bold,
284     gt-m =  Noto~Sans~CJK~Regular,
285     gt-bx = Noto~Sans~CJK~Bold,
286     gt-u =  Noto~Sans~CJK~Medium,
287     gt-eb = Noto~Sans~CJK~Black,
288     mg-m =  Noto~Sans~CJK~Black,
289     mc-l =  Noto~Serif~CJK~Light,
290     __custom = false, __office = false, __noembed = false,
291 }
292 \ltjpreset_declare_preset:nx{noto-otf}{
293     mc-m =  Noto~Serif~CJK~JP~Regular,
294     mc-bx = Noto~Serif~CJK~JP~Bold,
295     gt-m =  Noto~Sans~CJK~JP~Regular,
296     gt-bx = Noto~Sans~CJK~JP~Bold,
297     gt-u =  Noto~Sans~CJK~JP~Medium,
298     gt-eb = Noto~Sans~CJK~JP~Black,
299     mg-m =  Noto~Sans~CJK~JP~Black,
300     mc-l =  Noto~Serif~CJK~JP~Light,
301     __custom = false, __office = false, __noembed = false,
302 }
303
304
305 % ipa, ipaex, ms
306 \ltjpreset_declare_preset:nx{ipa}{
307   \ltjpreset_set_uni:nn { IPAMincho } { IPAGothic }
308 }
309 \ltjpreset_declare_preset:nx{ipaex}{
310   \ltjpreset_set_uni:nn { IPAExMincho } { IPAExGothic }
311 }
312 \ltjpreset_declare_preset:nx{ms}{
313   \ltjpreset_set_uni:nn { MS-Mincho } { MS-Gothic }
314 }
315
316 % {ipa,ipaex,ms}-dx % Office 付属フォントを利用
317 \ltjpreset_declare_preset:nx{ipaex-hg}{
318   \ltjpreset_set_office:nn { IPAExMincho } { IPAExGothic }
319 }
320 \ltjpreset_declare_preset:nx{ipa-hg}{
321   \ltjpreset_set_office:nn { IPAMincho } { IPAGothic }
322 }
323 \ltjpreset_declare_preset:nx{ms-hg}{
324   \ltjpreset_set_office:nn { MS-Mincho } { MS-Gothic }
325 }
326
327
328 % 非埋込
329 \ltjpreset_declare_preset:nx{noembed}{
330   \ltjpreset_set_uni:nn { Ryumin-Light } { GothicBBB-Medium },
331   __custom = false, __office = false, __noembed = true,
332 }
333
334 \keys_set:nn {luatexja-preset} { ipaex }
335 \ProcessKeysOptions { luatexja-preset }
336 \@ifpackageloaded{luatexja-fontspec}{
337   \bool_if:NT \g_ltjpreset_nfssonly_bool
338     { \msg_warning:nn { luatexja-preset }{ ltj-fontspec } }
339   \bool_set_false:N \g_ltjpreset_nfssonly_bool
340 }{}
341
342 %%%%%%%% main routine
343
344 \cs_new:Nn \ltjpreset_extract_fonts: {
345   %% MogaMincho の場合は 90 をつける/はずす
346   \bool_if:NF \g_ltjpreset_custom_bool {
347     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
348     \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
349       \tl_set:Nx \l_tmpb_tl { \prop_item:Nn \g_ltjpreset_font_prop { mc-m } }
350       \tl_if_in:NnT  \l_tmpb_tl { Moga90Mincho } {
351         \prop_clear:N \l_tmpa_prop
352         \prop_map_inline:Nn \g_ltjpreset_font_prop {
353            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
354           \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
355          } 
356          \prop_set_eq:NN \g_ltjpreset_font_prop \l_tmpa_prop
357        }
358        \tl_if_in:NnT  \l_tmpb_tl { MogaEx90Mincho } {
359          \prop_clear:N \l_tmpa_prop
360          \prop_map_inline:Nn \g_ltjpreset_font_prop {
361            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
362            \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
363          }
364          \prop_set_eq:NN \g_ltjpreset_font_prop \l_tmpa_prop
365        }
366     }
367   }
368   %%%%  リストからの展開
369   \cs_set:Nx \ltjpreset_font_mc_l:  { \prop_item:Nn \g_ltjpreset_font_prop { mc-l } }
370   \cs_set:Nx \ltjpreset_font_mc_m:  { \prop_item:Nn \g_ltjpreset_font_prop { mc-m } }
371   \cs_set:Nx \ltjpreset_font_mc_bx: { \prop_item:Nn \g_ltjpreset_font_prop { mc-bx } }
372   \cs_set:Nx \ltjpreset_font_gt_m:  { \prop_item:Nn \g_ltjpreset_font_prop { gt-m } }
373   \cs_set:Nx \ltjpreset_font_gt_u:  { \prop_item:Nn \g_ltjpreset_font_prop { gt-u } }
374   \cs_set:Nx \ltjpreset_font_gt_bx: { \prop_item:Nn \g_ltjpreset_font_prop { gt-bx } }
375   \cs_set:Nx \ltjpreset_font_gt_eb: { \prop_item:Nn \g_ltjpreset_font_prop { gt-eb } }
376   \cs_set:Nx \ltjpreset_font_mg_m:  { \prop_item:Nn \g_ltjpreset_font_prop { mg-m } }
377   %% HG 系フォント + JIS2004/90JIS のときはフォント名を置換
378   \bool_if:nT { !\g_ltjpreset_custom_bool && \g_ltjpreset_office_bool } {
379     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
380     \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
381       \cs_set:Nx \ltjpreset_font_mc_bx: { hgrme04.ttc }
382       \cs_set:Nx \ltjpreset_font_gt_bx: { hgrge04.ttc }
383       \cs_set:Nx \ltjpreset_font_gt_eb: { hgrsgu04.ttc }
384       \cs_set:Nx \ltjpreset_font_mg_m:  { hgrsmp04.ttf }
385       \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_u:
386       % HG ゴシックM のときはそうはいかないので 1 ウェイト時のゴシック体を使う
387     }
388     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
389     \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
390       \cs_set:Nx \ltjpreset_font_mc_bx: { hgrme.ttc }
391       \cs_set:Nx \ltjpreset_font_gt_bx: { hgrge.ttc }
392       \cs_set:Nx \ltjpreset_font_gt_eb: { hgrsgu.ttc }
393       \cs_set:Nx \ltjpreset_font_mg_m:  { hgrsmp.ttf }
394     }
395   }
396   % mc/l
397   \tl_set:Nx \l_tmpa_tl { \ltjpreset_font_mc_l: }
398   \tl_if_empty:NT \l_tmpa_tl {\tl_set:Nn \l_tmpa_tl {~}}
399   \cs_set:Nx \ltjpreset_font_mc_l: {
400     \tl_if_blank:nTF \l_tmpa_tl { \ltjpreset_font_mc_m: } {\tl_use:N \l_tmpa_tl }
401   }
402   %% bold オプションの処理
403   \bool_if:NTF \g_ltjpreset_deluxe_bool {
404     \bool_if:NT \g_ltjpreset_bold_bool {
405       \cs_set_eq:NN \ltjpreset_font_mc_bx: \ltjpreset_font_gt_bx:
406     }
407   }{
408     \bool_if:NTF \g_ltjpreset_bold_bool
409       { \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_bx: }
410       { \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_u: }
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 \g_ltjpreset_font_test: = "\cs:w ltjpreset_font_#1_#2: \cs_end:"\relax
421     \ifx \g_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 \g_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_set_eq:NN \ltjpreset_check_deluxe_existence: \prg_do_nothing:
444 }
445
446 \bool_if:NTF \g_ltjpreset_nfssonly_bool {
447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
448 %%%%%%%% nfss only
449   \msg_warning:nnx { luatexja-preset }{ scale }{ \Cjascale }
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*[\Cjascale]
454       { \bool_if:NT \g_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 \g_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 \g_ltjpreset_expert_bool { ;+vkna } }
464     \bool_if:NT \g_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 \g_ltjpreset_expert_bool {
479     \DeclareRobustCommand\rubyfamily { \kanjishape{rb}\selectfont }
480   }
481
482   \bool_if:NT \g_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 { ;+jp04 }
498     }
499     \ltj_preset_define_family:nnn {ltjpm} {m}  {\ltjpreset_font_mc_m:}
500     \ltj_preset_define_family:nnn {ltjpm} {bx} {\ltjpreset_font_mc_bx:}
501     \ltj_preset_define_family:nnn {ltjpm} {b}  {\ltjpreset_font_mc_bx:}
502     \ltj_preset_define_family:nnn {ltjpg} {m}  {\ltjpreset_font_gt_m:}
503     \ltj_preset_define_family:nnn {ltjpg} {bx} {\ltjpreset_font_gt_bx:}
504     \ltj_preset_define_family:nnn {ltjpg} {b}  {\ltjpreset_font_gt_bx:}
505     \normalfont
506     \bool_if:NT \g_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   \RequirePackage{luatexja-fontspec}
517   % scale
518   \msg_warning:nnx { luatexja-preset }{ scale }{ \Cjascale }
519   \tl_new:N \l_ltjpreset_add_features_tl
520
521   \bool_if:NT \g_ltjpreset_expert_bool {
522     \cs_set:Npn \rubyfamily { \addjfontfeatures {
523       Style=Ruby , YokoFeatures={RawFeature=-hkna} , TateFeatures={RawFeature=-vkna}
524     } }
525   }
526   \addjfontfeature{ Kerning=Off }
527   % 実際の fontspec の呼びだし
528   \cs_new:Nn \ltjpreset_do_fontset: { \group_begin:
529       \tl_gset:Nx \l_ltjpreset_add_features_tl {
530         \tl_use:N \l_ltjpreset_kanji_shape_tl,
531         YokoFeatures = { JFM = \tl_use:N \ltjpreset_use_jfm_yoko_tl },
532         TateFeatures = { JFM = \tl_use:N \ltjpreset_use_jfm_tate_tl },
533         Script=CJK, \bool_if:NT \g_ltjpreset_noembed_bool { , NoEmbed }
534       }
535     \group_end:
536     \bool_if:NT \g_ltjpreset_expert_bool {
537       \tl_put_left:Nn \l_ltjpreset_add_features_tl {
538         , YokoFeatures = {Style = HorizontalKana}, TateFeatures = {Style = VerticalKana}
539       }
540     }
541     \setmainjfont [
542       \bool_if:NT \g_ltjpreset_deluxe_bool { FontFace={l}{n}{\ltjpreset_font_mc_l:}, }
543       BoldFont = \ltjpreset_font_mc_bx: \tl_use:N \l_ltjpreset_add_features_tl
544     ] { \ltjpreset_font_mc_m: }
545     \setsansjfont [
546       \bool_if:NT \g_ltjpreset_deluxe_bool { FontFace={eb}{n}{\ltjpreset_font_gt_eb:}, }
547       BoldFont = \ltjpreset_font_gt_bx: \tl_use:N \l_ltjpreset_add_features_tl
548     ] { \ltjpreset_font_gt_m: }
549     \bool_if:NT \g_ltjpreset_deluxe_bool {
550       %% mg
551       \newjfontfamily \mgfamily [
552         BoldFont = \ltjpreset_font_mg_m: \tl_use:N \l_ltjpreset_add_features_tl
553       ] { \ltjpreset_font_mg_m: }
554       \DeclareTextFontCommand{\textmg}{\mgfamily}
555     }
556   }
557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
558 }
559
560 \def\ltjnewpreset{
561     \@ifstar{\ltjpreset_new_preset:nnn{ true }}{\ltjpreset_new_preset:nnn{ false }}}
562 \cs_set:Nn \ltjpreset_new_preset:nnn {
563   \keys_if_exist:nnTF { luatexja-preset } { #2 } {
564     \seq_if_in:NnTF \g_ltjpreset_presets_seq { #2 } {
565       \bool_if:cTF { c_ #1 _bool } {
566         \msg_warning:nnn { luatexja-preset }{ exist-preset-overwrite } { #2 }
567         \keys_define:nn { luatexja-preset } {
568         #2 .meta:n = { #3, __custom = true, __noembed = false, __office = false, },
569         #2 .value_forbidden:n = true, #2 .groups:n = { preset },
570         }
571       } {
572         \msg_error:nnn { luatexja-preset }{ exist-preset-nooverwrite } { #2 }
573       }
574     } {
575       \msg_error:nnn { luatexja-preset }{ illegal-preset-name } { #2 }
576     }
577   } {
578     \keys_define:nn { luatexja-preset } {
579       #2 .meta:n = { #3, __custom = true, __noembed = false, __office = false, },
580       #2 .value_forbidden:n = true, #2 .groups:n = { preset },
581     }
582     \seq_put_right:Nn \g_ltjpreset_presets_seq { #2 }
583   }
584 }
585
586 \cs_set:Npn \ltjapplypreset #1 {
587   \keys_set_groups:nnn { luatexja-preset } { preset } { #1 }
588   % \prop_map_inline:Nn \g_ltjpreset_font_prop {\typeout{ [##1] = "##2" } }
589   \ltjpreset_extract_fonts:
590   \ltjpreset_check_deluxe_existence:
591   \ltjpreset_do_fontset:
592   \normalfont
593 }
594
595 \ltjapplypreset {}
596
597 \@onlypreamble\ltjnewpreset
598 \@onlypreamble\ltjapplypreset
599
600 \ExplSyntaxOff
601
602 \endinput