OSDN Git Service

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