OSDN Git Service

Cherry-picked several commits from kitagawa_tfont branch
[luatex-ja/luatexja.git] / src / addons / luatexja-preset.sty
1 % luatexja-preset.sty
2 \ProvidesPackage{luatexja-preset}[2014/12/03 Japanese font presets]
3
4 \RequirePackage{expl3}
5 \RequirePackage{luatexja-fontspec}
6 \ExplSyntaxOn
7
8 %%%% message
9
10 \bool_new:N \l_ltjpreset_bold_bool % bold
11 \bool_set_false:N \l_ltjpreset_bold_bool
12 \DeclareOption{bold}  {\bool_set_true:N \l_ltjpreset_bold_bool}
13 \DeclareOption{nobold}{\bool_set_false:N \l_ltjpreset_bold_bool}
14
15 \bool_new:N \l_ltjpreset_expert_bool % expert
16 \bool_set_false:N \l_ltjpreset_expert_bool
17 \DeclareOption{expert}  {\bool_set_true:N \l_ltjpreset_expert_bool}
18 \DeclareOption{noexpert}{\bool_set_false:N \l_ltjpreset_expert_bool}
19
20 \int_new:N \l_ltjpreset_deluxe_int % expert
21 \int_set:Nn \l_ltjpreset_deluxe_int { 0 }
22 \DeclareOption{deluxe}{\int_set:Nn \l_ltjpreset_deluxe_int { 2 }}   % 6 fonts
23 \DeclareOption{nodeluxe}{\int_set:Nn \l_ltjpreset_deluxe_int { 0 }} % 2 fonts
24
25 % scale
26 \msg_new:nnn { luatexja-preset }{ scale }{
27   Japanese~fonts~will~be~scaled~by~\fp_use:N \g_ltj_fontspec_scale_fp.
28 }
29 \msg_warning:nn { luatexja-preset }{ scale }
30
31 % JFM
32 \cs_set:Npn \ltjpreset_use_jfm: {ujis}  % 使用する JFM
33 %%% \DeclareOption{min}{\cs_set:Npn  \ltjpreset_use_jfm: {min}} % min
34 %%% ↑jfm-min.lua が横組み・縦組み専用仮名に追いついていないので使用禁止
35 \DeclareOption{jis}{\cs_set:Npn  \ltjpreset_use_jfm: {jis}}     % jis
36 \DeclareOption{ujis}{\cs_set:Npn  \ltjpreset_use_jfm: {ujis}}   % ujis
37
38 % 漢字字形
39 \tl_new:N \l_ltjpreset_kanji_shape_tl
40 \DeclareOption{90jis}{  \tl_set:Nn \l_ltjpreset_kanji_shape_tl { , CJKShape=JIS1990 }} % 90jis
41 \DeclareOption{jis2004}{\tl_set:Nn \l_ltjpreset_kanji_shape_tl { , CJKShape=JIS2004 }} % jis2004
42
43 % font preset
44 \bool_new:N \l_ltjpreset_office_bool  % MS Office の HG 系フォントを使っているか
45 \bool_new:N \l_ltjpreset_noembed_bool % 非埋込か
46 \clist_new:N \l_ltjpreset_font_list
47
48 \cs_new:Npn \ltjpreset_set_uni:nn #1#2 {
49   \ltjpreset_set_multi:n { #1, #1, #2, #2, #2, #2, #1 }
50 }
51 \cs_new:Npn \ltjpreset_set_multi:n #1 {
52   \clist_set:Nn \l_ltjpreset_font_list { #1 }
53   \bool_set_false:N \l_ltjpreset_office_bool
54   \bool_set_false:N \l_ltjpreset_noembed_bool
55 }
56 \cs_new:Npn \ltjpreset_set_office:nn #1 #2{
57   \ltjpreset_set_multi:n {
58     #1, HGMinchoE ,           % mc/m, mc/bx
59     HGGothicM , HGGothicE ,   % gt/m, gt/bx (multiweight))
60     #2 , HGSoeiKakugothicUB , % gt/m (uni), gt/eb
61     HGMaruGothicMPRO          % mg/m
62   }
63   \bool_set_true:N \l_ltjpreset_office_bool
64 }
65
66
67 % 小塚 (Adobe)
68 %% Pro
69 \DeclareOption{kozuka-pro}{
70   \ltjpreset_set_multi:n {
71     KozMinPro-Regular , % mc/m
72     KozMinPro-Bold ,    % mc/bx
73     KozGoPro-Regular , % gt/m  (multi)
74     KozGoPro-Bold ,    % gt/bx
75     KozGoPro-Medium  , % gt/m  (uni)
76     KozGoPro-Heavy ,   % gt/eb
77     KozGoPro-Heavy     % mg/m
78   }
79 }
80 %% Pr6
81 \DeclareOption{kozuka-pr6}{
82   \ltjpreset_set_multi:n {
83     KozMinProVI-Regular , % mc/m
84     KozMinProVI-Bold ,    % mc/bx
85     KozGoProVI-Regular , % gt/m  (multi)
86     KozGoProVI-Bold ,    % gt/bx
87     KozGoProVI-Medium  , % gt/m  (uni)
88     KozGoProVI-Heavy ,   % gt/eb
89     KozGoProVI-Heavy     % mg/m
90   }
91 }
92 %% Pr6N
93 \DeclareOption{kozuka-pr6n}{
94   \ltjpreset_set_multi:n {
95     KozMinPr6N-Regular , % mc/m
96     KozMinPr6N-Bold ,    % mc/bx
97     KozGoPr6N-Regular , % gt/m  (multi)
98     KozGoPr6N-Bold ,    % gt/bx
99     KozGoPr6N-Medium  , % gt/m  (uni)
100     KozGoPr6N-Heavy ,   % gt/eb
101     KozGoPr6N-Heavy     % mg/m
102   }
103 }
104
105 % ヒラギノ (OSX)
106 \DeclareOption{hiragino-pro}{
107   \ltjpreset_set_multi:n {
108     Hiragino~Mincho~Pro~W3 , 
109     Hiragino~Mincho~Pro~W6 , 
110     Hiragino~Kaku~Gothic~Pro~W3 , % gt/m (multi)
111     Hiragino~Kaku~Gothic~Pro~W6 , 
112     Hiragino~Kaku~Gothic~Pro~W6 , % gt/m (uni)
113     Hiragino~Kaku~Gothic~Std~W8 , 
114     Hiragino~Maru~Gothic~Pro~W4 , 
115   }
116 }
117 \DeclareOption{hiragino-pron}{
118   \ltjpreset_set_multi:n {
119     Hiragino~Mincho~ProN~W3 , 
120     Hiragino~Mincho~ProN~W6 , 
121     Hiragino~Kaku~Gothic~ProN~W3 , % gt/m (multi)
122     Hiragino~Kaku~Gothic~ProN~W6 , 
123     Hiragino~Kaku~Gothic~ProN~W6 , % gt/m (uni)
124     Hiragino~Kaku~Gothic~StdN~W8 , 
125     Hiragino~Maru~Gothic~ProN~W4 , 
126   }
127 }
128
129 % モリサワ
130 \DeclareOption{morisawa-pro}{
131   \ltjpreset_set_multi:n {
132     A-OTF-RyuminPro-Light.otf , A-OTF-FutoMinA101Pro-Bold.otf ,    % mc/m, mc/bx
133     A-OTF-GothicBBBPro-Medium.otf , A-OTF-FutoGoB101Pro-Bold.otf , % gt/m, gt/bx (multiweight))
134     A-OTF-GothicBBBPro-Medium.otf , A-OTF-MidashiGoPro-MB31.otf ,  % gt/m (uni), gt/eb
135     A-OTF-Jun101Pro-Light.otf % mg/m
136   }
137 }
138 \DeclareOption{morisawa-pr6n}{
139   \ltjpreset_set_multi:n {
140     A-OTF-RyuminPr6N-Light.otf , A-OTF-FutoMinA101Pr6N-Bold.otf ,    % mc/m, mc/bx
141     A-OTF-GothicBBBPr6N-Medium.otf , A-OTF-FutoGoB101Pr6N-Bold.otf , % gt/m, gt/bx (multiweight))
142     A-OTF-GothicBBBPr6N-Medium.otf , A-OTF-MidashiGoPr6N-MB31.otf ,  % gt/m (uni), gt/eb
143     A-OTF-ShinMGoPr6N-Light.otf                                      % mg/m
144   }
145 }
146
147 % 游明朝/游ゴシック (Win8.1)
148 \DeclareOption{yu-win}{
149   \ltjpreset_set_multi:n {
150     YuMincho-Regular , YuMincho-Demibold , % mc/m, mc/bx
151     YuGothic-Regular , YuGothic-Bold ,     % gt/m, gt/bx (multiweight))
152     YuGothic-Bold    , YuGothic-Bold ,     % gt/m (uni), gt/eb
153     YuGothic-Bold                          % mg/m
154   }
155 }
156
157 % Yu fonts in OSX
158 % according to http://support.apple.com/kb/HT5944
159 \DeclareOption{yu-osx}{
160   \ltjpreset_set_multi:n {
161     YuMincho~Medium , YuMincho~Demibold , % mc/m, mc/bx
162     YuGothic~Medium , YuGothic~Bold ,     % gt/m, gt/bx (multiweight))
163     YuGothic~Bold   , YuGothic~Bold ,     % gt/m (uni), gt/eb
164     YuGothic~Bold                          % mg/m
165   }
166 }
167
168 % ipa, ipaex, ms
169 \DeclareOption{ipa}{
170   \ltjpreset_set_uni:nn { IPAMincho } { IPAGothic }
171 }
172 \DeclareOption{ipaex}{
173   \ltjpreset_set_uni:nn { IPAExMincho } { IPAExGothic }
174 }
175 \DeclareOption{ms}{
176   \ltjpreset_set_uni:nn { MS-Mincho } { MS-Gothic }
177 }
178
179 % {ipa,ipaex,ms}-dx % Office 付属フォントを利用
180 \DeclareOption{ipaex-hg}{
181   \ltjpreset_set_office:nn { IPAExMincho } { IPAExGothic }
182 }
183 \DeclareOption{ipa-hg}{
184   \ltjpreset_set_office:nn { IPAMincho } { IPAGothic }
185 }
186 \DeclareOption{ms-hg}{
187   \ltjpreset_set_office:nn { MS-Mincho } { MS-Gothic }
188 }
189
190
191 % 非埋込
192 \DeclareOption{noembed}{
193   \ltjpreset_set_uni:nn { Ryumin-Light } { GothicBBB-Medium }
194   \bool_set_true:N \l_ltjpreset_noembed_bool
195 }
196
197 \ExecuteOptions{ipaex}
198
199 % match 
200 \DeclareOption{match} {
201   \bool_if:NF  \ltj_fontspec_match_bool {
202     \ltj_fontspec_match_cmd
203     \bool_set_true:N \ltj_fontspec_match_bool
204   }
205 }
206 \ProcessOptions*
207
208 %% KozMinPr6N の場合はjp04 feature がないので,nlck にする
209 \clist_if_in:NnT \l_ltjpreset_font_list { KozMinPr6N-Regular } {
210   \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
211   \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
212     \tl_set:Nn \l_ltjpreset_kanji_shape_tl { , CJKShape=NLC }
213   }
214 }
215
216 %% HiraMinProN の場合はjp04 feature がない??ので,nlck にする
217 \clist_if_in:NnT \l_ltjpreset_font_list { Hiragino~Mincho~ProN~W3 } {
218   \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
219   \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
220     \tl_set:Nn \l_ltjpreset_kanji_shape_tl { , CJKShape=NLC }
221   }
222 }
223
224 %%%%%%%% main routine
225
226 %%%%  リストからの展開
227 % mc/m
228 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
229 \cs_set:Nx \ltjpreset_font_mc_m: { \tl_use:N \l_tmpa_tl }
230
231 % mc/bx
232 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
233 \cs_set:Nx \ltjpreset_font_mc_bx: { \tl_use:N \l_tmpa_tl }
234
235 % gt/m
236 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
237 \cs_set:Nx \ltjpreset_font_gt_m: { \tl_use:N \l_tmpa_tl }
238
239 % gt/bx
240 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
241 \cs_set:Nx \ltjpreset_font_gt_bx: { \tl_use:N \l_tmpa_tl }
242
243 % gt/m-uni
244 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
245 \cs_set:Nx \ltjpreset_font_gt_n_uni: { \tl_use:N \l_tmpa_tl }
246
247 % gt/eb
248 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
249 \cs_set:Nx \ltjpreset_font_gt_eb: { \tl_use:N \l_tmpa_tl }
250
251 % mg/m
252 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
253 \cs_set:Nx \ltjpreset_font_mg: { \tl_use:N \l_tmpa_tl }
254
255 %% HG 系フォント + JIS2004/90JIS のときはフォント名を置換
256 \bool_if:NT \l_ltjpreset_office_bool {
257   \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS2004 }
258   \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl { 
259     \cs_set:Nx \ltjpreset_font_mc_bx: { hgrme04.ttc }
260     \cs_set:Nx \ltjpreset_font_gt_bx: { hgrge04.ttc }
261     \cs_set:Nx \ltjpreset_font_gt_eb: { hgrsgu04.ttc }
262     \cs_set:Nx \ltjpreset_font_mg:    { hgrsmp04.ttf }
263     \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_n_uni:
264     % HG ゴシックM のときはそうはいかないので 1 ウェイト時のゴシック体を使う
265   }
266   \tl_set:Nn \l_tmpa_tl {, CJKShape=JIS1990 }
267   \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl { 
268     \cs_set:Nx \ltjpreset_font_mc_bx: { hgrme.ttc }
269     \cs_set:Nx \ltjpreset_font_gt_bx: { hgrge.ttc }
270     \cs_set:Nx \ltjpreset_font_gt_eb: { hgrsgu.ttc }
271     \cs_set:Nx \ltjpreset_font_mg:    { hgrsmp.ttf }
272   }
273 }
274
275 % expert 用設定
276 \tl_new:N \l_ltjpreset_add_features_tl
277
278 \tl_set:Nx \l_ltjpreset_add_features_tl {
279   \tl_use:N \l_ltjpreset_kanji_shape_tl, 
280   JFM   = \ltjpreset_use_jfm:
281 }
282
283 \bool_if:NT \l_ltjpreset_expert_bool {
284   \cs_set:Npn \rubyfamily { \addfontfeatures { Style = Ruby} }
285   \tl_put_left:Nn \l_ltjpreset_add_features_tl { Style = HorizontalKana, }
286 }
287
288 % (丸)ゴシック体の設定: bold option もここで
289 \int_compare:nTF { \l_ltjpreset_deluxe_int ==  2 } {
290 %% mg
291  \newjfontfamily \mgfamily [
292       BoldFont = \ltjpreset_font_mg:,
293       \tl_use:N \l_ltjpreset_add_features_tl
294       \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed }, 
295       \tl_use:N \l_ltjpreset_add_features_tl 
296     ] { \ltjpreset_font_mg: }
297     \DeclareTextFontCommand{\textmg}{\mgfamily}
298 %% gt/eb
299 %% 注意: ファミリは 'gteb'.シリーズは \mdseries のまま.
300 %%       \bfseries を追加したほうが良い?
301   \newjfontfamily \gtebfamily [
302       BoldFont = \ltjpreset_font_gt_eb:, 
303       \tl_use:N \l_ltjpreset_add_features_tl
304       \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed }, 
305       \tl_use:N \l_ltjpreset_add_features_tl 
306     ] { \ltjpreset_font_gt_eb: }
307   \DeclareTextFontCommand{\textgteb}{\gtebfamily}
308   \bool_if:NT \l_ltjpreset_bold_bool {
309     \cs_set_eq:NN \ltjpreset_font_mc_bx: \ltjpreset_font_gt_bx:
310   }
311 }{
312   \bool_if:NTF \l_ltjpreset_bold_bool {
313     \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_bx:
314   }{
315     \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_n_uni:
316   }
317   \cs_set_eq:NN \ltjpreset_font_gt_bx: \ltjpreset_font_gt_m:
318   \cs_set_eq:NN \ltjpreset_font_mc_bx: \ltjpreset_font_gt_m:
319 }
320
321
322 % 実際の fontspec の呼びだし
323
324 \addjfontfeature{ Kerning=Off }
325
326 \setmainjfont [ 
327   BoldFont = \ltjpreset_font_mc_bx:
328   \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed }, 
329   \tl_use:N \l_ltjpreset_add_features_tl 
330 ] { \ltjpreset_font_mc_m: }
331 \setsansjfont [ 
332   BoldFont = \ltjpreset_font_gt_bx: 
333   \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed }, 
334   \tl_use:N \l_ltjpreset_add_features_tl 
335 ] { \ltjpreset_font_gt_m: }
336
337 \ExplSyntaxOff
338 \endinput