summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/platex/pxjahyper/pxjahyper-enc.sty
blob: f51dc75e783f9f020e60510d70fcb3b1179e99b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
%%
%% This is file 'pxjahyper-enc.sty'.
%%
%% Copyright (c) 2012-2021 Takayuki YATO (aka. "ZR")
%%   GitHub:   https://github.com/zr-tex8r
%%   Twitter:  @zr_tex8r
%%
%% This package is distributed under the MIT License.
%%

%% package declaration
\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{pxjahyper-enc}[2021/06/06 v0.9c]
\def\pxhe@pkgname{pxjahyper-enc}
\providecommand{\bxDebug}[1]{}

%--------------------------------------- package options

%% variables
\let\pxhe@driver=d

% driver options
\DeclareOption{dvipdfmx}{%
  \let\pxhe@driver=d\relax
}
\DeclareOption{dvips}{%
  \let\pxhe@driver=s\relax
}
\DeclareOption{nodvidriver}{%
  \let\pxhe@driver=0\relax
}
% dispatch
\ProcessOptions*

%--------------------------------------- user interface

%% variables
\let\pxhe@bigcode=t
\let\pxhe@default@tounicode=t

%%<*> \suppressbigcode
\@onlypreamble\suppressbigcode
\newcommand*\suppressbigcode{%
  \global\let\pxhe@bigcode=f\relax
}

%%<*> \suppressdefaulttounicode
\@onlypreamble\suppressdefaulttounicode
\newcommand*\suppressdefaulttounicode{%
  \global\let\pxhe@default@tounicode=f\relax
}

%%<+> \pxjahyperToUnicodeSpecial{<name>}
\newcommand*\pxjahyperToUnicodeSpecial[1]{%
  \edef\pxhe@tmpa{%
    \noexpand\pxhe@begin@dvi@hook{\special{pdf:tounicode #1}}%
  }\pxhe@tmpa
}

%--------------------------------------- environment

%% check
\ifx d\pxhe@driver\else
  \ifx s\pxhe@driver
    \PackageWarningNoLine\pxhe@pkgname
     {Unsupported driver (dvips)}
  \fi
  \let\pxhe@begin@dvi@hook\@gobble
\expandafter\endinput\fi\relax

%% switch 'pxhe@new@hook@system'
\newif\ifpxhe@new@hook@system
\@ifl@t@r\fmtversion{2020/10/01}{\pxhe@new@hook@systemtrue}{}

%% \pxhe@jcode
\ifnum     \jis"2121="8140
  \let\pxhe@jcode=s\relax
\else\ifnum\jis"2121="A1A1
  \let\pxhe@jcode=e\relax
\else\ifnum\jis"2121="3000
  \let\pxhe@jcode=u\relax
\fi\fi\fi
\ifx\pxhe@jcode\@undefined
  \PackageError\pxhe@pkgname
   {Unknown internal kanji code}
   {Package loading is aborted right now.}
  \expandafter\endinput
\fi

%--------------------------------------- begin-dvi hook (new)
\ifpxhe@new@hook@system

%% \pxhe@hook@label
\def\pxhe@hook@label{pxjahyper/enc}

%% \pxhe@begin@dvi@hook{<text>}
\def\pxhe@begin@dvi@hook#1{%
  \AddToHook{shipout/firstpage}[\pxhe@hook@label]{#1}%
}

%% declare necessary rules
\DeclareHookRule{shipout/firstpage}{\pxhe@hook@label}{<}{hyperref}

\fi
%--------------------------------------- begin-dvi hook (old)
\ifpxhe@new@hook@system\else

%% packages
\RequirePackage{atbegshi}[2011/10/05]% v1.16

%% \pxhe@begin@dvi@hook{<text>}
\def\pxhe@begin@dvi@hook#1{%
  \begingroup
    \toks\z@{#1}%
    \toks\tw@\expandafter{\AtBegShi@HookFirst}%
    \xdef\AtBegShi@HookFirst{\the\toks@\the\toks\tw@}%
  \endgroup
}

\fi
%--------------------------------------- default tounicode special

%% \pxhe@cmap@name
\def\pxhe@cmap@name{%
  \if e\pxhe@jcode % euc
    EUC-UCS2%
  \else\if s\pxhe@jcode % sjis
    90ms-RKSJ-UCS2%
  \else\if t\pxhe@bigcode % ucs, bigcode
    UTF8-UTF16%
  \else % ucs, no bigcode
    UTF8-UCS2%
  \fi\fi\fi
}

%% \pxhe@do@default@tounicode
\def\pxhe@do@default@tounicode{%
  \if t\pxhe@default@tounicode
    \special{pdf:tounicode \pxhe@cmap@name}%
  \fi
}
\pxhe@begin@dvi@hook{\pxhe@do@default@tounicode}

%--------------------------------------- done
\endinput
%% EOF