diff options
author | Karl Berry <karl@freefriends.org> | 2014-05-05 22:06:34 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-05-05 22:06:34 +0000 |
commit | c282c4699b5c50d0d050bb1d7f5187a47eebc94e (patch) | |
tree | 247a127065821c008bc8fee600c1e130e2d0ecd5 /Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec.sty | |
parent | c2e26b130cd3c16ddba1e50bd65f8ff334ba8acc (diff) |
luatexja (4may14)
git-svn-id: svn://tug.org/texlive/trunk@33863 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec.sty')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec.sty | 178 |
1 files changed, 142 insertions, 36 deletions
diff --git a/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec.sty b/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec.sty index 9fa1ec4867e..43666d3b3f3 100644 --- a/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec.sty +++ b/Master/texmf-dist/tex/luatex/luatexja/addons/luatexja-fontspec.sty @@ -3,31 +3,64 @@ % \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{luatexja-fontspec}[2014/01/23 fontspec support of LuaTeX-ja] - -\RequirePackage{fontspec,luatexja} +\ProvidesPackage{luatexja-fontspec}[2014/04/16 fontspec support of LuaTeX-ja] +\RequirePackage{l3keys2e,luatexja} \ExplSyntaxOn +\bool_new:N \ltj_fontspec_match +\cs_set:Nn \ltj_fontspec_pass_opts: {} +\keys_define:nn { luatexja-fontspec } + { + match .bool_set:N = \ltj_fontspec_match, + match .default:n = true, + pass .code:n = \cs_set:Nn \ltj_fontspec_pass_opts: {#1}, + } +\ProcessKeysOptions { luatexja-fontspec } +\RequirePackage[\ltj_fontspec_pass_opts:]{fontspec}[2011/09/13] + +%%%%%%%% Change Japanese font family by \rmfamily or not +\bool_if:NTF \ltj_fontspec_match +{ + \renewcommand\jttdefault{\gtdefault} + \DeclareRobustCommand\rmfamily + {\not@math@alphabet\rmfamily\mathrm + \romanfamily\rmdefault\kanjifamily\mcdefault\selectfont} + \DeclareRobustCommand\sffamily + {\not@math@alphabet\sffamily\mathsf + \romanfamily\sfdefault\kanjifamily\gtdefault\selectfont} + \DeclareRobustCommand\ttfamily + {\not@math@alphabet\ttfamily\mathtt + \romanfamily\ttdefault\kanjifamily\jttdefault\selectfont} + \DeclareDocumentCommand \setmonojfont { O{} m } { + \__ltj_fontspec_set_family:Nnn \jttdefault {#1}{#2} + \normalfont + } +}{ +} + %%%%%%%% Messages -\cs_new:Npn \ltj_fontspec_warning:n { \msg_warning:nn {ltj-fontspec} } -\msg_new:nnn {ltj-fontspec} {addjfontfeatures-ignored} +\msg_new:nnn {luatexja-fontspec} {addjfontfeatures-ignored} { \string\addjfontfeature (s)~ ignored;\\ it~ cannot~ be~ used~ with~ a~ font~ that~ wasn't~ selected~ by~ luatexja-fontspec. } -\cs_generate_variant:Nn \prg_new_conditional:Nnn {Nnx} +\msg_new:nnn {luatexja-fontspec} {altfont-ignored-by-norange} +{ + ignored~ sublist~ `#1'~ in~ AltFont~ (no~ range~ is~ specified). +} -%%%%%%%% For compatibility with old fontspec. -\prg_new_conditional:Nnx \ltj_fontspec_if_liiikeys: {TF,F} { - \@ifpackagelater {fontspec} {2011/09/13} - { \exp_not:N \prg_return_true: } % fontspec >= 2.2 (l3keys) - { \exp_not:N \prg_return_false: } % fontspec < 2.2 (xkeyval) +\msg_new:nnn {luatexja-fontspec} {altfont-ignored-by-rangeonly} +{ + ignored~ sublist~ `#1'~ in~ AltFont~ (only~ range~ is~ specified). } +\cs_generate_variant:Nn \prg_new_conditional:Nnn {Nnx} + %%%%%%%% \g_ltj_fontspec_scale_fp %% Default scale value for jfont. +\fp_new:N \g_ltj_fontspec_scale_fp \group_begin: \fontsize{10}{10}\selectfont \fp_gset:Nn \g_ltj_fontspec_scale_fp {\zw / 10} @@ -36,23 +69,49 @@ %%%%%%%% Internal control sequences %% Each CS is ltj_fontspec version that corresponds to original CS of fontspec. \cs_new:Nn \ltj_fontspec_define_option:nn { - \ltj_fontspec_if_liiikeys:TF { - \keys_define:nn {fontspec} { #1 .code:n = {#2}} - } { - \define@key[zf]{options}{#1}{#2} - } + \keys_define:nn {fontspec} { #1 .code:n = {#2}} } \cs_new:Nn \ltj_fontspec_define_preparse_external:nn { - \ltj_fontspec_if_liiikeys:TF { - \keys_define:nn {fontspec-preparse-external} { #1 .code:n = {#2}} - } { - \define@key[zf]{preparse-external}{#1}{#2} - } + \keys_define:nn {fontspec-preparse-external} { #1 .code:n = {#2}} +} + +\cs_new:Nn \ltj_fontspec_define_altfont_option:nn { + \keys_define:nn {fontspec-ltjaltfont} { #1 .code:n = {#2}} } +%% Alternate Fonts +%% Spec: AltFont = { +%% ... +%% { Range = <range>, <font features> }, +%% { Range = <range>, Font = <font name>, <font features> }, +%% { Range = <range>, Font = <font name> }, +%% ... +%% } +\tl_new:N \l_ltj_fontspec_altname_tl +\tl_new:N \l_ltj_fontspec_altrange_tl +\clist_new:N \l_ltj_fontspec_altfont_clist +\clist_new:N \l_ltj_fontspec_altfont_leftover_clist +\int_new:N \g_ltj_fontspec_altnumber_int + +\ltj_fontspec_define_altfont_option:nn {Range} { + \tl_set:Nn \l_ltj_fontspec_altrange_tl {#1} +} +\ltj_fontspec_define_altfont_option:nn {Font} { + \fontspec_complete_fontname:Nn \l_ltj_fontspec_altname_tl {#1} +} + +\cs_new:Nn \__ltj_fontspec_altfont_key_code:n + { + \clist_set:Nn \l_ltj_fontspec_altfont_clist {#1} + \fontspec_update_fontid:n {alt:#1} + } + \cs_new:Nn \ltj_fontspec_select:nn { \group_begin: + \ltj_fontspec_define_option:nn {AltFont} { + \__ltj_fontspec_altfont_key_code:n { ##1 } + } \ltj_fontspec_define_option:nn {CID} { \fontspec_update_fontid:n {+cid=##1} \fontspec_update_featstr:n {cid=##1} @@ -74,43 +133,91 @@ \fontspec_update_fontid:n {-kern} \fontspec_update_featstr:n {-kern} } - \ltj_fontspec_if_liiikeys:TF { - \tl_set:Nn \g_fontspec_encoding_tl {JY3} - } { - \tl_set:Nn \zf@enc {JY3} - } + \tl_set:Nn \g_fontspec_encoding_tl {JY3} \tl_set:Nx \g_fontspec_default_fontopts_tl - {JFM=ujis,Scale=\fp_use:N \g_ltj_fontspec_scale_fp,Kerning=Off,\g_ltj_fontspec_default_fontopts_tl} + {JFM=ujis, Scale=\fp_use:N \g_ltj_fontspec_scale_fp, + Kerning=Off, \g_ltj_fontspec_default_fontopts_tl} \prop_set_eq:NN \g__fontspec_fontopts_prop \g__ltj_fontspec_fontopts_prop + \cs_set_eq:NN \fontspec_make_font_shapes:nnnn \ltj_fontspec_make_font_shapes:nnnn \cs_set_eq:NN \DeclareFontFamily \DeclareKanjiFamily \fontspec_select:nn{#1}{#2} \group_end: - \ltj_fontspec_if_liiikeys:F { - \tl_set_eq:NN \l_fontspec_family_tl \zf@family - } } -\cs_new:Nn \ltj_fontspec_set_family:Nnn { +\cs_new:Nn \__ltj_fontspec_set_family:Nnn { \ltj_fontspec_select:nn{#2}{#3} \tl_set_eq:NN #1 \l_fontspec_family_tl } +\cs_set_eq:NN \__ltj_orig_fontspec_make_font_shapes:nnnn \fontspec_make_font_shapes:nnnn +\cs_set_eq:NN \__ltj_fontspec_orig_DeclareFontShape \DeclareFontShape +\cs_new:Nn \ltj_fontspec_make_font_shapes:nnnn { + \__ltj_orig_fontspec_make_font_shapes:nnnn {#1} {#2} {#3} {#4} + \group_begin: + %% Parse font features. However, we have to avoid redefine already defined shape. + \__fontspec_load_fontname:n {#1} + \cs_set_eq:NN \DeclareFontShape \use_none:nnnnnn + \fontspec_declare_shape:nnn {#2}{#3} + { \quark_if_no_value:NF \l__fontspec_fontopts_clist {\l__fontspec_fontopts_clist,} #4 } + \cs_set_eq:NN \DeclareFontShape \__ltj_fontspec_orig_DeclareFontShape + %% + \clist_if_empty:NF \l_ltj_fontspec_altfont_clist { + \int_gzero:N \g_ltj_fontspec_altnumber_int + \clist_map_inline:Nn \l_ltj_fontspec_altfont_clist { + \tl_clear:N \l_ltj_fontspec_altrange_tl + \tl_set:Nn \l_ltj_fontspec_altname_tl { #1 } + \tl_set:Nn \l_tmpa_tl { #1 } + + \keys_set_known:nxN {fontspec-ltjaltfont} { \exp_after:wN \use:n ##1 } + \l_ltj_fontspec_altfont_leftover_clist + + \tl_if_empty:NT \l_ltj_fontspec_altrange_tl { + \msg_warning:nnn {luatexja-fontspec} {altfont-ignored-by-norange} { ##1 } + } { + \bool_if:nTF { + \tl_if_eq_p:NN \l_ltj_fontspec_altname_tl \l_tmpa_tl + && + \tl_if_empty_p:N \l_ltj_fontspec_altfont_leftover_clist + } { + \msg_warning:nnn {luatexja-fontspec} {altfont-ignored-by-rangeonly} { ##1 } + } { + \group_begin: + \__fontspec_load_fontname:n { \l_ltj_fontspec_altname_tl } + \fontspec_declare_shape:nnn {#2} + {#3 _ alt \int_use:N \g_ltj_fontspec_altnumber_int } + { + \quark_if_no_value:NF \l__fontspec_fontopts_clist {\l__fontspec_fontopts_clist,} + #4 , \l_ltj_fontspec_altfont_leftover_clist + } + \group_end: + \DeclareAlternateKanjiFont + {JY3}{ \l_fontspec_family_tl }{#2}{#3}% + {JY3}{ \l_fontspec_family_tl }{#2} + { #3 _alt \int_use:N \g_ltj_fontspec_altnumber_int } + { \l_ltj_fontspec_altrange_tl } + \int_gincr:N \g_ltj_fontspec_altnumber_int + } + } + } + } + \group_end: + } %%%%%%%% User commands \DeclareDocumentCommand \jfontspec { O{} m } { - \ltj_fontspec_set_family:Nnn \k@family {#1}{#2} + \__ltj_fontspec_set_family:Nnn \k@family {#1}{#2} \selectfont \ignorespaces } \DeclareDocumentCommand \setmainjfont { O{} m } { - \ltj_fontspec_set_family:Nnn \mcdefault {#1}{#2} + \__ltj_fontspec_set_family:Nnn \mcdefault {#1}{#2} \DeclareSymbolFont{mincho}{JY3}{\l_fontspec_family_tl}{m}{n} \SetSymbolFont{mincho}{bold}{JY3}{\l_fontspec_family_tl}{bx}{n} \normalfont } \DeclareDocumentCommand \setsansjfont { O{} m } { - \ltj_fontspec_set_family:Nnn \gtdefault {#1}{#2} + \__ltj_fontspec_set_family:Nnn \gtdefault {#1}{#2} \DeclareMathAlphabet{\mathgt}{JY3}{\l_fontspec_family_tl}{m}{n} \normalfont } @@ -160,7 +267,7 @@ \group_end: \fontfamily\l_fontspec_family_tl\selectfont \else - \ltj_fontspec_warning:n {addjfontfeatures-ignored} + \msg_warning:nn {luatexja-fontspec} {addjfontfeatures-ignored} \fi \ignorespaces } @@ -231,5 +338,4 @@ \fi \fi} - \endinput |