summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/xetex/xetexko/xetexko-vertical.sty
blob: 0e82f313a235de5295b748650f6dbf79c8164047 (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
% $Id: xetexko-vertical.sty,v 1.12 2012/12/13 09:13:00 nomos Exp $
%
% Copyright (c) 2013 Dohyun Kim  <nomos at ktug org>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% 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.3c or later is part of all distributions of LaTeX
% version 2006/05/20 or later.

\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname ProvidesPackage\endcsname\relax\else
  \ProvidesPackage{xetexko-vertical}
    [2013/03/27 v2.0 Vertical environment for XeTeX-ko]
\fi

\unless\ifcsname @tempdima\endcsname\newdimen\@tempdima\fi
\unless\ifcsname @tempdimb\endcsname\newdimen\@tempdimb\fi
\unless\ifcsname @tempdimc\endcsname\newdimen\@tempdimc\fi
\unless\ifcsname AtBeginDocument\endcsname\def\AtBeginDocument#1{#1}\fi
\unless\ifcsname @onlypreamble\endcsname\def\@onlypreamble#1{}\fi

% do not veticalize headline/footline
\protected\def\verticaltypesetting{%
  \AtBeginDocument{\XK@vertical@spacing}%
  \maxdepth\z@
  \dimen@\textwidth
  \textwidth\textheight
  \textheight\dimen@
  \edef\@outputpage{%
    \unexpanded{\xetexko@rotatebox\@outputbox\textwidth\textheight}%
    \unexpanded\expandafter{\@outputpage}}%
}
\@onlypreamble\verticaltypesetting

\def\xetexko@rotatebox#1{%
  \ifvbox#1\count@\@ne\else\count@\z@\fi
  \dimen@\wd#1\dimen@ii\dimexpr\ht#1+\dp#1\relax
  \setbox#1\ifnum\count@=\@ne
  \vbox to\dimen@\bgroup\hbox to\dimen@ii\bgroup\hfil\else
  \hbox to\dimen@ii\bgroup\vbox to\dimen@\bgroup\fi
    \wd#1\z@ \ht#1\z@ \dp#1\z@
    \special{x:gsave}\special{x:rotate -90}\box#1\special{x:grestore}%
    \ifnum\count@=\@ne\egroup\vfil\else\vfil\egroup\hfil\fi\egroup
}

% users can declare vertical EM size, which might be different from 1em.
\newdimen\verticalem

\def\XK@vertical@spacing{%
  \ifnum\verticalem > \z@
    \def\XK@vert@half@em{.5\verticalem}%
  \else
    \def\XK@vert@half@em{.5em}%
  \fi
  \def\precjkopenparen {\leavevmode\hbox to\XK@vert@half@em\bgroup\hss}%
  \def\precjkcloseparen{\leavevmode\hbox to\XK@vert@half@em\bgroup}%
  \def\precjkfullstop  {\leavevmode\hbox to\XK@vert@half@em\bgroup}%
  \spaceskip\XK@vert@half@em plus\XK@vert@half@em\relax
  \parindent\XK@vert@half@em \parindent2\parindent
}

\protected\long\def\vertical#1{%
  \setbox\z@\vbox\bgroup
    \hsize=#1%
    \leftskip\z@
    \rightskip\z@
    \parindent\z@
    \everypar{}%
    \XK@vertical@spacing
}

\protected\def\endvertical{%
  \egroup
  \@tempdima\wd\z@
  \@tempdimb\ht\z@
  \@tempdimc\dp\z@
  \setbox\z@\hbox{%
    \kern\dimexpr\@tempdimb+0.5em\relax
    \wd\z@\z@
    \ht\z@\z@
    \dp\z@\z@
    \special{x:gsave}%
    \special{x:rotate -90}%
    \box\z@
    \special{x:grestore}}%
  \wd\z@\dimexpr\@tempdimb+\@tempdimc\relax
  \ht\z@\z@
  \dp\z@\z@
  \leavevmode
  \raise\dimexpr\@tempdima-\@tempdimc\relax\box\z@
}

\protected\def\vertlatin#1{\leavevmode\lower0.5ex\hbox{\latinmarks #1}}

\endinput

%% example:
%\newhangulfontfamily\myvertfont
%  [Script=Hangul,Vertical=RotatedGlyphs]
%  {HCR Dotum LVT}
%\verticalem=1.05em
%\begin{vertical}{12em}\myvertfont
%  세로쓰기 영역.
%  #1 = 세로길이
%\end{vertical}