OSDN Git Service

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