OSDN Git Service

fix '(linebreak): invalid list tail, probably missing glue' error
[luatex-ja/luatexja.git] / src / addons / luatexja-preset.sty
1 % luatexja-preset.sty
2 \ProvidesPackage{luatexja-preset}[2020-09-14 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-Jun101Pr6N-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
316 % HaranoAji {Mincho, Gothic}
317 \ltjpreset_declare_preset:nx{haranoaji}{
318     mc-m =  HaranoAjiMincho-Regular.otf,
319     mc-b =  HaranoAjiMincho-Bold.otf,
320     gt-d =  HaranoAjiGothic-Regular.otf,
321     gt-b =  HaranoAjiGothic-Bold.otf,
322     gt-u =  HaranoAjiGothic-Medium.otf,
323     gt-eb = HaranoAjiGothic-Heavy.otf,
324     mg-m =  HaranoAjiGothic-Medium.otf,
325     mc-l =  HaranoAjiMincho-Light.otf,
326     __custom = false, __office = false, __noembed = false,
327 }
328
329
330 % ipa, ipaex, ms
331 \ltjpreset_declare_preset:nx{ipa}{
332   \__ltjpreset_set_uni:nn { IPAMincho } { IPAGothic }
333 }
334 \ltjpreset_declare_preset:nx{ipaex}{
335   \__ltjpreset_set_uni:nn { IPAExMincho } { IPAExGothic }
336 }
337 \ltjpreset_declare_preset:nx{ms}{
338   \__ltjpreset_set_uni:nn { MS-Mincho } { MS-Gothic }
339 }
340
341 % {ipa,ipaex,ms}-dx % Office 付属フォントを利用
342 \ltjpreset_declare_preset:nx{ipaex-hg}{
343   \__ltjpreset_set_office:nn { IPAExMincho } { IPAExGothic }
344 }
345 \ltjpreset_declare_preset:nx{ipa-hg}{
346   \__ltjpreset_set_office:nn { IPAMincho } { IPAGothic }
347 }
348 \ltjpreset_declare_preset:nx{ms-hg}{
349   \__ltjpreset_set_office:nn { MS-Mincho } { MS-Gothic }
350 }
351
352
353 % 非埋込
354 \ltjpreset_declare_preset:nx{noembed}{
355   \__ltjpreset_set_uni:nn { Ryumin-Light } { GothicBBB-Medium },
356   __custom = false, __office = false, __noembed = true,
357 }
358
359 \keys_set:nn {luatexja-preset} { haranoaji } %% old: ipaex
360 \ProcessKeysOptions { luatexja-preset }
361 \@ifpackageloaded{luatexja-fontspec}{
362   \bool_if:NT \g__ltjpreset_nfssonly_bool
363     { \msg_warning:nn { luatexja-preset }{ ltj-fontspec } }
364   \bool_set_false:N \g__ltjpreset_nfssonly_bool
365 }{}
366
367 %%%%%%%% main routine
368
369 \cs_new:Nn \__ltjpreset_extract_fonts: {
370   %% MogaMincho の場合は 90 をつける/はずす
371   \bool_if:NF \g__ltjpreset_custom_bool {
372     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
373     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
374       \tl_set:Nx \l_tmpb_tl { \prop_item:Nn \g__ltjpreset_font_prop { mc-m } }
375       \tl_if_in:NnT  \l_tmpb_tl { Moga90Mincho } {
376         \prop_clear:N \l_tmpa_prop
377         \prop_map_inline:Nn \g__ltjpreset_font_prop {
378            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
379           \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
380          } 
381          \prop_set_eq:NN \g__ltjpreset_font_prop \l_tmpa_prop
382        }
383        \tl_if_in:NnT  \l_tmpb_tl { MogaEx90Mincho } {
384          \prop_clear:N \l_tmpa_prop
385          \prop_map_inline:Nn \g__ltjpreset_font_prop {
386            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
387            \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
388          }
389          \prop_set_eq:NN \g__ltjpreset_font_prop \l_tmpa_prop
390        }
391     }
392   }
393   %%%%  リストからの展開
394   \cs_set:Nx \__ltjpreset_font_mc_l:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-l } }
395   \cs_set:Nx \__ltjpreset_font_mc_m:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-m } }
396   \cs_set:Nx \__ltjpreset_font_mc_b:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-b } }
397   \cs_set:Nx \__ltjpreset_font_gt_m:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-d } }
398   \cs_set:Nx \__ltjpreset_font_gt_u:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-u } }
399   \cs_set:Nx \__ltjpreset_font_gt_b:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-b } }
400   \cs_set:Nx \__ltjpreset_font_gt_eb: { \prop_item:Nn \g__ltjpreset_font_prop { gt-eb } }
401   \cs_set:Nx \__ltjpreset_font_mg_m:  { \prop_item:Nn \g__ltjpreset_font_prop { mg-m } }
402   %% HG 系フォント + JIS2004/90JIS のときはフォント名を置換
403   \bool_if:nT { !\g__ltjpreset_custom_bool && \g__ltjpreset_office_bool } {
404     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
405     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
406       \cs_set:Nx \__ltjpreset_font_mc_b:  { hgrme04.ttc }
407       \cs_set:Nx \__ltjpreset_font_gt_b:  { hgrge04.ttc }
408       \cs_set:Nx \__ltjpreset_font_gt_eb: { hgrsgu04.ttc }
409       \cs_set:Nx \__ltjpreset_font_mg_m:  { hgrsmp04.ttf }
410       \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_u:
411       % HG ゴシックM のときはそうはいかないので 1 ウェイト時のゴシック体を使う
412     }
413     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
414     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
415       \cs_set:Nx \__ltjpreset_font_mc_b:  { hgrme.ttc }
416       \cs_set:Nx \__ltjpreset_font_gt_b:  { hgrge.ttc }
417       \cs_set:Nx \__ltjpreset_font_gt_eb: { hgrsgu.ttc }
418       \cs_set:Nx \__ltjpreset_font_mg_m:  { hgrsmp.ttf }
419     }
420   }
421   % mc/l
422   \tl_set:Nx \l_tmpa_tl { \__ltjpreset_font_mc_l: }
423   \tl_if_empty:NT \l_tmpa_tl {\tl_set:Nn \l_tmpa_tl {~}}
424   \cs_set:Nx \__ltjpreset_font_mc_l: {
425     \tl_if_blank:nTF \l_tmpa_tl { \__ltjpreset_font_mc_m: } {\tl_use:N \l_tmpa_tl }
426   }
427   %% bold オプションの処理
428   \bool_if:NTF \g__ltjpreset_deluxe_bool {
429     \bool_if:NT \g__ltjpreset_bold_bool {
430       \cs_set_eq:NN \__ltjpreset_font_mc_b: \__ltjpreset_font_gt_b:
431     }
432   }{
433     \bool_if:NTF \g__ltjpreset_bold_bool
434       { \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_b: }
435       { \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_u: }
436     \cs_set_eq:NN \__ltjpreset_font_gt_b: \__ltjpreset_font_gt_m:
437     \cs_set_eq:NN \__ltjpreset_font_mc_b: \__ltjpreset_font_gt_m:
438   }
439 }
440
441 %%%%%%%% フォント名を \l__ltjpreset_font_name: に格納
442 \clist_new:N \l__ltjpreset_extensions_clist
443 \clist_set:Nn \l__ltjpreset_extensions_clist {.otf,.ttf,.OTF,.TTF,.ttc,.TTC}
444 \prg_new_conditional:Nnn \__ltjpreset_if_detect_external:n {TF} {
445   \clist_map_inline:Nn \l__ltjpreset_extensions_clist {
446     \bool_set_false:N \l_tmpa_bool
447     \tl_if_in:nnT {#1 <= end_of_string} {##1 <= end_of_string}
448       { \bool_set_true:N \l_tmpa_bool \clist_map_break: }
449   }
450   \bool_if:NTF \l_tmpa_bool \prg_return_true: \prg_return_false:
451 }
452 \cs_new:Nn \__ltjpreset_wrap_fontname:n {
453   \__ltjpreset_if_detect_external:nTF { #1 }
454     { \cs_set:Nn \l__ltjpreset_font_name: { [#1] } }
455     { \cs_set:Nn \l__ltjpreset_font_name: { "#1" } }
456 }
457 \cs_generate_variant:Nn \__ltjpreset_wrap_fontname:n { e }
458
459 %%%%%%%% 存在判定
460 \cs_new:Nn \__ltjpreset_substitute:nnnn {
461   \group_begin:
462     \suppressfontnotfounderror=1
463     \cs_if_exist:cTF { __ltjpreset_font_#1_#2: } {
464       \bool_if:NF \g__ltjpreset_nocheck_bool {
465         \__ltjpreset_wrap_fontname:e { \cs:w __ltjpreset_font_#1_#2: \cs_end: }
466         \font \g__ltjpreset_font_test: = \l__ltjpreset_font_name:\relax
467         \ifx \g__ltjpreset_font_test: \nullfont
468           \msg_warning:nnxxxx { luatexja-preset }{ no-font }
469             { \cs:w __ltjpreset_font_#1_#2: \cs_end: }{ #1/#2 }
470             { \cs:w __ltjpreset_font_#3_#4: \cs_end: }{ #3/#4 }
471           \cs_gset_eq:cc { __ltjpreset_font_#1_#2: } { __ltjpreset_font_#3_#4: }
472         \fi
473       }
474     } { \cs_gset_eq:cc { __ltjpreset_font_#1_#2: } { __ltjpreset_font_#3_#4: } }
475   \group_end:
476 }
477
478 %%%%%%%% deluxe (\mgfamily はあとで定義)
479 \bool_if:NTF \g__ltjpreset_deluxe_bool {
480   \cs_new:Nn \__ltjpreset_check_deluxe_existence: {
481     \__ltjpreset_substitute:nnnn { gt } { eb } { gt } { b }
482     \__ltjpreset_substitute:nnnn { mg } { m  } { gt } { b }
483     \__ltjpreset_substitute:nnnn { mc } { l  } { mc } { m }
484   }
485   \def\ltdefault{l}
486   \DeclareRobustCommand\ltseries { \not@math@alphabet\ltseries\relax\fontseries\ltdefault\selectfont }
487   \def\ebdefault{eb}
488   \DeclareRobustCommand\ebseries { \not@math@alphabet\ebseries\relax\fontseries\ebdefault\selectfont }
489   \DeclareRobustCommand\gtebfamily { \gtfamily\fontseries{\ebdefault}\selectfont }
490   \DeclareTextFontCommand{\textlt}{\ltseries}
491   \DeclareTextFontCommand{\texteb}{\ebseries}
492 } {
493   \cs_set_eq:NN \__ltjpreset_check_deluxe_existence: \prg_do_nothing:
494 }
495
496 \int_new:N \g__ltjpreset_applycount_int
497
498 \bool_if:NTF \g__ltjpreset_nfssonly_bool {
499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500 %%%%%%%% nfss only
501   \cs_if_exist:NF \Cjascale {
502     \group_begin:
503     \fontsize{16}{16}\selectfont
504     \cs_gset:Npx \Cjascale { \fp_to_decimal:n {\zw / 16} }
505     \group_end:
506   }
507
508   \msg_warning:nnx { luatexja-preset }{ scale }{ \Cjascale }
509
510   % {1: encoding}{2: family}{3: series}{4: shape}{5: fontname}{6: feature}{7: scale}
511   \cs_new:Nn \__ltjpreset_declare_font_shape:nnnnnnn {
512     \DeclareFontShape{#1}{#2}{#3}{#4}{ <-> s*[#7]
513       \bool_if:NT \g__ltjpreset_noembed_bool {psft:} #5
514       ;-kern \tl_use:N \l__ltjpreset_kanji_shape_tl; #6 } {}
515   }
516   \cs_new:Nn \__ltjpreset_define_family:nnn {
517         \__ltjpreset_wrap_fontname:e { #3 }
518     \__ltjpreset_declare_font_shape:nnnnnnn { JY3 }
519       { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { n }
520       { \l__ltjpreset_font_name: : jfm=\tl_use:N \__ltjpreset_use_jfm_yoko_tl }
521       { script=hani \bool_if:NT \g__ltjpreset_expert_bool { ;+hkna } }
522           { \Cjascale }
523     \__ltjpreset_declare_font_shape:nnnnnnn { JT3 }
524       { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { n }
525       { \l__ltjpreset_font_name:  : jfm=\tl_use:N \__ltjpreset_use_jfm_tate_tl }
526       { script=hani \bool_if:NT \g__ltjpreset_expert_bool { ;+vkna } }
527           { \Cjascale }
528     \bool_if:NT \g__ltjpreset_expert_bool {
529       \__ltjpreset_declare_font_shape:nnnnnnn { JY3 }
530         { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { rb }
531         { \l__ltjpreset_font_name:  : jfm=\tl_use:N \__ltjpreset_use_jfm_yoko_tl } { script=kana; +ruby }
532             { \Cjascale }
533       \__ltjpreset_declare_font_shape:nnnnnnn { JT3 }
534         { ltjp #1 \int_to_arabic:n { \g__ltjpreset_applycount_int }} { #2 } { rb }
535         { \l__ltjpreset_font_name:  : jfm=\tl_use:N \__ltjpreset_use_jfm_tate_tl } { script=kana; +ruby }
536             { \Cjascale }
537     }
538     \cs_if_exist:NT \ltjpreset_define_family_hook_nfssonly:nnn
539       { \ltjpreset_define_family_hook_nfssonly:nnn { #1 } { #2 } { #3 } }
540   }
541   \bool_if:NT \g__ltjpreset_deluxe_bool {
542     \let\mgfamily\undefined
543     \DeclareRobustCommand\mgfamily {
544       \not@math@alphabet\mgfamily\relax
545       \kanjifamily{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}\selectfont
546     }
547     \DeclareTextFontCommand{\textmg}{\mgfamily}
548   }
549   \bool_if:NT \g__ltjpreset_expert_bool {
550     \DeclareRobustCommand\rubyfamily { \kanjishape{rb}\selectfont }
551   }
552   %
553   \cs_new:Nn \__ltjpreset_do_fontset: { \group_begin:
554     % ======
555     \xdef\mcdefault{ltjpmc \int_to_arabic:n { \g__ltjpreset_applycount_int }}
556     \xdef\gtdefault{ltjpgt \int_to_arabic:n { \g__ltjpreset_applycount_int }}
557     \DeclareKanjiFamily{JY3}{\mcdefault}{}
558     \DeclareKanjiFamily{JT3}{\mcdefault}{}
559     \DeclareKanjiFamily{JY3}{\gtdefault}{}
560     \DeclareKanjiFamily{JT3}{\gtdefault}{}
561     \unless\ifltj@disablejfam
562       \SetSymbolFont{mincho}{normal}{JY3}{\mcdefault}{m}{n}
563       \SetSymbolFont{mincho}{bold}{JY3}{\mcdefault}{b}{n}
564       \DeclareMathAlphabet{\mathgt}{JY3}{\gtdefault}{m}{n}
565     \fi
566     \bool_if:NT \g__ltjpreset_deluxe_bool {
567       \DeclareKanjiFamily{JY3}{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}{}
568       \DeclareKanjiFamily{JT3}{ltjpmg \int_to_arabic:n { \g__ltjpreset_applycount_int }}{}
569     }
570     % ======
571     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
572     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
573       \tl_set:Nn \l__ltjpreset_kanji_shape_tl { ;+jp90 }
574     }
575     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
576     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
577       \tl_set:Nx \l__ltjpreset_kanji_shape_tl { ;+jp04 }
578     }
579     \__ltjpreset_define_family:nnn {mc} {m}  {\__ltjpreset_font_mc_m:}
580     \__ltjpreset_define_family:nnn {mc} {bx} {\__ltjpreset_font_mc_b:}
581     \__ltjpreset_define_family:nnn {mc} {b}  {\__ltjpreset_font_mc_b:}
582     \__ltjpreset_define_family:nnn {gt} {m}  {\__ltjpreset_font_gt_m:}
583     \__ltjpreset_define_family:nnn {gt} {bx} {\__ltjpreset_font_gt_b:}
584     \__ltjpreset_define_family:nnn {gt} {b}  {\__ltjpreset_font_gt_b:}
585     \normalfont
586     \bool_if:NT \g__ltjpreset_deluxe_bool {
587       \__ltjpreset_define_family:nnn {mc}  {l} {\__ltjpreset_font_mc_l:}
588       \__ltjpreset_define_family:nnn {gt}  {eb} {\__ltjpreset_font_gt_eb:}
589       \__ltjpreset_define_family:nnn {mg} {m}  {\__ltjpreset_font_mg_m:}
590     }
591     \group_end:
592   }
593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
594 %%%%%%%% fontspec
595 } {
596   \RequirePackage{luatexja-fontspec}
597   % scale
598   \msg_warning:nnx { luatexja-preset }{ scale }{ \Cjascale }
599   \tl_new:N \l__ltjpreset_add_features_tl
600
601   \bool_if:NT \g__ltjpreset_expert_bool {
602     \cs_set:Npn \rubyfamily { \addjfontfeatures {
603       Style=Ruby , YokoFeatures={RawFeature=-hkna} , TateFeatures={RawFeature=-vkna}
604     } }
605   }
606   \addjfontfeature{ Kerning=Off }
607   % 実際の fontspec の呼びだし
608   \cs_new:Nn \__ltjpreset_do_fontset: { \group_begin:
609       \tl_gset:Nx \l__ltjpreset_add_features_tl {
610         \tl_use:N \l__ltjpreset_kanji_shape_tl,
611         YokoFeatures = { JFM = \tl_use:N \__ltjpreset_use_jfm_yoko_tl },
612         TateFeatures = { JFM = \tl_use:N \__ltjpreset_use_jfm_tate_tl },
613         Script=CJK, \bool_if:NT \g__ltjpreset_noembed_bool { , NoEmbed }
614       }
615     \group_end:
616     \bool_if:NT \g__ltjpreset_expert_bool {
617       \tl_put_left:Nn \l__ltjpreset_add_features_tl {
618         , YokoFeatures = {Style = HorizontalKana}, TateFeatures = {Style = VerticalKana}
619       }
620     }
621     \setmainjfont [
622       \bool_if:NT \g__ltjpreset_deluxe_bool {
623             FontFace={l}{n}{ Font = \__ltjpreset_font_mc_l:,
624           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
625             \ltjpreset_define_family_hook_fontspec:nnn
626                           { mc } { l } { \__ltjpreset_font_mc_l: }
627               }
628                 },
629           }
630       BoldFont = \__ltjpreset_font_mc_b: \tl_use:N \l__ltjpreset_add_features_tl,
631       \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
632                 UprightFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
633                   { mc } { m } { \__ltjpreset_font_mc_m: } },
634                 BoldFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
635                   { mc } { b } { \__ltjpreset_font_mc_b: } },
636           }
637     ] { \__ltjpreset_font_mc_m: }
638     \setsansjfont [
639       \bool_if:NT \g__ltjpreset_deluxe_bool {
640                 FontFace={eb}{n}{ Font = \__ltjpreset_font_gt_eb:,
641           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
642             \ltjpreset_define_family_hook_fontspec:nnn
643                           { gt } { eb } { \__ltjpreset_font_gt_eb: }
644               }
645             },
646           }
647       BoldFont = \__ltjpreset_font_gt_b: \tl_use:N \l__ltjpreset_add_features_tl,
648       \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
649                 UprightFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
650                   { gt } { m } { \__ltjpreset_font_gt_m: } },
651                 BoldFeatures = { \ltjpreset_define_family_hook_fontspec:nnn
652                   { gt } { b } { \__ltjpreset_font_gt_b: } },
653           }
654     ] { \__ltjpreset_font_gt_m: }
655     \bool_if:NT \g__ltjpreset_deluxe_bool {
656       %% mg
657       \bool_if_exist:NTF \setfontfamily {
658         \setjfontfamily \mgfamily [
659           BoldFont = \__ltjpreset_font_mg_m: \tl_use:N \l__ltjpreset_add_features_tl,
660           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
661                     \ltjpreset_define_family_hook_fontspec:nnn
662                       { mg } { m } { \__ltjpreset_font_mg_m: },
663           }
664         ] { \__ltjpreset_font_mg_m: }
665       } {
666         \newjfontfamily \mgfamily [
667           BoldFont = \__ltjpreset_font_mg_m: \tl_use:N \l__ltjpreset_add_features_tl,
668           \cs_if_exist:NT \ltjpreset_define_family_hook_fontspec:nnn {
669                     \ltjpreset_define_family_hook_fontspec:nnn
670                       { mg } { m } { \__ltjpreset_font_mg_m: },
671           }
672         ] { \__ltjpreset_font_mg_m: }
673       }
674       \DeclareTextFontCommand{\textmg}{\mgfamily}
675     }
676   }
677 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678 }
679
680 \def\ltjnewpreset{
681     \@ifstar{\__ltjpreset_new_preset:nnn{ true }}{\__ltjpreset_new_preset:nnn{ false }}}
682 \cs_set:Nn \__ltjpreset_new_preset:nnn {
683   \keys_if_exist:nnTF { luatexja-preset } { #2 } {
684     \seq_if_in:NnTF \g__ltjpreset_presets_seq { #2 } {
685       \bool_if:cTF { c_ #1 _bool } {
686         \msg_warning:nnn { luatexja-preset }{ exist-preset-overwrite } { #2 }
687         \keys_define:nn { luatexja-preset } {
688         #2 .meta:n = { #3, __custom = true, __noembed = false, __office = false, },
689         #2 .value_forbidden:n = true, #2 .groups:n = { preset },
690         }
691       } {
692         \msg_error:nnn { luatexja-preset }{ exist-preset-nooverwrite } { #2 }
693       }
694     } {
695       \msg_error:nnn { luatexja-preset }{ illegal-preset-name } { #2 }
696     }
697   } {
698     \keys_define:nn { luatexja-preset } {
699       #2 .meta:n = { #3, __custom = true, __noembed = false, __office = false, },
700       #2 .value_forbidden:n = true, #2 .groups:n = { preset },
701     }
702     \seq_put_right:Nn \g__ltjpreset_presets_seq { #2 }
703   }
704 }
705
706
707 \cs_set:Npn \ltjapplypreset #1 {
708   \int_gincr:N \g__ltjpreset_applycount_int
709   \keys_set_groups:nnn { luatexja-preset } { preset } { #1 }
710   % \prop_map_inline:Nn \g__ltjpreset_font_prop {\typeout{ [##1] = "##2" } }
711   \__ltjpreset_extract_fonts:
712   \__ltjpreset_check_deluxe_existence:
713   \__ltjpreset_do_fontset:
714   \normalfont
715 }
716
717 \ltjapplypreset {}
718
719 \@onlypreamble\ltjnewpreset
720 \@onlypreamble\ltjapplypreset
721
722 \ExplSyntaxOff
723
724 \endinput