OSDN Git Service

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