OSDN Git Service

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