diff options
author | Karl Berry <karl@freefriends.org> | 2013-08-18 23:35:38 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-08-18 23:35:38 +0000 |
commit | 2a336b1e455ff43e4a2cfa2007a80acbb850219c (patch) | |
tree | ad357e8fe881556300baba4c48ee1223132942a2 /Master/texmf-dist/tex/latex/xcjk2uni/xCJK2uni.sty | |
parent | 3abd327d4999d888117813572f0c8b46bceb1dba (diff) |
xcjk2uni (18aug13)
git-svn-id: svn://tug.org/texlive/trunk@31464 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/xcjk2uni/xCJK2uni.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/xcjk2uni/xCJK2uni.sty | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/xcjk2uni/xCJK2uni.sty b/Master/texmf-dist/tex/latex/xcjk2uni/xCJK2uni.sty new file mode 100644 index 00000000000..7fd1cc9744c --- /dev/null +++ b/Master/texmf-dist/tex/latex/xcjk2uni/xCJK2uni.sty @@ -0,0 +1,233 @@ +%% +%% This is file `xCJK2uni.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% xCJK2uni.dtx (with options: `package') +%% +%% Copyright (C) 2013 by Qing Lee <sobenlee@gmail.com> +%% -------------------------------------------------------------------------- +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3 +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.3 or later is part of all distributions of LaTeX +%% version 2005/12/01 or later. +%% +%% This work has the LPPL maintenance status "maintained". +%% The Current Maintainer of this work is Qing Lee. +%% +\NeedsTeXFormat{LaTeX2e} +\RequirePackage{expl3} +\GetIdInfo$Id: xCJK2uni.dtx 512 2013-08-17 15:03:03Z sobenlee $ + {Convert CJK character to Unicode.} +\ProvidesExplPackage{\ExplFileName} + {\ExplFileDate}{0.1}{\ExplFileDescription} +\pdftex_if_engine:F + { + \msg_new:nnn { xCJK2uni } { pdflatex } + { The~xCJK2uni~package~is~only~supported~in~pdfTeX. } + \msg_critical:nn { xCJK2uni } { pdflatex } + } +\tl_new:N \l__CJKtu_sfd_tl +\prop_new:N \c__CJKtu_sfd_prop +\seq_new:N \c__CJKtu_encoding_seq +\int_new:N \l__CJKtu_i_min_int +\int_new:N \l__CJKtu_i_max_int +\int_new:N \l__CJKtu_ii_min_int +\int_new:N \l__CJKtu_ii_max_int +\int_new:N \l__CJKtu_gap_begin_int +\int_new:N \l__CJKtu_gap_end_int +\int_new:N \l__CJKtu_plane_int +\int_set:Nn \l__CJKtu_i_max_int { "FE } +\int_set:Nn \l__CJKtu_ii_max_int { "FE } +\cs_new_protected_nopar:Npn \__CJKtu_set_enc:nnnnnn #1#2#3#4#5#6 + { + \seq_put_right:Nn \c__CJKtu_encoding_seq {#1} + \prop_gput:Nnn \c__CJKtu_sfd_prop {#1} {#2} + \int_const:cn { c__CJKtu_ #1 _i_min_int } {#3} + \int_const:cn { c__CJKtu_ #1 _ii_min_int } {#4} + \tl_if_empty:nTF {#5} + { + \int_const:cn { c__CJKtu_ #1 _gap_begin_int } + { \l__CJKtu_ii_max_int + \c_one } + \int_const:cn { c__CJKtu_ #1 _gap_end_int } + { \use:c { c__CJKtu_ #1 _gap_begin_int } } + \int_const:cn { c__CJKtu_ #1 _plane_int } + { \l__CJKtu_ii_max_int - (#4) + \c_one } + } + { + \int_const:cn { c__CJKtu_ #1 _gap_begin_int } { #5 + \c_one } + \int_const:cn { c__CJKtu_ #1 _gap_end_int } {#6} + \int_const:cn { c__CJKtu_ #1 _plane_int } + { (#5) - (#4) + \l__CJKtu_ii_max_int - (#6) + \c_two } + } + \cs_if_exist_use:NTF \CJKaddEncHook + { {#1} { \__CJKtu_enc_map:nn {#1} {#2} } } + { + \AtBeginDocument + { + \cs_if_exist_use:NT \CJKaddEncHook + { {#1} { \__CJKtu_enc_map:nn {#1} {#2} } } + } + } + } +\cs_new_protected_nopar:Npn \__CJKtu_enc_map:nn #1#2 + { + \int_set_eq:Nc \l__CJKtu_i_min_int { c__CJKtu_ #1 _i_min_int } + \int_set_eq:Nc \l__CJKtu_ii_min_int { c__CJKtu_ #1 _ii_min_int } + \int_set_eq:Nc \l__CJKtu_gap_begin_int { c__CJKtu_ #1 _gap_begin_int } + \int_set_eq:Nc \l__CJKtu_gap_end_int { c__CJKtu_ #1 _gap_end_int } + \int_set_eq:Nc \l__CJKtu_plane_int { c__CJKtu_ #1 _plane_int } + \cs_if_exist:cF { CJKtu_ #1 _sfd_map:nn } + { \group_begin: \ExplSyntaxOn \file_input:n { xCJK2uni-#2.def } \group_end: } + \cs_set_eq:Nc \CJKtu_sfd_map:nn { CJKtu_ #1 _sfd_map:nn } + } +\cs_new_protected_nopar:Npn \__CJKtu_use_enc_map:n #1 + { + \prop_get:NxNTF \c__CJKtu_sfd_prop {#1} \l__CJKtu_sfd_tl + { \__CJKtu_enc_map:nn {#1} { \l__CJKtu_sfd_tl } } + { \msg_error:nnx { xCJK2uni } { invalid-encoding } {#1} } + } +\msg_new:nnn { xCJK2uni } { invalid-encoding } + { + The~enconding~`#1'~is~invalid.\\ + Only~\seq_use:Nnnn \c__CJKtu_encoding_seq { ~and~ } { ,~ } { ,~and~ } ~ + are~supported. + } +\cs_generate_variant:Nn \prop_get:NnNTF { Nx } +\__CJKtu_set_enc:nnnnnn { GB } { UGB } { "A1 } { "A1 } { } { } +\__CJKtu_set_enc:nnnnnn { JIS } { UJIS } { "A1 } { "A1 } { } { } +\__CJKtu_set_enc:nnnnnn { KS } { UKS } { "A1 } { "A1 } { } { } +\__CJKtu_set_enc:nnnnnn { Bg5 } { UBig5 } { "A1 } { "40 } { "7E } { "A1 } +\__CJKtu_set_enc:nnnnnn { Bg5+ } { UBg5plus } { "81 } { "40 } { "7E } { "80 } +\__CJKtu_set_enc:nnnnnn { GBK } { UGBK } { "81 } { "40 } { "7E } { "80 } +\cs_new_nopar:Npn \__CJKtu_sfd_to_unicode:nn #1#2 + { + \tex_romannumeral:D -`0 \exp_last_unbraced:Nf + \__CJKtu_get_unicode:w \CJKtu_sfd_map:nn {#1} {#2} \s__stop + } +\cs_new_nopar:Npn \__CJKtu_get_unicode:w #1 \s__stop + { \tl_if_empty:nF {#1} { \__CJKtu_get_unicode_aux:w #1 \q_stop } } +\cs_new_nopar:Npn \__CJKtu_get_unicode_aux:w #1 \or: #2 \q_stop + { \or: #2 \exp_stop_f: #1 } +\group_begin: +\char_set_catcode_active:n { "7F } +\cs_new_nopar:Npn \__CJKtu_char_to_unicode:n #1 + { + \tex_romannumeral:D -`0 + \int_compare:nNnTF { \tl_count:n {#1} } = \c_two + { \CJKtu_byte:NN #1 } + { + \tl_if_head_eq_meaning:nNTF {#1} ^^7f + { \__CJKtu_byte:wNwnw #1 } + { \__CJKtu_encoding_error: } + } + } +\cs_new_nopar:Npn \__CJKtu_byte:wNwnw ^^7f #1 ^^7f #2 ^^7f + { \CJKtu_byte_map:nn { `#1 } {#2} } +\cs_new_nopar:Npn \__CJKtu_byte:Nwnw #1 ^^7f #2 ^^7f + { \CJKtu_byte_map:nn { `#1 } {#2} } +\cs_new_protected_nopar:Npn \__CJKtu_bookmarks_hook: + { + \cs_set_eq:NN ^^7f \__CJKtu_byte:Nwnw + \cs_set_eq:NN \CJK@XX \CJKtu_byte:NN + \cs_set_eq:NN \CJKchar \__CJKtu_byte:wnn + \cs_set_eq:NN \CCTchar \CJKtu_byte:nn + \cs_set_eq:NN \@CCTSetChar \__CJKtu_CCT_byte:NNN + \cs_set_eq:NN \__CJKtu_get_unicode:n \__CJKtu_UTF_xvi_be:n + } +\group_end: +\cs_new_nopar:Npn \CJKtu_byte:NN #1#2 + { \CJKtu_byte:nn { `#1 } { `#2 } } +\cs_new_nopar:Npn \__CJKtu_CCT_byte:NNN #1#2#3 + { \CJKtu_byte:nn { `#1 } { `#3 } } +\cs_new_nopar:Npn \__CJKtu_byte:wnn #1# { \CJKtu_byte:nn } +\cs_new_nopar:Npn \CJKtu_byte:nn #1#2 + { + \int_compare:nTF { \l__CJKtu_i_min_int <= #1 <= \l__CJKtu_i_max_int } + { + \int_compare:nTF { \l__CJKtu_ii_min_int <= #2 < \l__CJKtu_gap_begin_int } + { \CJKtu_byte_map:nn {#1} {#2} } + { + \int_compare:nTF + { \l__CJKtu_gap_end_int <= #2 <= \l__CJKtu_ii_max_int } + { \CJKtu_byte_map:nn {#1} {#2} } + { \__CJKtu_encoding_error: } + } + } + { \__CJKtu_encoding_error: } + } +\cs_new_nopar:Npn \__CJKtu_encoding_error: + { \exp_stop_f: \__msg_expandable_error:n { Wrong~encoding~scheme. } } +\cs_new_nopar:Npn \CJKtu_byte_map:nn #1#2 + { + \exp_args:Nf \__CJKtu_index_map:n + { + \int_eval:n + { + ( #1 - \l__CJKtu_i_min_int ) * \l__CJKtu_plane_int + + (#2) - \l__CJKtu_ii_min_int + \int_compare:nNnF {#2} < \l__CJKtu_gap_begin_int + { + \l__CJKtu_gap_begin_int - \l__CJKtu_gap_end_int } + } + } + } +\cs_new_nopar:Npn \__CJKtu_index_map:n #1 + { + \__CJKtu_get_unicode:n + { + \CJKtu_sfd_map:nn + { \int_div_truncate:nn {#1} { \c_two_hundred_fifty_six } + \c_one } + { \int_mod:nn {#1} { \c_two_hundred_fifty_six } } + } + } +\cs_new_nopar:Npn \__CJKtu_get_unicode:n #1 + { \exp_last_unbraced:Nf \__CJKtu_get_unicode:w #1 \s__stop } +\cs_new_nopar:Npn \__CJKtu_UTF_xvi_be:n #1 + { \exp_args:Nf \__CJKtu_UTF_xvi_aux:n { \int_eval:n { "#1 } } } +\cs_new_nopar:Npn \__CJKtu_UTF_xvi_aux:n #1 + { + \HyPsd@DecimalToOctalFirst + { \int_div_truncate:nn {#1} { \c_two_hundred_fifty_six } } + \HyPsd@DecimalToOctalSecond + { \int_mod:nn {#1} { \c_two_hundred_fifty_six } } + } +\cs_if_exist_use:NTF \hypersetup { { unicode } } + { \PassOptionsToPackage { unicode } { hyperref } } +\AtBeginDocument + { + \@ifpackageloaded { CJKutf8 } + { \msg_warning:nn { xCJK2uni } { UTF-8-encoding } } + { + \cs_if_free:NF \pdfstringdefDisableCommands + { + \hypersetup { CJKbookmarks = false } + \pdfstringdefDisableCommands { \__CJKtu_bookmarks_hook: } + } + } + } +\msg_new:nnn { xCJK2uni } { UTF-8-encoding } + { It~is~not~necessary~to~load~xCJK2uni~in~UTF-8~encoding. } +\cs_new_eq:NN \useCJKencmap \__CJKtu_use_enc_map:n +\cs_new_eq:NN \CJKchartouni \__CJKtu_char_to_unicode:n +\cs_new_eq:NN \CJKsfdtouni \__CJKtu_sfd_to_unicode:nn +\useCJKencmap { GBK } +%% +%% This package consists of the file xCJK2uni.dtx, +%% and the derived files xCJK2uni.pdf, +%% xCJK2uni.sty, +%% xCJK2uni.ins, +%% xCJK2uni-make.ltx, +%% xCJK2uni-UBg5plus.def, +%% xCJK2uni-UBig5.def, +%% xCJK2uni-UGB.def, +%% xCJK2uni-UGBK.def, +%% xCJK2uni-UJIS.def, +%% xCJK2uni-UKS.def, +%% c****.cmap, and +%% README. +%% +%% End of file `xCJK2uni.sty'. |