OSDN Git Service

c0a58cd9c45493695114cd8610bdccd62be09180
[luatex-ja/luatexja.git] / src / addons / luatexja-preset.sty
1 % luatexja-preset.sty
2 \ProvidesPackage{luatexja-preset}[2020-05-15 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-b } {#1},
102   mc .groups:n = { preset }, mc .value_required:n = true,
103   mc-bx .code:n =
104      \prop_put:Nnn \g__ltjpreset_font_prop { mc-b } {#1},
105   gt .code:n =
106      \prop_put:Nnn \g__ltjpreset_font_prop { gt-u } {#1}
107      \prop_put:Nnn \g__ltjpreset_font_prop { gt-d } {#1}
108      \prop_put:Nnn \g__ltjpreset_font_prop { gt-b } {#1}
109      \prop_put:Nnn \g__ltjpreset_font_prop { gt-eb } {#1},
110   gt-bx .code:n =
111      \prop_put:Nnn \g__ltjpreset_font_prop { gt-b } {#1},
112   gt-m .code:n = % gtfamily , medium series
113      \prop_put:Nnn \g__ltjpreset_font_prop { gt-u } {#1}
114      \prop_put:Nnn \g__ltjpreset_font_prop { gt-d } {#1},
115   % gt-d, gt-u は隠し
116   gt .groups:n = { preset },   gt .value_required:n = true,
117   gt-m .groups:n = { preset }, gt-m .value_required:n = true,
118 }
119 \cs_set:Nn \ltjpreset_define_preset_prop:n {
120   \keys_define:nn { luatexja-preset } {
121     #1 .code:n = \prop_put:Non \g__ltjpreset_font_prop { #1 } { ##1 },
122     #1 .groups:n = { preset }, #1 .value_required:n = true,
123   }
124 }
125 \ltjpreset_define_preset_prop:n { mc-l }
126 \ltjpreset_define_preset_prop:n { mc-m }
127 \ltjpreset_define_preset_prop:n { mc-b }
128 \ltjpreset_define_preset_prop:n { gt-u }
129 \ltjpreset_define_preset_prop:n { gt-d }
130 \ltjpreset_define_preset_prop:n { gt-b }
131 \ltjpreset_define_preset_prop:n { gt-eb}
132 \ltjpreset_define_preset_prop:n { mg-m }
133
134 \cs_new:Nn \__ltjpreset_set_uni:nn {
135   mc = #1, gt = #2, mc-b = #2, mg-m = #2,
136   __custom = false, __office = false, __noembed = false,
137 }
138 \cs_new:Npn \__ltjpreset_set_office:nn #1 #2{
139   mc   = #1,         mc-b = HGMinchoE ,
140   gt-d = HGGothicM , gt-b = HGGothicE ,
141   gt-u = #2 ,        gt-eb = HGSoeiKakugothicUB ,
142   mg-m = HGMaruGothicMPRO,
143   __custom = false, __office = true, __noembed = false,
144 }
145
146 %%%%%%%% プリセット達
147
148 % カスタム指定
149  \keys_define:nn { luatexja-preset }{
150     custom .meta:n = { #1, __custom = true, }, 
151     custom .value_required:n = true,
152     jfm_yoko .tl_set:N = \__ltjpreset_use_jfm_yoko_tl,
153     jfm_tate .tl_set:N = \__ltjpreset_use_jfm_tate_tl,
154 }
155
156 % 小塚 (Adobe)
157 %% Pro
158 \ltjpreset_declare_preset:nx{kozuka-pro}{
159     mc-m =  KozMinPro-Regular, mc-b = KozMinPro-Bold,
160     gt-d =  KozGoPro-Regular,  gt-b = KozGoPro-Bold,
161     gt-u =  KozGoPro-Medium,   gt-eb = KozGoPro-Heavy,
162     mg-m =  KozGoPro-Heavy,    mc-l =  KozMinPro-Light,
163     __custom = false, __office = false, __noembed = false,
164 }
165 %% Pr6
166 \ltjpreset_declare_preset:nx{kozuka-pr6}{
167     mc-m =  KozMinProVI-Regular, mc-b = KozMinProVI-Bold,
168     gt-d =  KozGoProVI-Regular,  gt-b = KozGoProVI-Bold,
169     gt-u =  KozGoProVI-Medium,   gt-eb = KozGoProVI-Heavy,
170     mg-m =  KozGoProVI-Heavy,    mc-l =  KozMinProVI-Light,
171     __custom = false, __office = false, __noembed = false,
172 }
173 %% Pr6N
174 \ltjpreset_declare_preset:nx{kozuka-pr6n}{
175     mc-m =  KozMinPr6N-Regular, mc-b = KozMinPr6N-Bold,
176     gt-d =  KozGoPr6N-Regular,  gt-b = KozGoPr6N-Bold,
177     gt-u =  KozGoPr6N-Medium,   gt-eb = KozGoPr6N-Heavy,
178     mg-m =  KozGoPr6N-Heavy,    mc-l =  KozMinPr6N-Light,
179     __custom = false, __office = false, __noembed = false,
180 }
181
182 % ヒラギノ (OSX)
183 \ltjpreset_declare_preset:nx{hiragino-pro}{
184     mc-m = HiraMinPro-W3,  mc-b = HiraMinPro-W6,
185     gt-d = HiraKakuPro-W3, gt-b = HiraKakuPro-W6,
186     gt-u = HiraKakuPro-W6, gt-eb = HiraKakuStd-W8,
187     mg-m = HiraMaruPro-W4, mc-l =  HiraMinPro-W2,
188     __custom = false, __office = false, __noembed = false,
189 }
190 \ltjpreset_declare_preset:nx{hiragino-pron}{
191     mc-m = HiraMinProN-W3,  mc-b = HiraMinProN-W6,
192     gt-d = HiraKakuProN-W3, gt-b = HiraKakuProN-W6,
193     gt-u = HiraKakuProN-W6, gt-eb = HiraKakuStdN-W8,
194     mg-m = HiraMaruProN-W4, mc-l =  HiraMinProN-W2,
195     __custom = false, __office = false, __noembed = false,
196 }
197
198 % モリサワ
199 \ltjpreset_declare_preset:nx{bizud}{
200     mc =   BIZ-UDMinchoM.ttc,
201     gt-d = BIZ-UDGothicR.ttc, gt-b = BIZ-UDGothicB.ttc,
202     gt-u = BIZ-UDGothicR.ttc, gt-eb = BIZ-UDGothicB.ttc,
203     mg-m = BIZ-UDGothicB.ttc,
204     __custom = false, __office = false, __noembed = false,
205 }
206 \ltjpreset_declare_preset:nx{morisawa-pro}{
207     mc =   A-OTF-RyuminPro-Light.otf,      mc-b = A-OTF-FutoMinA101Pro-Bold.otf,
208     gt-d = A-OTF-GothicBBBPro-Medium.otf , gt-b = A-OTF-FutoGoB101Pro-Bold.otf,
209     gt-u = A-OTF-GothicBBBPro-Medium.otf , gt-eb = A-OTF-MidashiGoPro-MB31.otf,
210     mg-m = A-OTF-Jun101Pro-Light.otf,
211     __custom = false, __office = false, __noembed = false,
212 }
213 \ltjpreset_declare_preset:nx{morisawa-pr6n}{
214     mc =   A-OTF-RyuminPr6N-Light.otf,      mc-b = A-OTF-FutoMinA101Pr6N-Bold.otf,
215     gt-d = A-OTF-GothicBBBPr6N-Medium.otf , gt-b = A-OTF-FutoGoB101Pr6N-Bold.otf,
216     gt-u = A-OTF-GothicBBBPr6N-Medium.otf , gt-eb = A-OTF-MidashiGoPr6N-MB31.otf,
217     mg-m = A-OTF-Jun101Pr6N-Light.otf,
218     __custom = false, __office = false, __noembed = false,
219 }
220
221 % 游明朝/游ゴシック (Win8.1)
222 \ltjpreset_declare_preset:nx{yu-win}{
223     mc-m = YuMincho-Regular, mc-b = YuMincho-Demibold,
224     gt-d = YuGothic-Regular, gt-b = YuGothic-Bold,
225     gt-u = YuGothic-Regular, gt-eb = YuGothic-Bold,
226     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light,
227     __custom = false, __office = false, __noembed = false,
228 }
229 % Win10
230 \ltjpreset_declare_preset:nx{yu-win10}{
231     mc-m = YuMincho-Regular, mc-b = YuMincho-Demibold,
232     gt-d = YuGothic-Regular, gt-b = YuGothic-Bold,
233     gt-u = YuGothic-Medium,  gt-eb = YuGothic-Bold,
234     mg-m = YuGothic-Bold,    mc-l =  YuMincho-Light,
235     __custom = false, __office = false, __noembed = false,
236 }
237
238 % Yu fonts in OSX
239 % according to http://support.apple.com/kb/HT5944
240 \ltjpreset_declare_preset:nx{yu-osx}{
241     mc =  YuMincho~Medium,   mc-b = YuMincho~Demibold,
242     gt-d =  YuGothic~Medium, gt-u =  YuGothic~Medium,
243     gt-b = YuGothic~Bold,    gt-eb = YuGothic~Bold,
244     mg-m =  YuGothic~Bold,
245     __custom = false, __office = false, __noembed = false,
246 }
247
248 % moga-mobo
249 \ltjpreset_declare_preset:nx{moga-mobo}{
250     mc =   Moga90Mincho, mc-b = Moga90Mincho~Bold,
251     gt-d = Moga90Gothic, gt-b = Moga90Gothic~Bold,
252     gt-u = Moga90Gothic, gt-eb = Moga90Gothic~Bold,
253     mg-m = Mobo90Gothic,
254     __custom = false, __office = false, __noembed = false,
255 }
256 \ltjpreset_declare_preset:nx{moga-mobo-ex}{
257     mc =   MogaEx90Mincho, mc-b = MogaEx90Mincho~Bold,
258     gt-d = MogaEx90Gothic, gt-b = MogaEx90Gothic~Bold,
259     gt-u = MogaEx90Gothic, gt-eb = MogaEx90Gothic~Bold,
260     mg-m = MoboEx90Gothic,
261     __custom = false, __office = false, __noembed = false,
262 }
263
264 % Ume fones
265 \ltjpreset_declare_preset:nx{ume}{
266     mc = Ume~Mincho,
267     gt-d = Ume~Gothic,    gt-b = Ume~Gothic~O5,
268     gt-u = Ume~Gothic~O5, gt-eb = Ume~Gothic~O5,
269     mg-m = Ume~Gothic~O4,
270     __custom = false, __office = false, __noembed = false,
271 }
272
273 % Source Han {Serif,Sans}
274 \ltjpreset_declare_preset:nx{sourcehan}{
275     mc-m =  Source~Han~Serif~Regular,
276     mc-b =  Source~Han~Serif~Bold,
277     gt-d =  Source~Han~Sans~Regular,
278     gt-b =  Source~Han~Sans~Bold,
279     gt-u =  Source~Han~Sans~Medium,
280     gt-eb = Source~Han~Sans~Heavy,
281     mg-m =  Source~Han~Sans~Medium,
282     mc-l =  Source~Han~Serif~Light,
283     __custom = false, __office = false, __noembed = false,
284 }
285 \ltjpreset_declare_preset:nx{sourcehan-jp}{
286     mc-m =  Source~Han~Serif~JP~Regular,
287     mc-b =  Source~Han~Serif~JP~Bold,
288     gt-d =  Source~Han~Sans~JP~Regular,
289     gt-b =  Source~Han~Sans~JP~Bold,
290     gt-u =  Source~Han~Sans~JP~Medium,
291     gt-eb = Source~Han~Sans~JP~Heavy,
292     mg-m =  Source~Han~Sans~JP~Medium,
293     mc-l =  Source~Han~Serif~JP~Light,
294     __custom = false, __office = false, __noembed = false,
295 }
296 \ltjpreset_declare_preset:nx{noto-otc}{
297     mc-m =  Noto~Serif~CJK~Regular,
298     mc-b =  Noto~Serif~CJK~Bold,
299     gt-d =  Noto~Sans~CJK~Regular,
300     gt-b =  Noto~Sans~CJK~Bold,
301     gt-u =  Noto~Sans~CJK~Medium,
302     gt-eb = Noto~Sans~CJK~Black,
303     mg-m =  Noto~Sans~CJK~Medium,
304     mc-l =  Noto~Serif~CJK~Light,
305     __custom = false, __office = false, __noembed = false,
306 }
307 \ltjpreset_declare_preset:nx{noto-otf}{
308     mc-m =  Noto~Serif~CJK~JP~Regular,
309     mc-b =  Noto~Serif~CJK~JP~Bold,
310     gt-d =  Noto~Sans~CJK~JP~Regular,
311     gt-b =  Noto~Sans~CJK~JP~Bold,
312     gt-u =  Noto~Sans~CJK~JP~Medium,
313     gt-eb = Noto~Sans~CJK~JP~Black,
314     mg-m =  Noto~Sans~CJK~JP~Medium,
315     mc-l =  Noto~Serif~CJK~JP~Light,
316     __custom = false, __office = false, __noembed = false,
317 }
318
319 % HaranoAji {Mincho, Gothic}
320 \ltjpreset_declare_preset:nx{haranoaji}{
321     mc-m =  HaranoAjiMincho-Regular.otf,
322     mc-b =  HaranoAjiMincho-Bold.otf,
323     gt-d =  HaranoAjiGothic-Regular.otf,
324     gt-b =  HaranoAjiGothic-Bold.otf,
325     gt-u =  HaranoAjiGothic-Medium.otf,
326     gt-eb = HaranoAjiGothic-Heavy.otf,
327     mg-m =  HaranoAjiGothic-Medium.otf,
328     mc-l =  HaranoAjiMincho-Light.otf,
329     __custom = false, __office = false, __noembed = false,
330 }
331
332
333 % ipa, ipaex, ms
334 \ltjpreset_declare_preset:nx{ipa}{
335   \__ltjpreset_set_uni:nn { IPAMincho } { IPAGothic }
336 }
337 \ltjpreset_declare_preset:nx{ipaex}{
338   \__ltjpreset_set_uni:nn { IPAExMincho } { IPAExGothic }
339 }
340 \ltjpreset_declare_preset:nx{ms}{
341   \__ltjpreset_set_uni:nn { MS-Mincho } { MS-Gothic }
342 }
343
344 % {ipa,ipaex,ms}-dx % Office 付属フォントを利用
345 \ltjpreset_declare_preset:nx{ipaex-hg}{
346   \__ltjpreset_set_office:nn { IPAExMincho } { IPAExGothic }
347 }
348 \ltjpreset_declare_preset:nx{ipa-hg}{
349   \__ltjpreset_set_office:nn { IPAMincho } { IPAGothic }
350 }
351 \ltjpreset_declare_preset:nx{ms-hg}{
352   \__ltjpreset_set_office:nn { MS-Mincho } { MS-Gothic }
353 }
354
355
356 % 非埋込
357 \ltjpreset_declare_preset:nx{noembed}{
358   \__ltjpreset_set_uni:nn { Ryumin-Light } { GothicBBB-Medium },
359   __custom = false, __office = false, __noembed = true,
360 }
361
362 \keys_set:nn {luatexja-preset} { haranoaji } %% old: ipaex
363 \ProcessKeysOptions { luatexja-preset }
364 \@ifpackageloaded{luatexja-fontspec}{
365   \bool_if:NT \g__ltjpreset_nfssonly_bool
366     { \msg_warning:nn { luatexja-preset }{ ltj-fontspec } }
367   \bool_set_false:N \g__ltjpreset_nfssonly_bool
368 }{}
369
370 %%%%%%%% main routine
371
372 \cs_new:Nn \__ltjpreset_extract_fonts: {
373   %% MogaMincho の場合は 90 をつける/はずす
374   \bool_if:NF \g__ltjpreset_custom_bool {
375     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
376     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
377       \tl_set:Nx \l_tmpb_tl { \prop_item:Nn \g__ltjpreset_font_prop { mc-m } }
378       \tl_if_in:NnT  \l_tmpb_tl { Moga90Mincho } {
379         \prop_clear:N \l_tmpa_prop
380         \prop_map_inline:Nn \g__ltjpreset_font_prop {
381            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
382           \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
383          } 
384          \prop_set_eq:NN \g__ltjpreset_font_prop \l_tmpa_prop
385        }
386        \tl_if_in:NnT  \l_tmpb_tl { MogaEx90Mincho } {
387          \prop_clear:N \l_tmpa_prop
388          \prop_map_inline:Nn \g__ltjpreset_font_prop {
389            \tl_set:Nn \l_tmpb_tl { ##2 } \tl_remove_all:Nn \l_tmpb_tl {90}
390            \prop_put:Nnx \l_tmpa_prop { ##1 } { \tl_use:N \l_tmpb_tl }
391          }
392          \prop_set_eq:NN \g__ltjpreset_font_prop \l_tmpa_prop
393        }
394     }
395   }
396   %%%%  リストからの展開
397   \cs_set:Nx \__ltjpreset_font_mc_l:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-l } }
398   \cs_set:Nx \__ltjpreset_font_mc_m:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-m } }
399   \cs_set:Nx \__ltjpreset_font_mc_b:  { \prop_item:Nn \g__ltjpreset_font_prop { mc-b } }
400   \cs_set:Nx \__ltjpreset_font_gt_m:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-d } }
401   \cs_set:Nx \__ltjpreset_font_gt_u:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-u } }
402   \cs_set:Nx \__ltjpreset_font_gt_b:  { \prop_item:Nn \g__ltjpreset_font_prop { gt-b } }
403   \cs_set:Nx \__ltjpreset_font_gt_eb: { \prop_item:Nn \g__ltjpreset_font_prop { gt-eb } }
404   \cs_set:Nx \__ltjpreset_font_mg_m:  { \prop_item:Nn \g__ltjpreset_font_prop { mg-m } }
405   %% HG 系フォント + JIS2004/90JIS のときはフォント名を置換
406   \bool_if:nT { !\g__ltjpreset_custom_bool && \g__ltjpreset_office_bool } {
407     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
408     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
409       \cs_set:Nx \__ltjpreset_font_mc_b:  { hgrme04.ttc }
410       \cs_set:Nx \__ltjpreset_font_gt_b:  { hgrge04.ttc }
411       \cs_set:Nx \__ltjpreset_font_gt_eb: { hgrsgu04.ttc }
412       \cs_set:Nx \__ltjpreset_font_mg_m:  { hgrsmp04.ttf }
413       \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_u:
414       % HG ゴシックM のときはそうはいかないので 1 ウェイト時のゴシック体を使う
415     }
416     \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
417     \tl_if_eq:NNT \l__ltjpreset_kanji_shape_tl \l_tmpa_tl {
418       \cs_set:Nx \__ltjpreset_font_mc_b:  { hgrme.ttc }
419       \cs_set:Nx \__ltjpreset_font_gt_b:  { hgrge.ttc }
420       \cs_set:Nx \__ltjpreset_font_gt_eb: { hgrsgu.ttc }
421       \cs_set:Nx \__ltjpreset_font_mg_m:  { hgrsmp.ttf }
422     }
423   }
424   % mc/l
425   \tl_set:Nx \l_tmpa_tl { \__ltjpreset_font_mc_l: }
426   \tl_if_empty:NT \l_tmpa_tl {\tl_set:Nn \l_tmpa_tl {~}}
427   \cs_set:Nx \__ltjpreset_font_mc_l: {
428     \tl_if_blank:nTF \l_tmpa_tl { \__ltjpreset_font_mc_m: } {\tl_use:N \l_tmpa_tl }
429   }
430   %% bold オプションの処理
431   \bool_if:NTF \g__ltjpreset_deluxe_bool {
432     \bool_if:NT \g__ltjpreset_bold_bool {
433       \cs_set_eq:NN \__ltjpreset_font_mc_b: \__ltjpreset_font_gt_b:
434     }
435   }{
436     \bool_if:NTF \g__ltjpreset_bold_bool
437       { \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_b: }
438       { \cs_set_eq:NN \__ltjpreset_font_gt_m: \__ltjpreset_font_gt_u: }
439     \cs_set_eq:NN \__ltjpreset_font_gt_b: \__ltjpreset_font_gt_m:
440     \cs_set_eq:NN \__ltjpreset_font_mc_b: \__ltjpreset_font_gt_m:
441   }
442 }
443
444 %%%%%%%% フォント名を \l__ltjpreset_font_name: に格納
445 \clist_new:N \l__ltjpreset_extensions_clist
446 \clist_set:Nn \l__ltjpreset_extensions_clist {.otf,.ttf,.OTF,.TTF,.ttc,.TTC}
447 \prg_new_conditional:Nnn \__ltjpreset_if_detect_external:n {TF} {
448   \clist_map_inline:Nn \l__ltjpreset_extensions_clist {
449     \bool_set_false:N \l_tmpa_bool
450     \tl_if_in:nnT {#1 <= end_of_string} {##1 <= end_of_string}
451       { \bool_set_true:N \l_tmpa_bool \clist_map_break: }
452   }
453   \bool_if:NTF \l_tmpa_bool \prg_return_true: \prg_return_false:
454 }
455 \cs_new:Nn \__ltjpreset_wrap_fontname:n {
456   \__ltjpreset_if_detect_external:nTF { #1 }
457     { \cs_set:Nn \l__ltjpreset_font_name: { [#1] } }
458     { \cs_set:Nn \l__ltjpreset_font_name: { "#1" } }
459 }
460 \cs_generate_variant:Nn \__ltjpreset_wrap_fontname:n { e }
461
462 %%%%%%%% 存在判定
463 \cs_new:Nn \__ltjpreset_substitute:nnnn {
464   \group_begin:
465     \suppressfontnotfounderror=1
466     \cs_if_exist:cT {ltjpreset_font_#1_#2:} {
467       \__ltjpreset_wrap_fontname:e { \cs:w __ltjpreset_font_#1_#2: \cs_end: }
468       \font \g__ltjpreset_font_test: = \l__preset_font_name:\relax
469       \ifx \g__ltjpreset_font_test: \nullfont
470         \msg_warning:nnxxxx { luatexja-preset }{ no-font }
471           { \cs:w __ltjpreset_font_#1_#2: \cs_end: }{ #1/#2 }
472           { \cs:w __ltjpreset_font_#3_#4: \cs_end: }{ #3/#4 }
473         \cs_gset_eq:cc { __ltjpreset_font_#1_#2: } { __ltjpreset_font_#3_#4: }
474       \fi
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