OSDN Git Service

Adapt luatexja-preset.sty to commit 4aeb291.
[luatex-ja/luatexja.git] / src / addons / luatexja-preset.sty
1 % luatexja-preset.sty
2 \ProvidesPackage{luatexja-preset}
3   [2012/09/17 v0.1]
4
5 \RequirePackage{expl3}
6 \RequirePackage{luatexja-fontspec}
7 \ExplSyntaxOn
8
9 %%%% message
10
11
12 \bool_new:N \l_ltjpreset_bold_bool % bold
13 \bool_set_false:N \l_ltjpreset_bold_bool
14 \DeclareOption{bold}  {\bool_set_true:N \l_ltjpreset_bold_bool}
15 \DeclareOption{nobold}{\bool_set_false:N \l_ltjpreset_bold_bool}
16
17 \bool_new:N \l_ltjpreset_expert_bool % expert
18 \bool_set_false:N \l_ltjpreset_expert_bool
19 \DeclareOption{expert}  {\bool_set_true:N \l_ltjpreset_expert_bool}
20 \DeclareOption{noexpert}{\bool_set_false:N \l_ltjpreset_expert_bool}
21
22 \int_new:N \l_ltjpreset_deluxe_int % expert
23 \int_set:Nn \l_ltjpreset_deluxe_int { 0 }
24 \DeclareOption{deluxe}{\int_set:Nn \l_ltjpreset_deluxe_int { 2 }} % 7 fonts
25 \DeclareOption{nodeluxe}{\int_set:Nn \l_ltjpreset_deluxe_int { 0 }} % 2 fonts
26
27 % scale
28 \msg_new:nnn { luatexja-preset }{ scale }{
29   日本語フォントは~\fp_use:N \g_ltj_fontspec_scale_fp~倍にスケーリングされます.
30 }
31 \msg_warning:nn { luatexja-preset }{ scale }
32
33 % JFM
34 \cs_set:Npn \ltjpreset_use_jfm: {ujis}  % 使用する JFM
35 %%% \DeclareOption{min}{\cs_set:Npn  \ltjpreset_use_jfm: {min}} % min
36 %%% ↑jfm-min.lua が横組み・縦組み専用仮名に追いついていないので使用禁止
37 \DeclareOption{jis}{\cs_set:Npn  \ltjpreset_use_jfm: {jis}}     % jis
38 \DeclareOption{ujis}{\cs_set:Npn  \ltjpreset_use_jfm: {ujis}}   % ujis
39
40 % 漢字字形
41 \tl_new:N \l_ltjpreset_kanji_shape_tl
42 \DeclareOption{90jis}{  \tl_set:Nn \l_ltjpreset_kanji_shape_tl { , RawFeature = +jp90 }} % 90jis
43 \DeclareOption{jis2004}{\tl_set:Nn \l_ltjpreset_kanji_shape_tl { , RawFeature = +jp04 }} % jis2004
44
45 % font preset
46 \bool_new:N \l_ltjpreset_office_bool  % MS Office の HG 系フォントを使っているか
47 \bool_new:N \l_ltjpreset_noembed_bool % 非埋込か
48 \clist_new:N \l_ltjpreset_font_list
49
50 \cs_new:Npn \ltjpreset_set_uni:nn #1#2 {
51   \ltjpreset_set_multi:n { #1, #1, #2, #2, #2, #2, #1 }
52 }
53 \cs_new:Npn \ltjpreset_set_multi:n #1 {
54   \clist_set:Nn \l_ltjpreset_font_list { #1 }
55   \bool_set_false:N \l_ltjpreset_office_bool
56   \bool_set_false:N \l_ltjpreset_noembed_bool
57 }
58 \cs_new:Npn \ltjpreset_set_office:nn #1 #2{
59   \ltjpreset_set_multi:n {
60     #1, HGMinchoE ,           % mc/m, mc/bx
61     HGGothicM , HGGothicE ,   % gt/m, gt/bx (multiweight))
62     #2 , HGSoeiKakugothicUB , % gt/m (uni), gt/eb
63     HGMaruGothicMPRO          % mg/m
64   }
65   \bool_set_true:N \l_ltjpreset_office_bool
66 }
67
68 % kozuka
69 \DeclareOption{kozuka4}{
70   \ltjpreset_set_multi:n {
71     KozMinPro-Regular.otf , KozMinPro-Bold.otf, % mc/m, mc/bx
72     KozGoPro-Regular.otf  , KozGoPro-Bold.otf,  % gt/m, gt/bx (multiweight))
73     KozGoPro-Medium.otf   , KozGoPro-Heavy.otf, % gt/m (uni), gt/eb
74     KozGoPro-Heavy.otf                          % mg/m
75   }
76 }
77 \DeclareOption{kozuka6}{
78   \ltjpreset_set_multi:n {
79     KozMinProVI-Regular.otf , KozMinProVI-Bold.otf, % mc/m, mc/bx
80     KozGoProVI-Regular.otf  , KozGoProVI-Bold.otf,  % gt/m, gt/bx (multiweight))
81     KozGoProVI-Medium.otf   , KozGoProVI-Heavy.otf, % gt/m (uni), gt/eb
82     KozGoProVI-Heavy.otf                            % mg/m
83   }
84 }
85 \DeclareOption{kozuka6n}{
86   \ltjpreset_set_multi:n {
87     KozMinPr6N-Regular.otf , KozMinPr6N-Bold.otf, % mc/m, mc/bx
88     KozGoPr6N-Regular.otf  , KozGoPr6N-Bold.otf,  % gt/m, gt/bx (multiweight))
89     KozGoPr6N-Medium.otf   , KozGoPr6N-Heavy.otf, % gt/m (uni), gt/eb
90     KozGoPr6N-Heavy.otf                           % mg/m
91   }
92 }
93
94 % hiragino
95 \DeclareOption{hiragino}{
96   \ltjpreset_set_multi:n {
97     HiraMinPro-W3.otf      , HiraMinPro-W6.otf,   % mc/m, mc/bx
98     HiraKakuPro-W3.otf     , HiraKakuPro-W6.otf,  % gt/m, gt/bx (multiweight))
99     HiraKakuPro-W3.otf     , HiraKakuStd-W8.otf,  % gt/m (uni), gt/eb
100     HiraMaruPro-W4.otf                            % mg/m
101   }
102 }
103 \DeclareOption{hiraginon}{
104   \ltjpreset_set_multi:n {
105     HiraMinProN-W3.otf      , HiraMinProN-W6.otf,   % mc/m, mc/bx
106     HiraKakuProN-W3.otf     , HiraKakuProN-W6.otf,  % gt/m, gt/bx (multiweight))
107     HiraKakuProN-W3.otf     , HiraKakuStdN-W8.otf,  % gt/m (uni), gt/eb
108     HiraMaruProN-W4.otf                             % mg/m
109   }
110 }
111
112 % morisawa?
113 \DeclareOption{morisawa4}{
114   \ltjpreset_set_multi:n {
115     A-OTF-RyuminPro-Light.otf , A-OTF-FutoMinA101Pro-Bold.otf ,    % mc/m, mc/bx
116     A-OTF-GothicBBBPro-Medium.otf , A-OTF-FutoGoB101Pro-Bold.otf , % gt/m, gt/bx (multiweight))
117     A-OTF-GothicBBBPro-Medium.otf , A-OTF-MidashiGoPro-MB31.otf ,  % gt/m (uni), gt/eb
118     A-OTF-Jun101Pro-Light.otf % mg/m
119   }
120 }
121 \DeclareOption{morisawa6n}{
122   \ltjpreset_set_multi:n {
123     A-OTF-RyuminPr6N-Light.otf , A-OTF-FutoMinA101Pr6N-Bold.otf ,    % mc/m, mc/bx
124     A-OTF-GothicBBBPr6N-Medium.otf , A-OTF-FutoGoB101Pr6N-Bold.otf , % gt/m, gt/bx (multiweight))
125     A-OTF-GothicBBBPr6N-Medium.otf , A-OTF-MidashiGoPr6N-MB31.otf ,  % gt/m (uni), gt/eb
126     A-OTF-Jun101Pr6N-Light.otf                                       % mg/m
127   }
128 }
129
130
131 % ipa, ipaex, ms
132 \DeclareOption{ipa}{
133   \ltjpreset_set_uni:nn { IPAMincho } { IPAGothic }
134 }
135 \DeclareOption{ipaex}{
136   \ltjpreset_set_uni:nn { IPAExMincho } { IPAExGothic }
137 }
138 \DeclareOption{ms}{
139   \ltjpreset_set_uni:nn { MS-Mincho } { MS-Gothic }
140 }
141
142 % {ipa,ipaex,ms}-dx % Office 付属フォントを利用
143 \DeclareOption{ipaex-dx}{
144   \ltjpreset_set_office:nn { IPAExMincho } { IPAExGothic }
145 }
146 \DeclareOption{ipa-dx}{
147   \ltjpreset_set_office:nn { IPAMincho } { IPAGothic }
148 }
149 \DeclareOption{ms-dx}{
150   \ltjpreset_set_office:nn { MS-Mincho } { MS-Gothic }
151 }
152
153
154 % 非埋込
155 \DeclareOption{noembed}{
156   \ltjpreset_set_uni:nn { Ryumin-Light } { GothicBBB-Medium }
157   \bool_set_true:N \l_ltjpreset_noembed_bool
158 }
159
160 \ExecuteOptions{noembed}
161 \ProcessOptions*
162
163 %% KozMinPr6N の場合はjp04 feature がないので,nlck にする
164 \clist_if_in:NnT \l_ltjpreset_font_list { KozMinPr6N-Regular.otf } {
165   \tl_set:Nn \l_tmpa_tl {, RawFeature = +jp04}
166   \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl {
167     \tl_set:Nn \l_ltjpreset_kanji_shape_tl { , RawFeature = +nlck }
168   }
169 }
170
171 %%%%%%%% main routine
172
173 %%%%  リストからの展開
174 % mc/m
175 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
176 \cs_set:Nx \ltjpreset_font_mc_m: { \tl_use:N \l_tmpa_tl }
177
178 % mc/bx
179 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
180 \cs_set:Nx \ltjpreset_font_mc_bx: { \tl_use:N \l_tmpa_tl }
181
182 % gt/m
183 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
184 \cs_set:Nx \ltjpreset_font_gt_m: { \tl_use:N \l_tmpa_tl }
185
186 % gt/bx
187 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
188 \cs_set:Nx \ltjpreset_font_gt_bx: { \tl_use:N \l_tmpa_tl }
189
190 % gt/m-uni
191 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
192 \cs_set:Nx \ltjpreset_font_gt_n_uni: { \tl_use:N \l_tmpa_tl }
193
194 % gt/eb
195 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
196 \cs_set:Nx \ltjpreset_font_gt_eb: { \tl_use:N \l_tmpa_tl }
197
198 % mg/m
199 \clist_pop:NN \l_ltjpreset_font_list \l_tmpa_tl
200 \cs_set:Nx \ltjpreset_font_mg: { \tl_use:N \l_tmpa_tl }
201
202 %% HG 系フォント + JIS2004/90JIS のときはフォント名を置換
203 \bool_if:NT \l_ltjpreset_office_bool {
204   \tl_set:Nn \l_tmpa_tl {, RawFeature = +jp04}
205   \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl { 
206     \cs_set:Nx \ltjpreset_font_mc_bx: { hgrme04.ttc }
207     \cs_set:Nx \ltjpreset_font_gt_bx: { hgrge04.ttc }
208     \cs_set:Nx \ltjpreset_font_gt_eb: { hgrsgu04.ttc }
209     \cs_set:Nx \ltjpreset_font_mg:    { hgrsmp04.ttf }
210     \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_n_uni:
211     % HG ゴシックM のときはそうはいかないので 1 ウェイト時のゴシック体を使う
212   }
213   \tl_set:Nn \l_tmpa_tl {, RawFeature = +jp90}
214   \tl_if_eq:NNT \l_ltjpreset_kanji_shape_tl \l_tmpa_tl { 
215     \cs_set:Nx \ltjpreset_font_mc_bx: { hgrme.ttc }
216     \cs_set:Nx \ltjpreset_font_gt_bx: { hgrge.ttc }
217     \cs_set:Nx \ltjpreset_font_gt_eb: { hgrsgu.ttc }
218     \cs_set:Nx \ltjpreset_font_mg:    { hgrsmp.ttf }
219   }
220 }
221
222 %%%% expert 用設定
223 \tl_new:N \l_ltjpreset_add_features_tl
224
225 \tl_set:Nx \l_ltjpreset_add_features_tl {
226   \tl_use:N \l_ltjpreset_kanji_shape_tl, 
227   JFM   = \ltjpreset_use_jfm:
228 }
229
230 \bool_if:NT \l_ltjpreset_expert_bool {
231   \cs_set:Npn \rubyfamily { \addfontfeatures { Style = Ruby} }
232   \tl_put_left:Nn \l_ltjpreset_add_features_tl { Style = HorizontalKana, }
233 }
234
235 %%%% (丸)ゴシック体の設定: bold option もここで
236 \int_compare:nTF { \l_ltjpreset_deluxe_int ==  2 } {
237   \newjfontfamily \mgfamily [
238       \tl_use:N \l_ltjpreset_add_features_tl
239       \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed }
240     ] { \ltjpreset_font_mg: }
241   \newjfontfamily \gtebfamily [
242       \tl_use:N \l_ltjpreset_add_features_tl
243       \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed }
244     ] { \ltjpreset_font_gt_eb: }
245   \bool_if:NT \l_ltjpreset_bold_bool {
246     \cs_set_eq:NN \ltjpreset_font_mc_bx: \ltjpreset_font_gt_bx:
247   }
248 }{
249   \bool_if:NTF \l_ltjpreset_bold_bool {
250     \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_bx:
251   }{
252     \cs_set_eq:NN \ltjpreset_font_gt_m: \ltjpreset_font_gt_n_uni:
253   }
254   \cs_set_eq:NN \ltjpreset_font_gt_bx: \ltjpreset_font_gt_m:
255   \cs_set_eq:NN \ltjpreset_font_mc_bx: \ltjpreset_font_gt_m:
256 }
257
258
259 %%%% 実際の fontspec の呼びだし
260
261 \defaultjfontfeatures{ Kerning=Off, \tl_use:N \l_ltjpreset_add_features_tl }
262
263 \setmainjfont [ 
264   BoldFont = \ltjpreset_font_mc_bx:
265   \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed }
266 ] { \ltjpreset_font_mc_m: }
267 \setsansjfont [ 
268   BoldFont = \ltjpreset_font_gt_bx: 
269   \bool_if:NT \l_ltjpreset_noembed_bool { , NoEmbed }
270 ] { \ltjpreset_font_gt_m: }
271
272 \ExplSyntaxOff
273 \endinput