summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/xetex/zhspacing/zhfont.sty
blob: cc3f98d382bb3a37e6a9ae3f8d0c7657f3125db9 (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
%	zhfont.sty	coded by YIN Dian
%	Simplify setting various font effects
%	Hist:	071204	First coded.
%		071210	Improved. Added \newfontfamilywithslant and
%			\newfontfamilywithslantandbold to simplify setting.
%		071211	Added fake bold support.
%		071231	Added underdot support.
%		080102	Minor changes on underdot. Don's use \scantokens.
%			Fixed bug of \zhfont in ulem. Added font family
%			selection and fake bold support in active hanzi.
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\def\filedate{2008/01/02}
\ProvidesPackage{zhfont}[\filedate]
\RequirePackage{zhspacing}
\RequirePackage{zhulem}
\newif\ifzhfont@fakebold
\zhfont@fakeboldfalse
\DeclareOption{fakebold}{\zhfont@fakeboldtrue}
\ProcessOptions\relax

\def\zhs@tmpmacro{}
\def\zhs@curr@fam{-1}

\zhnfsssavefont
\g@addto@macro\zhs@savefont{%
  \long\edef\zhs@tmpmacro{\f@family}%
  \def\zhs@curr@fam{0}%
  \ifx\zhs@tmpmacro\sfdefault
    \def\zhs@curr@fam{1}%
  \else\ifx\zhs@tmpmacro\ttdefault
    \def\zhs@curr@fam{2}%
  \fi\fi
  \edef\zhs@tmpmacro{\f@family}%
  \ifx\zhs@tmpmacro\sfdefault
    \def\zhs@curr@fam{1}%
  \else\ifx\zhs@tmpmacro\ttdefault
    \def\zhs@curr@fam{2}%
  \fi\fi
}
\ifzhfont@fakebold
\def\zhfont@bx{bx}
\g@addto@macro\zhs@savefont{%
  \ifx\f@series\zhfont@bx
    \special{pdf: literal direct q 0.3 w 2 Tr}%
  \fi
}
\g@addto@macro\zhs@restorefont{%
  \ifx\f@series\zhfont@bx
    \special{pdf: literal direct 0 Tr}%
  \fi
}
\fi

\def\newfontfamilywithslant#1#2{%
  \newfontfamily#1[ItalicFont=#2,ItalicFeatures={RawFeature={slant=0.17}},BoldItalicFont=#2,BoldItalicFeatures={RawFeature={slant=0.17}}]{#2}%
}
\def\newfontfamilywithslantandbold#1#2#3{%
  \newfontfamily#1[BoldFont=#3,ItalicFont=#2,ItalicFeatures={RawFeature={slant=0.17}},BoldItalicFont=#3,BoldItalicFeatures={RawFeature={slant=0.17}}]{#2}%
}

\ifzhfont@fakebold
  \newfontfamilywithslant\zhrmfont{SimSun}
  \newfontfamilywithslant\zhsffont{SimHei}
  \newfontfamilywithslant\zhttfont{[simfang.ttf]}
\else
  \newfontfamilywithslantandbold\zhrmfont{SimSun}{SimHei}
  \newfontfamilywithslant\zhsffont{SimHei}
  \newfontfamilywithslantandbold\zhttfont{[simfang.ttf]}{[simkai.ttf]}
\fi
\def\zhfont{\ifcase\zhs@curr@fam\zhrmfont\or\zhsffont\or\zhttfont\else\zhrmfont\fi}

\def\setzhmainfont{\newfontfamily\zhrmfont}
\def\setzhsansfont{\newfontfamily\zhsffont}
\def\setzhmonofont{\newfontfamily\zhttfont}

\enableactivehanzi
\def\zhhanzihook#1{%
  % select family
  \long\edef\zhs@tmpmacro{\f@family}%
  \def\zhs@curr@fam{0}%
  \ifx\zhs@tmpmacro\sfdefault
    \def\zhs@curr@fam{1}%
  \else\ifx\zhs@tmpmacro\ttdefault
    \def\zhs@curr@fam{2}%
  \fi\fi
  \edef\zhs@tmpmacro{\f@family}%
  \ifx\zhs@tmpmacro\sfdefault
    \def\zhs@curr@fam{1}%
  \else\ifx\zhs@tmpmacro\ttdefault
    \def\zhs@curr@fam{2}%
  \fi\fi
  \ifzhfont@fakebold\ifx\f@series\zhfont@bx
    \special{pdf: literal direct q 0.3 w 2 Tr}%
  \fi\fi
  {\XeTeXinterchartokenstate=0\zhs@font #1}%
  \ifzhfont@fakebold\ifx\f@series\zhfont@bx
    \special{pdf: literal direct 0 Tr}%
  \fi\fi
}

\def\underdot@dot{\XeTeXinterchartokenstate=0\zhpunctfont \vbox to 0.5em{\vss\hbox{·}\vss}}
%\def\underdot@dot{\vbox to 0.5em{\vss\hbox{\bf .}\vss}}
\newskip\underdot@skip
\underdot@skip=2.5pt
\def\underdot{%
  \begingroup
  \makehanziglobalactive
  \def\zhhanzihook##1{%
    \setbox0=\hbox{\underdot@dot}%
    \leavevmode\vtop{\baselineskip=\underdot@skip\lineskiplimit=-\maxdimen
    \advance\baselineskip\ht0
    % select family
    \long\edef\zhs@tmpmacro{\f@family}%
    \def\zhs@curr@fam{0}%
    \ifx\zhs@tmpmacro\sfdefault
      \def\zhs@curr@fam{1}%
    \else\ifx\zhs@tmpmacro\ttdefault
      \def\zhs@curr@fam{2}%
    \fi\fi
    \edef\zhs@tmpmacro{\f@family}%
    \ifx\zhs@tmpmacro\sfdefault
      \def\zhs@curr@fam{1}%
    \else\ifx\zhs@tmpmacro\ttdefault
      \def\zhs@curr@fam{2}%
    \fi\fi
    \ialign{####\cr\XeTeXinterchartokenstate=0\zhs@font 
    \ifzhfont@fakebold\ifx\f@series\zhfont@bx
    \special{pdf: literal direct q 0.3 w 2 Tr}##1%
    \special{pdf: literal direct 0 Tr}\else ##1\fi\else ##1\fi
    \cr\hidewidth\box0\hidewidth\cr}}%
  }%
  \underd@t
}
\def\underd@t#1{%
  #1%
  \makehanzigloballetter
  \endgroup
}

\endinput