OSDN Git Service

luatexja-preset: add preset noto and noto-jp
[luatex-ja/luatexja.git] / src / addons / luatexja-preset.sty
1 % luatexja-preset.sty
2 \ProvidesPackage{luatexja-preset}[2022-06-19 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     \PassOptionsToPackage { \l_keys_key_str } { luatexja-fontspec },
38   scale .code:n  = \gdef\Cjascale{#1},
39   match .code:n =
40     \renewcommand\jttdefault{\gtdefault}\@ltj@match@familytrue
41     \PassOptionsToPackage { match } { luatexja-fontspec },
42   match .value_forbidden:n = true,
43   __custom  .bool_set:N = \g__ltjpreset_custom_bool,  __custom  .groups:n = { preset },
44   __office  .bool_set:N = \g__ltjpreset_office_bool,  __office  .groups:n = { preset },
45   __noembed .bool_set:N = \g__ltjpreset_noembed_bool, __noembed .groups:n = { preset },
46 }
47 \cs_new:Nn \__ltjpreset_declare_option:nn {
48   \keys_define:nn { luatexja-preset }{
49     #1 .code:n = { #2 },
50     #1 .value_forbidden:n = true
51   }
52 }
53 \cs_new:Nn \ltjpreset_declare_preset:nn {
54   \keys_define:nn { luatexja-preset }{
55     #1 .meta:n = { #2 },
56     #1 .value_forbidden:n = true, #1 .groups:n = { preset },
57   }
58   \seq_put_right:Nn \g__ltjpreset_presets_seq { #1 }
59 }
60 \cs_generate_variant:Nn \ltjpreset_declare_preset:nn {nx}
61 \cs_new:Nn \__ltjpreset_declare_bool_option:nn {
62   \bool_new:c { g__ltjpreset_#1_bool }
63   \bool_set_false:c { g__ltjpreset_#1_bool }
64   \keys_define:nn { luatexja-preset }{
65     #1 .bool_set:c =  { g__ltjpreset_#1_bool },
66     #2 .bool_set_inverse:c =  { g__ltjpreset_#1_bool },
67     #1 .default:n =  true, #2 .default:n =  true,
68   }
69 }
70
71 %%%%%%%% bool options
72 \__ltjpreset_declare_bool_option:nn { nfssonly }{ fontspec }
73 \__ltjpreset_declare_bool_option:nn { bold }{ nobold }
74 \__ltjpreset_declare_bool_option:nn { expert }{ noexpert }
75 \__ltjpreset_declare_bool_option:nn { deluxe }{ nodeluxe }
76 \__ltjpreset_declare_bool_option:nn { nocheck }{ check }
77
78 % JFM
79 \tl_new:N \__ltjpreset_use_jfm_yoko_tl % 使用する JFM(横)
80 \tl_set:Nn \__ltjpreset_use_jfm_yoko_tl {\ltj@stdyokojfm}
81 \tl_new:N \__ltjpreset_use_jfm_tate_tl % 使用する JFM(縦)
82 \tl_set:Nn \__ltjpreset_use_jfm_tate_tl {\ltj@stdtatejfm}
83 \__ltjpreset_declare_option:nn{jis}{\tl_set:Nn  \__ltjpreset_use_jfm_yoko_tl {jis}}     % jis
84 \__ltjpreset_declare_option:nn{ujis}{\tl_set:Nn  \__ltjpreset_use_jfm_yoko_tl {ujis}}   % ujis
85
86 % 漢字字形
87 \tl_new:N \l__ltjpreset_kanji_shape_tl
88 \__ltjpreset_declare_option:nn{90jis}{  \tl_set:Nn \l__ltjpreset_kanji_shape_tl { , CJKShape=JIS1990 }} % 90jis
89 \__ltjpreset_declare_option:nn{jis90}{  \tl_set:Nn \l__ltjpreset_kanji_shape_tl { , CJKShape=JIS1990 }} % 90jis
90 \__ltjpreset_declare_option:nn{jis2004}{\tl_set:Nn \l__ltjpreset_kanji_shape_tl { , CJKShape=JIS2004 }} % jis2004
91 \__ltjpreset_declare_option:nn{2004jis}{\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-b } {#1},
100   mc .groups:n = { preset }, mc .value_required:n = true,
101   mc-bx .code:n =
102      \prop_put:Nnn \g__ltjpreset_font_prop { mc-b } {#1},
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-b } {#1}
107      \prop_put:Nnn \g__ltjpreset_font_prop { gt-eb } {#1},
108   gt-bx .code:n =
109      \prop_put:Nnn \g__ltjpreset_font_prop { gt-b } {#1},
110   gt-m .code:n = % gtfamily , medium series
111      \prop_put:Nnn \g__ltjpreset_font_prop { gt-u } {#1}
112      \prop_put:Nnn \g__ltjpreset_font_prop { gt-d } {#1},
113   gt .groups:n = { preset },   gt .value_required:n = true,
114   gt-m .groups:n = { preset }, gt-m .value_required:n = true,
115 }
116 \cs_set:Nn \ltjpreset_define_preset_prop:n {
117   \keys_define:nn { luatexja-preset } {
118     #1 .code:n = \prop_put:Non \g__ltjpreset_font_prop { #1 } { ##1 },
119     #1 .groups:n = { preset }, #1 .value_required:n = true,
120   }
121 }
122 \ltjpreset_define_preset_prop:n { mc-l }
123 \ltjpreset_define_preset_prop:n { mc-m }
124 \ltjpreset_define_preset_prop:n { mc-b }
125 \ltjpreset_define_preset_prop:n { gt-u }
126 \ltjpreset_define_preset_prop:n { gt-d }
127 \ltjpreset_define_preset_prop:n { gt-b }
128 \ltjpreset_define_preset_prop:n { gt-eb}
129 \ltjpreset_define_preset_prop:n { mg-m }
130
131 \cs_new:Nn \__ltjpreset_set_uni:nn {
132   mc = #1, gt = #2, mc-b = #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-b = HGMinchoE ,
137   gt-d = HGGothicM , gt-b = 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-b = KozMinPro-Bold,
157     gt-d =  KozGoPro-Regular,  gt-b = 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-b = KozMinProVI-Bold,
165     gt-d =  KozGoProVI-Regular,  gt-b = 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-b = KozMinPr6N-Bold,
173     gt-d =  KozGoPr6N-Regular,  gt-b = 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-b = HiraMinPro-W6,
182     gt-d = HiraKakuPro-W3, gt-b = 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-b = HiraMinProN-W6,
189     gt-d = HiraKakuProN-W3, gt-b = 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{bizud}{
197     mc =   BIZ-UDMinchoM.ttc,
198     gt-d = BIZ-UDGothicR.ttc, gt-b = BIZ-UDGothicB.ttc,
199     gt-u = BIZ-UDGothicR.ttc, gt-eb = BIZ-UDGothicB.ttc,
200     mg-m = BIZ-UDGothicB.ttc,
201     __custom = false, __office = false, __noembed = false,
202 }
203 \ltjpreset_declare_preset:nx{morisawa-pro}{
204     mc =   A-OTF-RyuminPro-Light.otf,      mc-b = A-OTF-FutoMinA101Pro-Bold.otf,
205     gt-d = A-OTF-GothicBBBPro-Medium.otf , gt-b = A-OTF-FutoGoB101Pro-Bold.otf,
206     gt-u = A-OTF-GothicBBBPro-Medium.otf , gt-eb = A-OTF-MidashiGoPro-MB31.otf,
207     mg-m = A-OTF-Jun101Pro-Light.otf,
208     __custom = false, __office = false, __noembed = false,
209 }
210 \ltjpreset_declare_preset:nx{morisawa-pr6n}{
211     mc =   A-OTF-RyuminPr6N-Light.otf,      mc-b = A-OTF-FutoMinA101Pr6N-Bold.otf,
212     gt-d = A-OTF-GothicBBBPr6N-Medium.otf , gt-b = A-OTF-FutoGoB101Pr6N-Bold.otf,
213     gt-u = A-OTF-GothicBBBPr6N-Medium.otf , gt-eb = A-OTF-MidashiGoPr6N-MB31.otf,
214     mg-m = A-OTF-ShinMGoPr6N-Light.otf,
215     __custom = false, __office = false, __noembed = false,
216 }
217
218 % 游明朝/游ゴシック (Win8.1)
219 \ltjpreset_declare_preset:nx{yu-win}{
220     mc-m = YuMincho-Regular, mc-b = YuMincho-Demibold,
221     gt-d = YuGothic-Regular, gt-b = YuGothic-Bold,
222     gt-u = YuGothic-Regular, gt-eb = YuGothic-Bold,
223     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light,
224     __custom = false, __office = false, __noembed = false,
225 }
226 % Win10
227 \ltjpreset_declare_preset:nx{yu-win10}{
228     mc-m = YuMincho-Regular, mc-b = YuMincho-Demibold,
229     gt-d = YuGothic-Regular, gt-b = YuGothic-Bold,
230     gt-u = YuGothic-Medium,  gt-eb = YuGothic-Bold,
231     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light,
232     __custom = false, __office = false, __noembed = false,
233 }
234
235 % Yu fonts in OSX
236 % according to http://support.apple.com/kb/HT5944
237 \ltjpreset_declare_preset:nx{yu-osx}{
238     mc =  YuMincho~Medium,   mc-b = YuMincho~Demibold,
239     gt-d =  YuGothic~Medium, gt-u =  YuGothic~Medium,
240     gt-b = YuGothic~Bold,    gt-eb = YuGothic~Bold,
241     mg-m =  YuGothic~Bold,
242     __custom = false, __office = false, __noembed = false,
243 }
244
245 % moga-mobo
246 \ltjpreset_declare_preset:nx{moga-mobo}{
247     mc =   Moga90Mincho, mc-b = Moga90Mincho~Bold,
248     gt-d = Moga90Gothic, gt-b = Moga90Gothic~Bold,
249     gt-u = Moga90Gothic, gt-eb = Moga90Gothic~Bold,
250     mg-m = Mobo90Gothic,
251     __custom = false, __office = false, __noembed = false,
252 }
253 \ltjpreset_declare_preset:nx{moga-mobo-ex}{
254     mc =   MogaEx90Mincho, mc-b = MogaEx90Mincho~Bold,
255     gt-d = MogaEx90Gothic, gt-b = MogaEx90Gothic~Bold,
256     gt-u = MogaEx90Gothic, gt-eb = MogaEx90Gothic~Bold,
257     mg-m = MoboEx90Gothic,
258     __custom = false, __office = false, __noembed = false,
259 }
260
261 % Ume fones
262 \ltjpreset_declare_preset:nx{ume}{
263     mc = Ume~Mincho,
264     gt-d = Ume~Gothic,    gt-b = Ume~Gothic~O5,
265     gt-u = Ume~Gothic~O5, gt-eb = Ume~Gothic~O5,
266     mg-m = Ume~Gothic~O4,
267     __custom = false, __office = false, __noembed = false,
268 }
269
270 % Source Han {Serif,Sans}
271 \ltjpreset_declare_preset:nx{sourcehan}{
272     mc-m =  Source~Han~Serif~Regular,
273     mc-b =  Source~Han~Serif~Bold,
274     gt-d =  Source~Han~Sans~Regular,
275     gt-b =  Source~Han~Sans~Bold,
276     gt-u =  Source~Han~Sans~Medium,
277     gt-eb = Source~Han~Sans~Heavy,
278     mg-m =  Source~Han~Sans~Medium,
279     mc-l =  Source~Han~Serif~Light,
280     __custom = false, __office = false, __noembed = false,
281 }
282 \ltjpreset_declare_preset:nx{sourcehan-jp}{
283     mc-m =  Source~Han~Serif~JP~Regular,
284     mc-b =  Source~Han~Serif~JP~Bold,
285     gt-d =  Source~Han~Sans~JP~Regular,
286     gt-b =  Source~Han~Sans~JP~Bold,
287     gt-u =  Source~Han~Sans~JP~Medium,
288     gt-eb = Source~Han~Sans~JP~Heavy,
289     mg-m =  Source~Han~Sans~JP~Medium,
290     mc-l =  Source~Han~Serif~JP~Light,
291     __custom = false, __office = false, __noembed = false,
292 }
293 \ltjpreset_declare_preset:nx{noto-otc}{
294     mc-m =  Noto~Serif~CJK~Regular,
295     mc-b =  Noto~Serif~CJK~Bold,
296     gt-d =  Noto~Sans~CJK~Regular,
297     gt-b =  Noto~Sans~CJK~Bold,
298     gt-u =  Noto~Sans~CJK~Medium,
299     gt-eb = Noto~Sans~CJK~Black,
300     mg-m =  Noto~Sans~CJK~Medium,
301     mc-l =  Noto~Serif~CJK~Light,
302     __custom = false, __office = false, __noembed = false,
303 }
304 \ltjpreset_declare_preset:nx{noto-otf}{
305     mc-m =  Noto~Serif~CJK~JP~Regular,
306     mc-b =  Noto~Serif~CJK~JP~Bold,
307     gt-d =  Noto~Sans~CJK~JP~Regular,
308     gt-b =  Noto~Sans~CJK~JP~Bold,
309     gt-u =  Noto~Sans~CJK~JP~Medium,
310     gt-eb = Noto~Sans~CJK~JP~Black,
311     mg-m =  Noto~Sans~CJK~JP~Medium,
312     mc-l =  Noto~Serif~CJK~JP~Light,
313     __custom = false, __office = false, __noembed = false,
314 }
315 \ltjpreset_declare_preset:nx{noto}{
316     noto-otf,
317 }
318 \ltjpreset_declare_preset:nx{noto-jp}{
319     mc-m =  Noto~Serif~JP~Regular,
320     mc-b =  Noto~Serif~JP~Bold,
321     gt-d =  Noto~Sans~JP~Regular,
322     gt-b =  Noto~Sans~JP~Bold,
323     gt-u =  Noto~Sans~JP~Medium,
324     gt-eb = Noto~Sans~JP~Black,
325     mg-m =  Noto~Sans~JP~Medium,
326     mc-l =  Noto~Serif~JP~Light,
327     __custom = false, __office = false, __noembed = false,
328 }
329
330 % HaranoAji {Mincho, Gothic}
331 \ltjpreset_declare_preset:nx{haranoaji}{
332     mc-m =  HaranoAjiMincho-Regular.otf,
333     mc-b =  HaranoAjiMincho-Bold.otf,
334     gt-d =  HaranoAjiGothic-Regular.otf,
335     gt-b =  HaranoAjiGothic-Bold.otf,
336     gt-u =  HaranoAjiGothic-Medium.otf,
337     gt-eb = HaranoAjiGothic-Heavy.otf,
338     mg-m =  HaranoAjiGothic-Medium.otf,
339     mc-l =  HaranoAjiMincho-Light.otf,
340     __custom = false, __office = false, __noembed = false,
341 }
342
343
344 % ipa, ipaex, ms
345 \ltjpreset_declare_preset:nx{ipa}{
346   \__ltjpreset_set_uni:nn { IPAMincho } { IPAGothic }
347 }
348 \ltjpreset_declare_preset:nx{ipaex}{
349   \__ltjpreset_set_uni:nn { IPAExMincho } { IPAExGothic }
350 }
351 \ltjpreset_declare_preset:nx{ms}{
352   \__ltjpreset_set_uni:nn { MS-Mincho } { MS-Gothic }
353 }
354
355 % {ipa,ipaex,ms}-dx % Office 付属フォントを利用
356 \ltjpreset_declare_preset:nx{ipaex-hg}{
357   \__ltjpreset_set_office:nn { IPAExMincho } { IPAExGothic }
358 }
359 \ltjpreset_declare_preset:nx{ipa-hg}{
360   \__ltjpreset_set_office:nn { IPAMincho } { IPAGothic }
361 }
362 \ltjpreset_declare_preset:nx{ms-hg}{
363   \__ltjpreset_set_office:nn { MS-Mincho } { MS-Gothic }
364 }
365
366
367 % 非埋込
368 \ltjpreset_declare_preset:nx{noembed}{
369   \__ltjpreset_set_uni:nn { Ryumin-Light } { GothicBBB-Medium },
370   __custom = false, __office = false, __noembed = true,
371 }
372
373 \keys_set:nn {luatexja-preset} { haranoaji } %% old: ipaex
374 \ProcessKeysOptions { luatexja-preset }
375 \@ifpackageloaded{luatexja-fontspec}{
376   \bool_if:NT \g__ltjpreset_nfssonly_bool
377     { \msg_warning:nn { luatexja-preset }{ ltj-fontspec } }
378   \bool_set_false:N \g__ltjpreset_nfssonly_bool
379 }{}
380
381 %%%%%%%% main routine
382
383 \cs_new:Nn \__ltjpreset_extract_fonts: {
384   %% MogaMincho の場合は 90 をつける/はずす
385   \bool_if:NF \g__ltjpreset_custom_bool {
386     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
387     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
388       \tl_set:Nx \l_tmpb_tl { \prop_item:Nn \g__ltjpreset_font_prop { mc-m } }
389       \tl_if_in:NnT  \l_tmpb_tl { Moga90Mincho } {
390         \prop_clear:N \l_tmpa_prop
391         \prop_map_inline:Nn \g__ltjpreset_font_prop {
392            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
393           \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
394          } 
395          \prop_set_eq:NN \g__ltjpreset_font_prop \l_tmpa_prop
396        }
397        \tl_if_in:NnT  \l_tmpb_tl { MogaEx90Mincho } {
398          \prop_clear:N \l_tmpa_prop
399          \prop_map_inline:Nn \g__ltjpreset_font_prop {
400            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
401            \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
402          }
403          \prop_set_eq:NN \g__ltjpreset_font_prop \l_tmpa_prop
404        }
405     }
406   }
407   %%%%  リストからの展開
408   \cs_set:Nx \__ltjpreset_font_mc_l:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-l } }
409   \cs_set:Nx \__ltjpreset_font_mc_m:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-m } }
410   \cs_set:Nx \__ltjpreset_font_mc_b:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-b } }
411   \cs_set:Nx \__ltjpreset_font_gt_m:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-d } }
412   \cs_set:Nx \__ltjpreset_font_gt_u:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-u } }
413   \cs_set:Nx \__ltjpreset_font_gt_b:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-b } }
414   \cs_set:Nx \__ltjpreset_font_gt_eb: { \prop_item:Nn \g__ltjpreset_font_prop { gt-eb } }
415   \cs_set:Nx \__ltjpreset_font_mg_m:  { \prop_item:Nn \g__ltjpreset_font_prop { mg-m } }
416   %% HG 系フォント + JIS2004/90JIS のときはフォント名を置換
417   \bool_if:nT { !\g__ltjpreset_custom_bool && \g__ltjpreset_office_bool } {
418     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
419     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
420       \cs_set:Nx \__ltjpreset_font_mc_b:  { hgrme04.ttc }
421       \cs_set:Nx \__ltjpreset_font_gt_b:  { hgrge04.ttc }
422       \cs_set:Nx \__ltjpreset_font_gt_eb: { hgrsgu04.ttc }
423       \cs_set:Nx \__ltjpreset_font_mg_m:  { hgrsmp04.ttf }
424       \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_u:
425       % HG ゴシックM のときはそうはいかないので 1 ウェイト時のゴシック体を使う
426     }
427     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
428     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
429       \cs_set:Nx \__ltjpreset_font_mc_b:  { hgrme.ttc }
430       \cs_set:Nx \__ltjpreset_font_gt_b:  { hgrge.ttc }
431       \cs_set:Nx \__ltjpreset_font_gt_eb: { hgrsgu.ttc }
432       \cs_set:Nx \__ltjpreset_font_mg_m:  { hgrsmp.ttf }
433     }
434   }
435   % mc/l
436   \tl_set:Nx \l_tmpa_tl { \__ltjpreset_font_mc_l: }
437   \tl_if_empty:NT \l_tmpa_tl {\tl_set:Nn \l_tmpa_tl {~}}
438   \cs_set:Nx \__ltjpreset_font_mc_l: {
439     \tl_if_blank:nTF \l_tmpa_tl { \__ltjpreset_font_mc_m: } {\tl_use:N \l_tmpa_tl }
440   }
441   %% bold オプションの処理
442   \bool_if:NTF \g__ltjpreset_deluxe_bool {
443     \bool_if:NT \g__ltjpreset_bold_bool {
444       \cs_set_eq:NN \__ltjpreset_font_mc_b: \__ltjpreset_font_gt_b:
445     }
446   }{
447     \bool_if:NTF \g__ltjpreset_bold_bool
448       { \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_b: }
449       { \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_u: }
450     \cs_set_eq:NN \__ltjpreset_font_gt_b: \__ltjpreset_font_gt_m:
451     \cs_set_eq:NN \__ltjpreset_font_mc_b: \__ltjpreset_font_gt_m:
452   }
453 }
454
455 %%%%%%%% フォント名を \l__ltjpreset_font_name: に格納
456 \clist_new:N \l__ltjpreset_extensions_clist
457 \clist_set:Nn \l__ltjpreset_extensions_clist {.otf,.ttf,.OTF,.TTF,.ttc,.TTC}
458 \prg_new_conditional:Nnn \__ltjpreset_if_detect_external:n {TF} {
459   \clist_map_inline:Nn \l__ltjpreset_extensions_clist {
460     \bool_set_false:N \l_tmpa_bool
461     \tl_if_in:nnT {#1 <= end_of_string} {##1 <= end_of_string}
462       { \bool_set_true:N \l_tmpa_bool \clist_map_break: }
463   }
464   \bool_if:NTF \l_tmpa_bool \prg_return_true: \prg_return_false:
465 }
466 \cs_new:Nn \__ltjpreset_wrap_fontname:n {
467   \__ltjpreset_if_detect_external:nTF { #1 }
468     { \cs_set:Nn \l__ltjpreset_font_name: { [#1] } }
469     { \cs_set:Nn \l__ltjpreset_font_name: { "#1" } }
470 }
471 \cs_generate_variant:Nn \__ltjpreset_wrap_fontname:n { e }
472
473 %%%%%%%% 存在判定
474 \cs_new:Nn \__ltjpreset_substitute:nnnn {
475   \group_begin:
476     \suppressfontnotfounderror=1
477     \cs_if_exist:cTF { __ltjpreset_font_#1_#2: } {
478       \bool_if:NF \g__ltjpreset_nocheck_bool {
479         \__ltjpreset_wrap_fontname:e { \cs:w __ltjpreset_font_#1_#2: \cs_end: }
480         \font \g__ltjpreset_font_test: = \l__ltjpreset_font_name:\relax
481         \ifx \g__ltjpreset_font_test: \nullfont
482           \msg_warning:nnxxxx { luatexja-preset }{ no-font }
483             { \cs:w __ltjpreset_font_#1_#2: \cs_end: }{ #1/#2 }
484             { \cs:w __ltjpreset_font_#3_#4: \cs_end: }{ #3/#4 }
485           \cs_gset_eq:cc { __ltjpreset_font_#1_#2: } { __ltjpreset_font_#3_#4: }
486         \fi
487       }
488     } { \cs_gset_eq:cc { __ltjpreset_font_#1_#2: } { __ltjpreset_font_#3_#4: } }
489   \group_end:
490 }
491
492 %%%%%%%% deluxe (\mgfamily はあとで定義)
493 \bool_if:NTF \g__ltjpreset_deluxe_bool {
494   \cs_new:Nn \__ltjpreset_check_deluxe_existence: {
495     \__ltjpreset_substitute:nnnn { gt } { eb } { gt } { b }
496     \__ltjpreset_substitute:nnnn { mg } { m  } { gt } { b }
497     \__ltjpreset_substitute:nnnn { mc } { l  } { mc } { m }
498   }
499   \def\ltdefault{l}
500   \DeclareRobustCommand\ltseries { \not@math@alphabet\ltseries\relax\fontseries\ltdefault\selectfont }
501   \def\ebdefault{eb}
502   \DeclareRobustCommand\ebseries { \not@math@alphabet\ebseries\relax\fontseries\ebdefault\selectfont }
503   \DeclareRobustCommand\gtebfamily { \gtfamily\fontseries{\ebdefault}\selectfont }
504   \DeclareTextFontCommand{\textlt}{\ltseries}
505   \DeclareTextFontCommand{\texteb}{\ebseries}
506 } {
507   \cs_set_eq:NN \__ltjpreset_check_deluxe_existence: \prg_do_nothing:
508 }
509
510 \int_new:N \g__ltjpreset_applycount_int
511
512 \bool_if:NTF \g__ltjpreset_nfssonly_bool {
513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
514 %%%%%%%% nfss only
515   \cs_if_exist:NF \Cjascale {
516     \group_begin:
517     \fontsize{16}{16}\selectfont
518     \cs_gset:Npx \Cjascale { \fp_to_decimal:n {\zw / 16} }
519     \group_end:
520   }
521
522   \msg_warning:nnx { luatexja-preset }{ scale }{ \Cjascale }
523
524   % {1: encoding}{2: family}{3: series}{4: shape}{5: fontname}{6: feature}{7: scale}
525   \cs_new:Nn \__ltjpreset_declare_font_shape:nnnnnnn {
526     \DeclareFontShape{#1}{#2}{#3}{#4}{ <-> s*[#7]
527       \bool_if:NT \g__ltjpreset_noembed_bool {psft:} #5
528       ;-kern \tl_use:N \l__ltjpreset_kanji_shape_tl; #6 } {}
529   }
530   \cs_new:Nn \__ltjpreset_define_family:nnn {
531         \__ltjpreset_wrap_fontname:e { #3 }
532     \__ltjpreset_declare_font_shape:nnnnnnn { JY3 }
533       { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { n }
534       { \l__ltjpreset_font_name: : jfm=\tl_use:N \__ltjpreset_use_jfm_yoko_tl }
535       { script=hani \bool_if:NT \g__ltjpreset_expert_bool { ;+hkna } }
536           { \Cjascale }
537     \__ltjpreset_declare_font_shape:nnnnnnn { JT3 }
538       { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { n }
539       { \l__ltjpreset_font_name:  : jfm=\tl_use:N \__ltjpreset_use_jfm_tate_tl }
540       { script=hani \bool_if:NT \g__ltjpreset_expert_bool { ;+vkna } }
541           { \Cjascale }
542     \bool_if:NT \g__ltjpreset_expert_bool {
543       \__ltjpreset_declare_font_shape:nnnnnnn { JY3 }
544         { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { rb }
545         { \l__ltjpreset_font_name:  : jfm=\tl_use:N \__ltjpreset_use_jfm_yoko_tl } { script=kana; +ruby }
546             { \Cjascale }
547       \__ltjpreset_declare_font_shape:nnnnnnn { JT3 }
548         { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { rb }
549         { \l__ltjpreset_font_name:  : jfm=\tl_use:N \__ltjpreset_use_jfm_tate_tl } { script=kana; +ruby }
550             { \Cjascale }
551     }
552     \cs_if_exist:NT \ltjpreset_define_family_hook_nfssonly:nnn
553       { \ltjpreset_define_family_hook_nfssonly:nnn { #1 } { #2 } { #3 } }
554   }
555   \bool_if:NT \g__ltjpreset_deluxe_bool {
556     \let\mgfamily\undefined
557     \DeclareRobustCommand\mgfamily {
558       \not@math@alphabet\mgfamily\relax
559       \kanjifamily{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}\selectfont
560     }
561     \DeclareTextFontCommand{\textmg}{\mgfamily}
562   }
563   \bool_if:NT \g__ltjpreset_expert_bool {
564     \DeclareRobustCommand\rubyfamily { \kanjishape{rb}\selectfont }
565   }
566   %
567   \cs_new:Nn \__ltjpreset_do_fontset: { \group_begin:
568     % ======
569     \xdef\mcdefault{ltjpmc \int_to_arabic:n { \g__ltjpreset_applycount_int }}
570     \xdef\gtdefault{ltjpgt \int_to_arabic:n { \g__ltjpreset_applycount_int }}
571     \DeclareKanjiFamily{JY3}{\mcdefault}{}
572     \DeclareKanjiFamily{JT3}{\mcdefault}{}
573     \DeclareKanjiFamily{JY3}{\gtdefault}{}
574     \DeclareKanjiFamily{JT3}{\gtdefault}{}
575     \unless\ifltj@disablejfam
576       \SetSymbolFont{mincho}{normal}{JY3}{\mcdefault}{m}{n}
577       \SetSymbolFont{mincho}{bold}{JY3}{\mcdefault}{b}{n}
578       \DeclareMathAlphabet{\mathgt}{JY3}{\gtdefault}{m}{n}
579     \fi
580     \bool_if:NT \g__ltjpreset_deluxe_bool {
581       \DeclareKanjiFamily{JY3}{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}{}
582       \DeclareKanjiFamily{JT3}{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}{}
583     }
584     % ======
585     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
586     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
587       \tl_set:Nn \l__ltjpreset_kanji_shape_tl { ;+jp90 }
588     }
589     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
590     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
591       \tl_set:Nx \l__ltjpreset_kanji_shape_tl { ;+jp04 }
592     }
593     \__ltjpreset_define_family:nnn {mc} {m}  {\__ltjpreset_font_mc_m:}
594     \__ltjpreset_define_family:nnn {mc} {bx} {\__ltjpreset_font_mc_b:}
595     \__ltjpreset_define_family:nnn {mc} {b}  {\__ltjpreset_font_mc_b:}
596     \__ltjpreset_define_family:nnn {gt} {m}  {\__ltjpreset_font_gt_m:}
597     \__ltjpreset_define_family:nnn {gt} {bx} {\__ltjpreset_font_gt_b:}
598     \__ltjpreset_define_family:nnn {gt} {b}  {\__ltjpreset_font_gt_b:}
599     \normalfont
600     \bool_if:NT \g__ltjpreset_deluxe_bool {
601       \__ltjpreset_define_family:nnn {mc}  {l} {\__ltjpreset_font_mc_l:}
602       \__ltjpreset_define_family:nnn {gt}  {eb} {\__ltjpreset_font_gt_eb:}
603       \__ltjpreset_define_family:nnn {mg} {m}  {\__ltjpreset_font_mg_m:}
604     }
605     \group_end:
606   }
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608 %%%%%%%% fontspec
609 } {
610   \RequirePackage{luatexja-fontspec}
611   % scale
612   \msg_warning:nnx { luatexja-preset }{ scale }{ \Cjascale }
613   \tl_new:N \l__ltjpreset_add_features_tl
614
615   \bool_if:NT \g__ltjpreset_expert_bool {
616     \cs_set:Npn \rubyfamily { \addjfontfeatures {
617       Style=Ruby , YokoFeatures={RawFeature=-hkna} , TateFeatures={RawFeature=-vkna}
618     } }
619   }
620   \addjfontfeature{ Kerning=Off }
621   % 実際の fontspec の呼びだし
622   \cs_new:Nn \__ltjpreset_do_fontset: { \group_begin:
623       \tl_gset:Nx \l__ltjpreset_add_features_tl {
624         \tl_use:N \l__ltjpreset_kanji_shape_tl,
625         YokoFeatures = { JFM = \tl_use:N \__ltjpreset_use_jfm_yoko_tl },
626         TateFeatures = { JFM = \tl_use:N \__ltjpreset_use_jfm_tate_tl },
627         Script=CJK, \bool_if:NT \g__ltjpreset_noembed_bool { , NoEmbed }
628       }
629     \group_end:
630     \bool_if:NT \g__ltjpreset_expert_bool {
631       \tl_put_left:Nn \l__ltjpreset_add_features_tl {
632         , YokoFeatures = {Style = HorizontalKana}, TateFeatures = {Style = VerticalKana}
633       }
634     }
635     \setmainjfont [
636       \bool_if:NT \g__ltjpreset_deluxe_bool {
637             FontFace={l}{n}{ Font = \__ltjpreset_font_mc_l:,
638           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
639             \ltjpreset_define_family_hook_fontspec:nnn
640                           { mc } { l } { \__ltjpreset_font_mc_l: }
641               }
642                 },
643           }
644       BoldFont = \__ltjpreset_font_mc_b: \tl_use:N \l__ltjpreset_add_features_tl,
645       \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
646                 UprightFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
647                   { mc } { m } { \__ltjpreset_font_mc_m: } },
648                 BoldFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
649                   { mc } { b } { \__ltjpreset_font_mc_b: } },
650           }
651     ] { \__ltjpreset_font_mc_m: }
652     \setsansjfont [
653       \bool_if:NT \g__ltjpreset_deluxe_bool {
654                 FontFace={eb}{n}{ Font = \__ltjpreset_font_gt_eb:,
655           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
656             \ltjpreset_define_family_hook_fontspec:nnn
657                           { gt } { eb } { \__ltjpreset_font_gt_eb: }
658               }
659             },
660           }
661       BoldFont = \__ltjpreset_font_gt_b: \tl_use:N \l__ltjpreset_add_features_tl,
662       \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
663                 UprightFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
664                   { gt } { m } { \__ltjpreset_font_gt_m: } },
665                 BoldFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
666                   { gt } { b } { \__ltjpreset_font_gt_b: } },
667           }
668     ] { \__ltjpreset_font_gt_m: }
669     \bool_if:NT \g__ltjpreset_deluxe_bool {
670       %% mg
671       \bool_if_exist:NTF \setfontfamily {
672         \setjfontfamily \mgfamily [
673           BoldFont = \__ltjpreset_font_mg_m: \tl_use:N \l__ltjpreset_add_features_tl,
674           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
675                     \ltjpreset_define_family_hook_fontspec:nnn
676                       { mg } { m } { \__ltjpreset_font_mg_m: },
677           }
678         ] { \__ltjpreset_font_mg_m: }
679       } {
680         \newjfontfamily \mgfamily [
681           BoldFont = \__ltjpreset_font_mg_m: \tl_use:N \l__ltjpreset_add_features_tl,
682           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
683                     \ltjpreset_define_family_hook_fontspec:nnn
684                       { mg } { m } { \__ltjpreset_font_mg_m: },
685           }
686         ] { \__ltjpreset_font_mg_m: }
687       }
688       \DeclareTextFontCommand{\textmg}{\mgfamily}
689     }
690   }
691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
692 }
693
694 \def\ltjnewpreset{
695     \@ifstar{\__ltjpreset_new_preset:nnn{ true }}{\__ltjpreset_new_preset:nnn{ false }}}
696 \cs_set:Nn \__ltjpreset_new_preset:nnn {
697   \keys_if_exist:nnTF { luatexja-preset } { #2 } {
698     \seq_if_in:NnTF \g__ltjpreset_presets_seq { #2 } {
699       \bool_if:cTF { c_ #1 _bool } {
700         \msg_warning:nnn { luatexja-preset }{ exist-preset-overwrite } { #2 }
701         \keys_define:nn { luatexja-preset } {
702         #2 .meta:n = { #3, __custom = true, __noembed = false, __office = false, },
703         #2 .value_forbidden:n = true, #2 .groups:n = { preset },
704         }
705       } {
706         \msg_error:nnn { luatexja-preset }{ exist-preset-nooverwrite } { #2 }
707       }
708     } {
709       \msg_error:nnn { luatexja-preset }{ illegal-preset-name } { #2 }
710     }
711   } {
712     \keys_define:nn { luatexja-preset } {
713       #2 .meta:n = { #3, __custom = true, __noembed = false, __office = false, },
714       #2 .value_forbidden:n = true, #2 .groups:n = { preset },
715     }
716     \seq_put_right:Nn \g__ltjpreset_presets_seq { #2 }
717   }
718 }
719
720
721 \cs_set:Npn \ltjapplypreset #1 {
722   \int_gincr:N \g__ltjpreset_applycount_int
723   \keys_set_groups:nnn { luatexja-preset } { preset } { #1 }
724   % \prop_map_inline:Nn \g__ltjpreset_font_prop {\typeout{ [##1] = "##2" } }
725   \__ltjpreset_extract_fonts:
726   \__ltjpreset_check_deluxe_existence:
727   \__ltjpreset_do_fontset:
728   \normalfont
729 }
730
731 \ltjapplypreset {}
732
733 \@onlypreamble\ltjnewpreset
734 \@onlypreamble\ltjapplypreset
735
736 \ExplSyntaxOff
737
738 \endinput