OSDN Git Service

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