OSDN Git Service

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