%%% written by Dohyun Kim <nomos at ktug dot kr>
%%% public domain
%%%
%%% $Id: luatexko.tex,v 1.64 2011/07/21 06:01:15 nomos Exp $

\chardef\catcodeofatchar\the\catcode`@
\catcode`@ = 11

\ifcsname hangul@font\endcsname
  \expandafter\endinput\fi % prevent multiple loading

\input luaotfload.sty

\input luatexko-core.tex

%%%%%%%%%%%%
% plain only

\def\verticaltypesetting{%
  %\pdfpagesattr{ /Rotate 90 }
  \dimen@\hsize\hsize\vsize\vsize\dimen@
  \edef\plainoutput{\unexpanded{\dimen@\hsize\hsize\vsize\vsize\dimen@}%
    \unexpanded\expandafter{\plainoutput}}
  \def\pagebody{\setbox\z@\vbox to\hsize{\boxmaxdepth=\maxdepth
    \pagecontents}\luatexkorotatebox\z@\box\z@}
  \maxdepth\z@ \luatexko@vertical}

%% hangul in math mode -- plain
\newfam\symmathhangul
\def\setmathhangulfont#1#{\setmathhangulfont@}
\def\setmathhangulfont@#1{%
  \font\tenhangul   = "#1" at 10pt
  \font\sevenhangul = "#1" at 7pt
  \font\fivehangul  = "#1" at 5pt
  \textfont\symmathhangul         = \tenhangul
  \scriptfont\symmathhangul       = \sevenhangul
  \scriptscriptfont\symmathhangul = \fivehangul}
\setmathhangulfont{UnBatang}
\setmathhangulblock{AC00}{D7A3}

%%%%%
\let\check@hangul@family\relax
\let\check@hanja@family \relax

\def\hangulfont{\afterassignment\luatexko@hangul@selectfont\font\hangul@font}
\def\hanjafont {\afterassignment\luatexko@hanja@selectfont\font\hanja@font}

% disabled because of \"a etc.
%\font\tenrm={file:lmroman10-regular:script=latn;+liga;+kern;+trep;+tlig;}
%\font\tenbf={file:lmroman10-bold:script=latn;+liga;+kern;+trep;+tlig;}
%\tenrm
\hangulfont{file:UnBatang:interhangul=-0.04;interlatincjk=0.125;%
  punctraise=-0.125} at 10pt

% font resize under plain tex
% ex: \resizecurrentfont{9pt}
\def\resizecurrentfont#1{%
  \edef\curr@font@name{\directlua{
    local f = "\fontname\font"
    f = f and string.gsub(f," at .+","")
    if f then
      tex.sprint(f)
    else
      error("cannot get current font name")
    end
  }}%
  \font\resized@font="\curr@font@name" at #1\resized@font}

\catcode`@\catcodeofatchar

\endinput
