OSDN Git Service

Added cache tables of JFM for speed. (quick fix)
[luatex-ja/luatexja.git] / src / luatexja-fontspec.sty
1 %
2 % luatexja-fontspec.sty
3 %
4
5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{luatexja-fontspec}[2011/09/23 v0.2]
7
8 \RequirePackage{fontspec}[2011/09/18] % v2.2a
9 \RequirePackage{luatexja}
10
11 \ExplSyntaxOn
12
13 \cs_new:Npn \ltj_fontspec_warning:n   { \msg_warning:nn   {ltj-fontspec} }
14
15 \msg_new:nnn {ltj-fontspec} {addjfontfeatures-ignored}
16 {
17   \string\addjfontfeature (s)~ ignored;\\
18   it~ cannot~ be~ used~ with~ a~ font~ that~ wasn't~ selected~ by~ luatexja-fontspec.
19 }
20
21 \cs_new:Nn \ltj_fontspec_select:nn {
22   \group_begin:
23   \keys_define:nn {fontspec} { JFM .code:n = {
24       \fontspec_update_fontid:n  {+jfm=##1}
25       \fontspec_update_featstr:n {jfm=##1}      
26     }
27   }
28   \keys_define:nn {fontspec} { JFM-var .code:n = {
29       \fontspec_update_fontid:n  {+jfmvar=##1}
30       \fontspec_update_featstr:n {jfmvar=##1}      
31     }
32   }
33   \keys_define:nn {fontspec-preparse-external} { NoEmbed .code:n = {
34       \cs_set:Nn \fontspec_namewrap:n {psft:####1}
35     }
36   }
37   \tl_set:Nn \g_fontspec_encoding_tl {JY3}
38   \tl_set:Nx \g_fontspec_default_fontopts_tl 
39              {JFM=ujis,Scale=0.960444,Kerning=Off,\g_ltj_fontspec_default_fontopts_tl}
40   \cs_set_eq:NN \DeclareFontFamily \DeclareKanjiFamily
41   \fontspec_select:nn{#1}{#2}
42   \group_end:
43 }
44
45 \cs_new:Nn \ltj_fontspec_set_family:Nnn {
46   \ltj_fontspec_select:nn{#2}{#3}
47   \tl_set_eq:NN #1 \l_fontspec_family_tl
48 }
49
50 \DeclareDocumentCommand \jfontspec { O{} m } {
51   \ltj_fontspec_set_family:Nnn \k@family {#1}{#2}
52   \selectfont
53   \ignorespaces
54 }
55
56 \DeclareDocumentCommand \setmainjfont { O{} m } {
57   \ltj_fontspec_set_family:Nnn \mcdefault {#1}{#2}
58   \normalfont
59 }
60
61 \DeclareDocumentCommand \setsansjfont { O{} m } {
62   \ltj_fontspec_set_family:Nnn \gtdefault {#1}{#2}
63   \normalfont
64 }
65
66 \DeclareDocumentCommand \newjfontfamily { m O{} m } {
67   \ltj_fontspec_select:nn{#2}{#3}
68   \use:x {
69     \exp_not:N \DeclareRobustCommand \exp_not:N #1 {
70       \exp_not:N \kanjifamily {\l_fontspec_family_tl} \exp_not:N \selectfont
71     }
72   }
73 }
74
75 \DeclareDocumentCommand \newjfontface { m O{} m } {
76   \newjfontfamily #1 [ BoldFont={},ItalicFont={},SmallCapsFont={},#2 ] {#3}
77 }
78
79 \DeclareDocumentCommand \defaultjfontfeatures {m} {
80   \tl_set:Nn \g_ltj_fontspec_default_fontopts_tl {#1,}
81 }
82
83 \tl_clear:N \g_ltj_fontspec_default_fontopts_tl
84
85 \DeclareDocumentCommand \addjfontfeatures {m} {
86   \ifcsname zf@family@fontdef\k@family\endcsname
87     \group_begin:
88       \tl_clear:N \g_ltj_fontspec_default_fontopts_tl
89       \use:x {
90         \exp_not:N\ltj_fontspec_select:nn
91           {\csname zf@family@options\k@family\endcsname,#1}
92           {\csname zf@family@fontname\k@family\endcsname}
93       }
94     \group_end:
95     \fontfamily\l_fontspec_family_tl\selectfont
96   \else
97     \ltj_fontspec_warning:n {addjfontfeatures-ignored}
98   \fi
99   \ignorespaces
100 }
101
102 \cs_set_eq:NN \addjfontfeature \addjfontfeatures
103
104 \endinput