OSDN Git Service

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