OSDN Git Service

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