OSDN Git Service

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