OSDN Git Service

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