summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-05-13 22:13:08 +0000
committerKarl Berry <karl@freefriends.org>2014-05-13 22:13:08 +0000
commit8ed901e81f474c7cf2946183f99b5836d40ffcd7 (patch)
tree0022083d26affb19815426f497b91ad443d74ebe /Master/texmf-dist/tex/luatex
parentbd7687e8abb5975905db822498e640ca7e2e1b2c (diff)
luatexko (11may14)
git-svn-id: svn://tug.org/texlive/trunk@34018 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/luatexko/luatexko-core.sty140
-rw-r--r--Master/texmf-dist/tex/luatex/luatexko/luatexko-normalize.lua90
-rw-r--r--Master/texmf-dist/tex/luatex/luatexko/luatexko-uhc2utf8.lua37
-rw-r--r--Master/texmf-dist/tex/luatex/luatexko/luatexko.lua524
-rw-r--r--Master/texmf-dist/tex/luatex/luatexko/luatexko.sty537
5 files changed, 808 insertions, 520 deletions
diff --git a/Master/texmf-dist/tex/luatex/luatexko/luatexko-core.sty b/Master/texmf-dist/tex/luatex/luatexko/luatexko-core.sty
index 22cf34ffdfa..835f8b14baf 100644
--- a/Master/texmf-dist/tex/luatex/luatexko/luatexko-core.sty
+++ b/Master/texmf-dist/tex/luatex/luatexko/luatexko-core.sty
@@ -1,6 +1,6 @@
% luatexko-core.sty
%
-% Copyright (c) 2013 Dohyun Kim <nomos at ktug org>
+% Copyright (c) 2013-2014 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
@@ -12,20 +12,21 @@
\ifx\ProvidesPackage\undefined
\input luaotfload.sty
+ \ifcsname ifpdf\endcsname\else \input ifpdf.sty \fi
\catcode`@ = 11
\else
- \ProvidesPackage{luatexko-core}[2014/01/04 v1.4 Typesetting Korean with LuaTeX]
+ \ProvidesPackage{luatexko-core}[2014/05/11 v1.5 Typesetting Korean with LuaTeX]
\RequirePackage{luaotfload}[2013/05/23]
\fi
%% attributes
-\newluatexattribute\finemathattr \finemathattr\@ne % finemath on by default
+\newluatexattribute\finemathattr \finemathattr\tw@ % finemath on by default
\newluatexattribute\cjtypesetattr
\newluatexattribute\dotemphattr
\newluatexattribute\autojosaattr
\newluatexattribute\luakorubyattr \chardef\luakorubyattrnum\the\allocationnumber
-\newluatexattribute\hangfntattr
-\newluatexattribute\hanjfntattr
+\newluatexattribute\hangulfntattr
+\newluatexattribute\hanjafntattr
\newluatexattribute\fallbackfntattr
\newluatexattribute\hangulpunctsattr
@@ -72,13 +73,13 @@
\def\dotemphraise{0.4em }
\unless\ifdefined\bfseries\let\bfseries\bf\fi
\def\dotemphchar{\bfseries ^^^^02d9}
-\newcount\dotemph@cnt \dotemph@cnt\z@
+\newcount\luakodotemphcnt \luakodotemphcnt\z@
\protected\def\dotemph#1{{%
- \ifnum\dotemph@cnt > 100 \global\dotemph@cnt\z@ \fi
- \global\advance\dotemph@cnt\@ne
+ \ifnum\luakodotemphcnt > 65535 \luakodotemphcnt\z@ \fi
+ \global\advance\luakodotemphcnt\@ne
\setbox\z@\hbox{\raise\dotemphraise\hbox{\dotemphchar}}\ht\z@\z@\dp\z@\z@
- \directlua{luatexko.dotemphnode[\the\dotemph@cnt] = node.copy_list(tex.box[0])}%
- \dotemphattr\dotemph@cnt #1}}
+ \directlua{luatexko.dotemphnode[\the\luakodotemphcnt] = node.copy_list(tex.box[0])}%
+ \dotemphattr\luakodotemphcnt #1}}
%% ruby : ruby.sty by Lemberg is excellent; but
%% it doesn't match well with luatexko, so implemented anew
@@ -90,12 +91,12 @@
\let\rubyoverlap\ruby@overlaptrue
\let\rubynooverlap\ruby@overlapfalse
\rubyoverlap % ruby may protrude over adjacent chars
-\newcount\luakorubyattr@cnt\luakorubyattr@cnt\z@
+\newcount\luakorubyattrcnt\luakorubyattrcnt\z@
\protected\def\ruby#1#2{%
- \ifnum\luakorubyattr@cnt > 1000 \global\luakorubyattr@cnt\z@ \fi
- \global\advance\luakorubyattr@cnt\@ne
+ \ifnum\luakorubyattrcnt > 65535 \luakorubyattrcnt\z@ \fi
+ \global\advance\luakorubyattrcnt\@ne
\begingroup
- \setbox\z@\hbox attr\luakorubyattrnum\luakorubyattr@cnt{% base character
+ \setbox\z@\hbox attr\luakorubyattrnum\luakorubyattrcnt{% base character
\vrule width\z@ height.88em depth\z@\relax #1}%
\setbox\tw@\hbox{% ruby
\ifdefined\rubyfont \rubyfont \fi
@@ -112,10 +113,13 @@
\ifdefined\hanja@font
\luatexko@resize@font\hanjafont{}\hanja@font\rubysize
\fi
+ \ifdefined\fallback@font
+ \luatexko@resize@font\fallbackfont{}\fallback@font\rubysize
+ \fi
\fi
\fi #2}\ht\tw@\z@\dp\tw@\z@
\directlua{%
- luatexko.rubynode[\the\luakorubyattr@cnt] = {
+ luatexko.rubynode[\the\luakorubyattrcnt] = {
node.copy_list(tex.box[2]),
\number\numexpr\dimexpr\rubysep\relax\relax,
\ifruby@overlap true\else false\fi}}%
@@ -123,20 +127,18 @@
\endgroup}
\ifcsname selectfont\endcsname\else
- % font resize under plain tex
- \def\luatexko@resize@font#1#2#3#4{%
- \expandafter\dimen@\pdffontsize#3\relax
- \edef\luatexko@tmp@fontname{%
- \directlua{
- local f = [===[\fontname#3]===]
- f = string.gsub(f," at .+","")
- tex.sprint(f) }}%
- #1#2=\luatexko@tmp@fontname\space at #4\dimen@
- #2}
+% font resize under plain tex
+\begingroup\edef\x{\endgroup
+ \def\noexpand\rem@vesizepart##1\detokenize{ at}##2\noexpand\end{##1}}\x
+\def\luatexko@resize@font#1#2#3#4{%
+ \begingroup
+ \edef\x@{\noexpand\rem@vesizepart\fontname#3\detokenize{ at}\noexpand\end}%
+ \edef\y@{\endgroup#1\noexpand#2 \x@\space at#4\dimexpr\pdffontsize#3\relax}%
+ \y@#2}
\fi
%% vertical typesetting
-%% EXPERIMENTAL code: don't use this
+%% EXPERIMENTAL code
\def\luatexko@vertical{%
\ifnum\cjtypesetattr<\@ne
\cjtypesetattr\z@ % korean-vertical
@@ -160,8 +162,13 @@
\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@
- \pdfliteral{ q 0 -1 1 0 0 0 cm}\box#1\pdfliteral{ Q}%
+ \luatexko@rotate@clockwise{\box#1}%
\ifnum\count@=\@ne\egroup\vfil\else\vfil\egroup\hfil\fi\egroup}
+\def\luatexko@rotate@clockwise#1{%
+ \ifpdf\pdfliteral{q 0 -1 1 0 0 0 cm}#1\pdfliteral{Q}%
+ \else\special{pdf:btrans rotate -90}#1\special{pdf:etrans}%
+ \fi
+}
% do not veticalize headline/footline
\ifdefined\ProvidesPackage % for latex
@@ -185,25 +192,25 @@
%% especially linebreak does not occur inside cjk words.
\def\ulinewidth{0.04em }
\def\ulinedown {0.25em }
-\newcount\ulinebox@cnt\ulinebox@cnt\z@
+\newcount\luakoulineboxcnt\luakoulineboxcnt\z@
\protected\def\uline#1{%
- \ifnum\ulinebox@cnt > 100 \global\ulinebox@cnt\z@ \fi
- \global\advance\ulinebox@cnt\@ne
+ \ifnum\luakoulineboxcnt > 65535 \luakoulineboxcnt\z@ \fi
+ \global\advance\luakoulineboxcnt\@ne
\dimen@\dimexpr\ulinedown+\ulinewidth\relax
\dimen@ii-\dimexpr\ulinedown\relax
\setbox\z@\hbox{\vrule width\z@ height\dimen@ii depth\dimen@}%
- \directlua{luatexko.ulinebox[\the\ulinebox@cnt]=node.copy_list(tex.box[0].head)}%
- \leavevmode\special{luako:ulinebegin=\the\ulinebox@cnt}%
+ \directlua{luatexko.ulinebox[\the\luakoulineboxcnt]=node.copy_list(tex.box[0].head)}%
+ \leavevmode\special{luako:ulinebegin=\the\luakoulineboxcnt}%
#1\special{luako:ulineend}}
% strike-out
\protected\def\sout#1{{\def\ulinedown{-0.5ex-\ulinewidth/2}\uline{#1}}}
% ulem with arbitray box
\protected\def\markoverwidth#1#2{%
- \ifnum\ulinebox@cnt > 100 \global\ulinebox@cnt\z@ \fi
- \global\advance\ulinebox@cnt\@ne
+ \ifnum\luakoulineboxcnt > 65535 \luakoulineboxcnt\z@ \fi
+ \global\advance\luakoulineboxcnt\@ne
\setbox\z@\hbox{#1}%
- \directlua{luatexko.ulinebox[\the\ulinebox@cnt]=node.copy_list(tex.box[0])}%
- \leavevmode\special{luako:ulinebegin=\the\ulinebox@cnt}%
+ \directlua{luatexko.ulinebox[\the\luakoulineboxcnt]=node.copy_list(tex.box[0])}%
+ \leavevmode\special{luako:ulinebegin=\the\luakoulineboxcnt}%
#2\special{luako:ulineend}}
\protected\def\uuline{\dimen@ii-\dimexpr\ulinedown\relax
\dimen@\dimexpr\ulinedown+\ulinewidth\relax
@@ -219,41 +226,42 @@
%% hangul font -- core
\def\luatexko@hangul@selectfont{%
+ \ifdefined\hangul@font
\begingroup
\let\luatexko@hangul@selectfont\relax
\let\luatexko@hanja@selectfont\relax
\let\luatexko@fallback@selectfont\relax
- \check@hangul@family
- \ifdefined\hangul@font \hangul@font \fi
+ \hangul@font
\expandafter\expandafter\expandafter
\endgroup
- \expandafter\hangfntattr\luatexfontid\font\relax
+ \expandafter\hangulfntattr\luatexfontid\font\relax
+ \fi
}
\def\luatexko@hanja@selectfont{%
+ \ifdefined\hanja@font
\begingroup
\let\luatexko@hangul@selectfont\relax
\let\luatexko@hanja@selectfont\relax
\let\luatexko@fallback@selectfont\relax
- \check@hanja@family
- \ifdefined\hanja@font \hanja@font \fi
+ \hanja@font
\expandafter\expandafter\expandafter
\endgroup
- \expandafter\hanjfntattr\luatexfontid\font\relax
+ \expandafter\hanjafntattr\luatexfontid\font\relax
+ \fi
}
\def\luatexko@fallback@selectfont{%
+ \ifdefined\fallback@font
\begingroup
\let\luatexko@hangul@selectfont\relax
\let\luatexko@hanja@selectfont\relax
\let\luatexko@fallback@selectfont\relax
- \check@fallback@family
- \ifdefined\fallback@font \fallback@font \fi
+ \fallback@font
\expandafter\expandafter\expandafter
\endgroup
\expandafter\fallbackfntattr\luatexfontid\font\relax
+ \fi
}
-\let\check@hangul@family\relax
-\let\check@hanja@family \relax
-\let\check@fallback@family\relax
+
% user interface for plain tex
\protected\def\hangulfont
{\afterassignment\luatexko@hangul@selectfont\font\hangul@font}
@@ -270,12 +278,10 @@
\ifnum\count@<"#2
\advance\count@\@ne
\repeat}
-\def\setmathhangulfont#1#{\setmathhangul@font@}
-\ifdefined\ProvidesPackage
- \let\setmathhangul@font@\@gobble
-\else
+\ifdefined\ProvidesPackage\else
% for plain; see luatexko.sty for latex
\newfam\symmathhangul
+ \def\setmathhangulfont#1#{\setmathhangul@font@}
\def\setmathhangul@font@#1{%
\font\tenhangul = "#1" at 10pt
\font\sevenhangul = "#1" at 7pt
@@ -356,6 +362,38 @@
\fi\fi
}
+% Actual Text: beware that #2 should not be divided into separate pages.
+% \actualtext* variant inserts space char from phvr8r. see accsupp manual
+\protected\def\actualtext#1#{%
+ \ifx\empty#1\empty
+ \expandafter\actualtext@\expandafter!%
+ \else
+ \expandafter\actualtext@\expandafter*%
+ \fi
+}
+\def\actualtext@#1#2{%
+ \luatexko@pdfspecial{/Span<</ActualText\directlua{
+ luatexko.actualtext("\luatexluaescapestring{\detokenize{#2}}")
+ }>>BDC}%
+ #2%
+ \ifx*#1%
+ \begingroup
+ \ifdefined\actualtext@spacefont\else
+ \global\font\actualtext@spacefont=phvr8r\relax
+ \fi
+ \setbox\z@\hbox{\actualtext@spacefont\char32}%
+ \wd\z@\z@\ht\z@\z@\dp\z@\z@
+ \leavevmode\copy\z@
+ \endgroup
+ \fi
+ \luatexko@pdfspecial{EMC}%
+}
+\def\luatexko@pdfspecial#1{%
+ \ifpdf\pdfliteral page{#1}%
+ \else\special{pdf:content #1}%
+ \fi
+}
+
%% 말줄임표
\def\hellipsis{^^^^2026^^^^2026}
diff --git a/Master/texmf-dist/tex/luatex/luatexko/luatexko-normalize.lua b/Master/texmf-dist/tex/luatex/luatexko/luatexko-normalize.lua
index 8c6e0bc3d98..4c2fde7fff0 100644
--- a/Master/texmf-dist/tex/luatex/luatexko/luatexko-normalize.lua
+++ b/Master/texmf-dist/tex/luatex/luatexko/luatexko-normalize.lua
@@ -1,6 +1,6 @@
-- luatexko-normalize.lua
--
--- Copyright (c) 2013 Dohyun Kim <nomos at ktug org>
+-- Copyright (c) 2013-2014 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
@@ -12,8 +12,8 @@
luatexbase.provides_module({
name = "luatexko-normalize",
- version = 1.2,
- date = "2013/06/10",
+ version = 1.5,
+ date = "2014/05/11",
author = "Dohyun Kim",
description = "Hangul normalization",
license = "LPPL v1.3+",
@@ -22,9 +22,9 @@ luatexbase.provides_module({
luatexkonormalize = luatexkonormalize or {}
local luatexkonormalize = luatexkonormalize
-local cho = "[\225\132\128-\225\132\146]"
-local jung = "[\225\133\161-\225\133\181]"
-local jong = "[\225\134\168-\225\135\130]"
+local ncho = "[\225\132\128-\225\132\146]"
+local njung = "[\225\133\161-\225\133\181]"
+local jong = "[\225\134\168-\225\135\191\237\159\139-\237\159\187]"
local ojong = "[\225\135\131-\225\135\191\237\159\139-\237\159\187]"
local compathanja = "[\239\164\128-\239\168\139]"
local chanjatohanja = {
@@ -398,36 +398,39 @@ local jamotocjamo = {
}
}
+require "unicode"
local gsub = unicode.utf8.gsub
local byte = unicode.utf8.byte
local char = unicode.utf8.char
+local find = unicode.utf8.find
+local concat = table.concat
local add_to_callback = luatexbase.add_to_callback
local remove_from_callback = luatexbase.remove_from_callback
+local priority_in_callback = luatexbase.priority_in_callback
local jamo2syllable = function(l,v,t)
+ if find(t,ojong) then return end
l, v = byte(l), byte(v)
local s = (l - 0x1100) * 21
s = (s + v - 0x1161) * 28
- if t then
- t = byte(t)
- s = s + t - 0x11a7
+ if t ~= "" then
+ s = s + byte(t) - 0x11a7
end
- s = s + 0xac00
- return char(s)
+ return char(s + 0xac00)
end
-local hanguldecompose = function(buffer)
- buffer = gsub(buffer, "[가-힣]", function(s)
+local syllable2jamo = function(s)
s = byte(s) - 0xac00
- local cho = s / (21 * 28) + 0x1100
- local jung = (s % (21 * 28)) / 28 + 0x1161
- local jong = s % 28 + 0x11a7
- if jong > 0x11a7 then
- return char(cho)..char(jung)..char(jong)
- end
- return char(cho)..char(jung)
- end)
- return buffer
+ local t = {}
+ t[1] = char(s / 588 + 0x1100)
+ t[2] = char(s % 588 / 28 + 0x1161)
+ local jong = s % 28
+ t[3] = jong > 0 and char(jong + 0x11a7) or nil
+ return concat(t)
+end
+
+local hanguldecompose = function(buffer)
+ return gsub(buffer, "[가-힣]", syllable2jamo)
end
local function hanjanormalize(c)
@@ -442,48 +445,39 @@ local function jamo2cjamocho(c)
return jamo
end
-local function jamo2cjamojung(c)
+local function jamo2cjamojung(c,t)
+ if t ~= "" then return end
local jamo = jamotocjamo.cjung[byte(c)]
jamo = jamo and char(jamo)
return jamo
end
local hangulcompose = function(buffer)
- buffer = hanguldecompose(buffer)
- buffer = gsub(buffer, "("..cho..")("..jung..")("..jong..")", jamo2syllable)
- buffer = gsub(buffer, "("..cho..")("..jung..ojong..")", "%1\1%2")
- buffer = gsub(buffer, "("..cho..")("..jung..")", jamo2syllable)
- buffer = gsub(buffer, "([\225\132\128-\225\133\153])\225\133\160", jamo2cjamocho)
- buffer = gsub(buffer, "\225\133\159([\225\133\161-\225\134\161])", jamo2cjamojung)
- buffer = gsub(buffer, "\1", "")
- buffer = gsub(buffer, "("..compathanja..")", hanjanormalize)
+ buffer = gsub(buffer, "[가-힣]"..jong, hanguldecompose)
+ buffer = gsub(buffer, "("..ncho..")("..njung..")("..jong.."?)", jamo2syllable)
+ buffer = gsub(buffer,
+ "([\225\132\128-\225\133\153])\225\133\160", jamo2cjamocho)
+ buffer = gsub(buffer,
+ "\225\133\159([\225\133\161-\225\134\161])("..jong.."?)", jamo2cjamojung)
+ buffer = gsub(buffer, compathanja, hanjanormalize)
return buffer
end
-local loaded = false
-
-local function compose()
- if loaded then
+local function unload()
+ if priority_in_callback('process_input_buffer', 'luatexko-hangul-normalize') then
remove_from_callback('process_input_buffer', 'luatexko-hangul-normalize')
end
- loaded = true
+end
+luatexkonormalize.unload = unload
+
+local function compose()
+ unload()
add_to_callback('process_input_buffer', hangulcompose, 'luatexko-hangul-normalize')
end
luatexkonormalize.compose = compose
local function decompose()
- if loaded then
- remove_from_callback('process_input_buffer', 'luatexko-hangul-normalize')
- end
- loaded = true
+ unload()
add_to_callback('process_input_buffer', hanguldecompose, 'luatexko-hangul-normalize')
end
luatexkonormalize.decompose = decompose
-
-local function unload()
- if loaded then
- remove_from_callback('process_input_buffer', 'luatexko-hangul-normalize')
- end
- loaded = false
-end
-luatexkonormalize.unload = unload
diff --git a/Master/texmf-dist/tex/luatex/luatexko/luatexko-uhc2utf8.lua b/Master/texmf-dist/tex/luatex/luatexko/luatexko-uhc2utf8.lua
index 2afdad38532..3d28a668b1f 100644
--- a/Master/texmf-dist/tex/luatex/luatexko/luatexko-uhc2utf8.lua
+++ b/Master/texmf-dist/tex/luatex/luatexko/luatexko-uhc2utf8.lua
@@ -1,6 +1,6 @@
-- luatexko-uhc2utf8.lua
--
--- Copyright (c) 2013 Dohyun Kim <nomos at ktug org>
+-- Copyright (c) 2013-2014 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
@@ -12,8 +12,8 @@
luatexbase.provides_module({
name = "luatexko-uhc2utf8",
- version = 1.2,
- date = "2013/06/10",
+ version = 1.5,
+ date = "2014/05/11",
author = "Dohyun Kim",
description = "UHC (CP949) input encoding",
license = "LPPL v1.3+",
@@ -22,11 +22,12 @@ luatexbase.provides_module({
luatexkouhc2utf8 = luatexkouhc2utf8 or {}
local luatexkouhc2utf8 = luatexkouhc2utf8
-local find = string.find
+local match = string.match
local gsub = string.gsub
local byte = string.byte
-local len = string.len
local format = string.format
+local utfvalues = string.utfvalues
+require "unicode"
local ugsub = unicode.utf8.gsub
local ubyte = unicode.utf8.byte
local uchar = unicode.utf8.char
@@ -43,7 +44,7 @@ local function get_uhc_uni_table()
while true do
local line = file:read("*line")
if not line then break end
- local _,_,ea,eb,uni = find(line,"<(%x+)>%s+<(%x+)>%s+<(%x+)>")
+ local ea,eb,uni = match(line,"<(%x+)>%s+<(%x+)>%s+<(%x+)>")
if ea and eb and uni then
ea, eb, uni = tonumber(ea,16),tonumber(eb,16),tonumber(uni,16)
for i=ea,eb do
@@ -62,16 +63,18 @@ local t_uhc2ucs = t_uhc2ucs or get_uhc_uni_table()
local uhc_to_utf8 = function(buffer)
if not buffer then return end
-- check if buffer is already utf-8; better solution?
- local t = gsub(buffer,"[\0-\127]","")
- t = gsub(t,"[\194-\223][\128-\191]","")
- t = gsub(t,"[\224-\239][\128-\191][\128-\191]","")
- t = gsub(t,"[\240-\244][\128-\191][\128-\191][\128-\191]","")
- if len(t) == 0 then return buffer end
+ local isutf = true
+ for v in utfvalues(buffer) do
+ if v == 0xFFFD then -- REPLACEMENT CHARACTER
+ isutf = false
+ break
+ end
+ end
+ if isutf == true then return buffer end
-- now convert to utf8
buffer = gsub(buffer, "([\129-\253])([\65-\254])",
function(a, b)
- a, b = byte(a), byte(b)
- local utf = t_uhc2ucs[a * 256 + b]
+ local utf = t_uhc2ucs[byte(a) * 256 + byte(b)]
if utf then return uchar(utf) end
end)
return buffer
@@ -105,8 +108,9 @@ local function utf8_to_uhc (name)
name = ugsub(name, "[\161-\239\191\166]", -- 00A1..FFE6
function(u)
local c = t_ucs2uhc[ubyte(u)]
- if not c then return u end
- return format("%c%c", floor(c/256), c%256)
+ if c then
+ return format("%c%c", floor(c/256), c%256)
+ end
end)
return name
end
@@ -115,8 +119,7 @@ local function uhc_find_file (file, ...)
local f = kpse_find_file(file, ...)
if f then return f end
f = utf8_to_uhc(file)
- f = f and kpse_find_file(f, ...)
- return f
+ return f and kpse_find_file(f, ...)
end
local function start_uhc_filename ()
diff --git a/Master/texmf-dist/tex/luatex/luatexko/luatexko.lua b/Master/texmf-dist/tex/luatex/luatexko/luatexko.lua
index 8ef25e1f439..aa14bbc249f 100644
--- a/Master/texmf-dist/tex/luatex/luatexko/luatexko.lua
+++ b/Master/texmf-dist/tex/luatex/luatexko/luatexko.lua
@@ -1,6 +1,6 @@
-- luatexko.lua
--
--- Copyright (c) 2013 Dohyun Kim <nomos at ktug org>
+-- Copyright (c) 2013-2014 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
@@ -12,8 +12,8 @@
local err,warn,info,log = luatexbase.provides_module({
name = 'luatexko',
- date = '2014/01/06',
- version = 1.4,
+ date = '2014/05/11',
+ version = 1.5,
description = 'Korean linebreaking and font-switching',
author = 'Dohyun Kim',
license = 'LPPL v1.3+',
@@ -26,21 +26,21 @@ local dotemphnode,rubynode,ulinebox = {},{},{}
luatexko.dotemphnode = dotemphnode
luatexko.rubynode = rubynode
luatexko.ulinebox = ulinebox
-luatexko.hanjafontforhanja = luatexko.hanjafontforhanja or false
local stringbyte = string.byte
local stringgsub = string.gsub
local stringchar = string.char
local stringfind = string.find
local stringmatch = string.match
-local stringgmatch = string.gmatch
local stringformat = string.format
local string_sub = string.sub
local mathfloor = math.floor
local tex_round = tex.round
local tex_sp = tex.sp
+local texcount = tex.count
local fontdefine = font.define
-local utf8char = unicode.utf8.char
+
+local kpse_find_file = kpse.find_file
local fontdata = fonts.hashes.identifiers
@@ -57,14 +57,17 @@ local nodecount = node.count
local nodeslide = node.slide
local nodedimensions = node.dimensions
local nodetail = node.tail
+local end_of_math = node.end_of_math
+local nodenext = node.next
+local nodeprev = node.prev
local finemathattr = luatexbase.attributes.finemathattr
local cjtypesetattr = luatexbase.attributes.cjtypesetattr
local dotemphattr = luatexbase.attributes.dotemphattr
local autojosaattr = luatexbase.attributes.autojosaattr
local luakorubyattr = luatexbase.attributes.luakorubyattr
-local hangfntattr = luatexbase.attributes.hangfntattr
-local hanjfntattr = luatexbase.attributes.hanjfntattr
+local hangulfntattr = luatexbase.attributes.hangulfntattr
+local hanjafntattr = luatexbase.attributes.hanjafntattr
local fallbackfntattr = luatexbase.attributes.fallbackfntattr
local hangulpunctsattr = luatexbase.attributes.hangulpunctsattr
local luakoglueattr = luatexbase.new_attribute("luakoglueattr")
@@ -552,7 +555,6 @@ local function get_cjk_class (ch, cjtype)
end
return c
end
- return nil
end
local function get_font_table (fid)
@@ -597,8 +599,8 @@ end
local function get_unicode_char(curr)
local uni = curr.char
- if (uni > 0 and uni < 0xE000) or (uni > 0xF8FF and uni < 0xF0000) then
- return uni -- no pua
+ if (uni > 0xFF and uni < 0xE000) or (uni > 0xF8FF and uni < 0xF0000) then
+ return uni -- no pua. no nanumgtm??
end
-- tounicode is now reliable. backend is fixed
uni = get_font_char(curr.font, curr.char)
@@ -622,7 +624,7 @@ local function get_hlist_class_first (hlist)
elseif curr.id == gluenode then
if curr.spec and curr.spec.width ~= 0 then return end
end
- curr = curr.next
+ curr = nodenext(curr)
end
end
@@ -638,7 +640,7 @@ local function get_hlist_class_last (hlist,prevchar,prevfont)
elseif curr.id == gluenode then
if curr.spec and curr.spec.width ~= 0 then return end
end
- curr = curr.prev
+ curr = nodeprev(curr)
end
return prevchar, prevfont
end
@@ -679,7 +681,7 @@ end
local function koreanlatinskip (head,curr,currfont,prevfont,was_penalty)
local width = 0 -- default: 0em
- if has_attribute(curr,finemathattr) == 1 then -- not ttfamily
+ if (has_attribute(curr,finemathattr) or 0) > 0 then -- not ttfamily
local latincjk = get_font_feature(currfont, "interlatincjk")
if not latincjk then
latincjk = get_font_feature(prevfont, "interlatincjk")
@@ -700,8 +702,8 @@ local function cjk_insert_nodes(head,curr,currchar,currfont,prevchar,prevfont)
local p = get_cjk_class(prevchar, currentcjtype)
local c = get_cjk_class(currchar, currentcjtype)
---[[raise latin puncts
- if curr.id == glyphnode and has_attribute(curr,finemathattr) == 1 and c < 10 then -- not ttfamily
- local nn, raise = curr.next, nil
+ if curr.id == glyphnode and (has_attribute(curr,finemathattr) or 0) > 0 and c < 10 then -- not ttfamily
+ local nn, raise = nodenext(curr), nil
while nn do
if nn.id == glyphnode and latin_fullstop[nn.char] then
if not raise then
@@ -709,12 +711,11 @@ local function cjk_insert_nodes(head,curr,currchar,currfont,prevchar,prevfont)
raise = raise and tex_sp(raise)
end
if raise then
- nn.yoffset = nn.yoffset or 0
- nn.yoffset = nn.yoffset + raise
+ nn.yoffset = (nn.yoffset or 0) + raise
end
- nn = nn.next
+ nn = nodenext(nn)
elseif nn.id == kernnode then
- nn = nn.next
+ nn = nodenext(nn)
else
break
end
@@ -796,7 +797,8 @@ end
local function cjk_spacing_linebreak (head)
local prevchar,prevfont = nil,nil
- for curr in traverse(head) do
+ local curr = head
+ while curr do
if has_attribute(curr,finemathattr) then
if curr.id == gluenode then
prevchar,prevfont = nil,nil
@@ -815,8 +817,8 @@ local function cjk_spacing_linebreak (head)
end
if curr.subtype == 0 then
cjk_insert_nodes(head,curr,currchar,nil,prevchar,prevfont)
- prevchar,prevfont = nil,nil
- else
+ curr = end_of_math(curr)
+ if not curr then break end
prevchar,prevfont = currchar,nil
end
unset_attribute(curr,finemathattr)
@@ -831,6 +833,7 @@ local function cjk_spacing_linebreak (head)
else
prevchar,prevfont = 0,nil -- treat \verb as latin character.
end
+ curr = nodenext(curr)
end
end
@@ -838,55 +841,61 @@ end
-- remove japanese/chinese spaceskip
------------------------------------
local function remove_cj_spaceskip (head)
- for curr in traverse_id(gluenode,head) do
- local cjattr = has_attribute(curr,cjtypesetattr)
- local prv, nxt = curr.prev, curr.next
- if cjattr and cjattr > 0 and prv and nxt then
- local prevclass, prevchar, prevfont, nextclass
- if prv.id == hlistnode or prv.id == vlistnode then
- prevclass = get_hlist_class_last(prv)
- else
- -- what is this strange kern before \text??
- if prv.id == kernnode and prv.kern == 0 then
- prv = prv.prev
+ local curr, prevfont = head, nil
+ while curr do
+ if curr.id == mathnode and curr.subtype == 0 then
+ curr = end_of_math(curr)
+ elseif curr.id == gluenode then
+ local cjattr = has_attribute(curr,cjtypesetattr)
+ local prv, nxt = nodeprev(curr), nodenext(curr)
+ if cjattr and cjattr > 0 and prv and nxt then
+ local prevclass, prevchar, nextclass
+ if prv.id == hlistnode or prv.id == vlistnode then
+ prevclass = get_hlist_class_last(prv)
+ else
+ -- what is this strange kern before \text??
+ if prv.id == kernnode and prv.kern == 0 then
+ prv = nodeprev(prv)
+ end
+ if prv.id == glyphnode then
+ prevclass = get_cjk_class(get_unicode_char(prv), cjattr)
+ prevchar, prevfont = prv.char, prv.font
+ end
end
- if prv.id == glyphnode then
- prevclass = get_cjk_class(get_unicode_char(prv), cjattr)
- prevchar, prevfont = prv.char, prv.font
+ if nxt.id == glyphnode then
+ nextclass = get_cjk_class(get_unicode_char(nxt), cjattr)
+ elseif nxt.id == hlistnode or nxt.id == vlistnode then
+ nextclass = get_hlist_class_first(nxt)
end
- end
- if nxt.id == glyphnode then
- nextclass = get_cjk_class(get_unicode_char(nxt), cjattr)
- elseif nxt.id == hlistnode or nxt.id == vlistnode then
- nextclass = get_hlist_class_first(nxt)
- end
- if (prevclass and prevclass < 10) or (nextclass and nextclass < 10) then
- local subtype = curr.subtype
- if subtype == 13 then -- do not touch on xspaceskip for now
- remove_node(head,curr)
- else -- before \text?? spaceskip is replaced by glue type 0
- local spec = curr.spec
- local csp = spec and spec.width
- local cst = spec and spec.stretch
- local csh = spec and spec.shrink
- local fp = get_font_table(prevfont)
- fp = fp and fp.parameters
- local sp = fp and fp.space
- local st = fp and fp.space_stretch
- local sh = fp and fp.space_shrink
- sp = sp and tex_round(sp)
- st = st and tex_round(st)
- sh = sh and tex_round(sh)
- if prevchar and prevchar >= 65 and prevchar <= 90 then
- st = st and mathfloor(st*(999/1000))
- sh = sh and mathfloor(sh*(1001/1000))
- end
- if sp == csp and st == cst and sh == csh then
+ if (prevclass and prevclass < 10) or (nextclass and nextclass < 10) then
+ local subtype = curr.subtype
+ if subtype == 13 then -- do not touch on xspaceskip for now
remove_node(head,curr)
+ else -- before \text?? spaceskip is replaced by glue type 0
+ local spec = curr.spec
+ local csp = spec and spec.width
+ local cst = spec and spec.stretch
+ local csh = spec and spec.shrink
+ local fp = get_font_table(prevfont)
+ fp = fp and fp.parameters
+ local sp = fp and fp.space
+ local st = fp and fp.space_stretch
+ local sh = fp and fp.space_shrink
+ sp = sp and tex_round(sp)
+ st = st and tex_round(st)
+ sh = sh and tex_round(sh)
+ if prevchar and prevchar >= 65 and prevchar <= 90 then
+ st = st and mathfloor(st*(999/1000))
+ sh = sh and mathfloor(sh*(1001/1000))
+ end
+ if sp == csp and st == cst and sh == csh then
+ remove_node(head,curr)
+ end
end
end
end
end
+ curr = nodenext(curr)
end
end
@@ -906,7 +915,7 @@ local function compress_fullwidth_punctuations (head)
local ensize = emsize/2
local oneoften = emsize/10
local bbox = get_char_boundingbox(curr.font, curr.char)
- if not bbox then return head end --
+ bbox = bbox or {ensize-oneoften, ensize-oneoften, ensize+oneoften, ensize+oneoften}
if class == 2 or class == 4 then
local wd
if get_font_feature(curr.font,'vertical') then
@@ -1025,14 +1034,14 @@ local function get_ruby_side_kern (head)
if curr.width < rubywidth then
local _,fid = get_hlist_class_first(curr)
emsize = get_font_emsize(fid)
- local leftwidth,leftmargin = get_ruby_side_width(basewidth,rubywidth,curr.prev)
+ local leftwidth,leftmargin = get_ruby_side_width(basewidth,rubywidth,nodeprev(curr))
if leftwidth > 0 then
curr.width = curr.width + leftwidth
end
if leftmargin > 0 then
rubynode[attr].leftmargin = leftmargin
end
- local rightwidth,rightmargin = get_ruby_side_width(basewidth,rubywidth,curr.next)
+ local rightwidth,rightmargin = get_ruby_side_width(basewidth,rubywidth,nodenext(curr))
if rightwidth > 0 then
curr.width = curr.width + rightwidth
end
@@ -1079,13 +1088,14 @@ local function no_ruby_at_margin(head)
end
margin = rubynode[attr].rightmargin
if margin then
- if curr.next then
- if curr.next.id == gluenode then
+ local nn = nodenext(curr)
+ if nn then
+ if nn.id == gluenode then
insert_after(head,curr,get_kernnode(-margin))
head = zero_width_rule_with_dir(head,curr)
insert_after(head,curr,get_kernnode(margin))
- elseif curr.next.id == penaltynode and curr.next.penalty < 10000 then
- insert_after(head,curr.next,get_kernnode(-margin))
+ elseif nn.id == penaltynode and nn.penalty < 10000 then
+ insert_after(head,nn,get_kernnode(-margin))
head = zero_width_rule_with_dir(head,curr)
insert_after(head,curr,get_kernnode(margin))
end
@@ -1104,14 +1114,15 @@ local function inject_char_widow_penalty (head,curr,uni,cjattr)
local class = get_cjk_class(uni, cjattr)
if class and class < 9 then
local pv = cjattr and 500 or 5000
- if curr.prev and curr.prev.id == rulenode then
- curr = curr.prev
+ local np = nodeprev(curr)
+ if np and np.id == rulenode then
+ curr = np; np = nodeprev(curr)
end
- if curr.prev and curr.prev.id == gluenode then
- curr = curr.prev
+ if np and np.id == gluenode then
+ curr = np; np = nodeprev(curr)
end
- if curr.prev and curr.prev.id == penaltynode then
- curr = curr.prev
+ if np and np.id == penaltynode then
+ curr = np
if curr.penalty < pv then
curr.penalty = pv
end
@@ -1141,7 +1152,7 @@ local function discourage_char_widow (head,curr)
local cjattr = has_attribute(curr,cjtypesetattr)
curr = inject_char_widow_penalty(head,curr,uni,cjattr)
end
- curr = curr.prev
+ curr = nodeprev(curr)
end
end
@@ -1228,7 +1239,7 @@ end
local function get_hanja_hangul_table (table,file,init)
local i = 0
- local file = kpse.find_file(file)
+ local file = kpse_find_file(file)
if not file then return table end
file = io.open(file, "r")
if not file then return table end
@@ -1301,7 +1312,7 @@ local function get_josaprevs(curr,josaprev,ignoreparens,halt)
josaprev = get_josaprevs(nodeslide(curr.head),josaprev,ignoreparens,halt)
end
if #josaprev == 3 then break end
- curr = curr.prev
+ curr = nodeprev(curr)
end
return josaprev
end
@@ -1311,13 +1322,12 @@ local function korean_autojosa (head)
if has_attribute(curr,autojosaattr) and has_attribute(curr,finemathattr) then
local ignoreparens = has_attribute(curr,autojosaattr) > 1 and true or false
local josaprev = {}
- josaprev = get_josaprevs(curr.prev,josaprev,ignoreparens)
+ josaprev = get_josaprevs(nodeprev(curr),josaprev,ignoreparens)
local josacode = get_josacode(josaprev)
local thischar = get_unicode_char(curr)
if thischar == 0xC774 then
- if curr.next
- and curr.next.id == glyphnode
- and get_unicode_char(curr.next) == 0xB77C then
+ local nn = nodenext(curr)
+ if nn and nn.id == glyphnode and get_unicode_char(nn) == 0xB77C then
curr.char = josa_list[0xC774][josacode]
else
curr.char = josa_list[0xAC00][josacode]
@@ -1353,30 +1363,65 @@ local function hangulspaceskip (engfont, hfontid, spec)
return tex_round(hsp), tex_round(hst), tex_round(hsh)
end
+local type1fonts = {} -- due to too verbose log
+local function nanumtype1font(curr)
+ if curr.char > 0xFFFF then return end
+ local fnt_t = get_font_table(curr.font)
+ local family = (has_attribute(curr,finemathattr) or 0) > 1 and not is_hanja(curr.char) and "nanummj" or "nanumgt"
+ local series = fnt_t.shared and fnt_t.shared.rawdata.metadata.pfminfo.weight
+ if series then
+ series = series > 500 and "b" or "m"
+ else
+ series = stringfind(fnt_t.name,"^cmb") and "b" or "m"
+ end
+ local shape = fnt_t.parameters.slant > 0 and "o" or ""
+ local subfnt = stringformat("%s%s%s%02x",family,series,shape,curr.char/256)
+ local fsize = fnt_t.size or 655360
+ local fspec = stringformat("%s@%d",subfnt,fsize)
+ local newfnt = type1fonts[fspec]
+ local newchr = curr.char % 256
+ local function ital_corr (curr,chr_t)
+ if shape ~= "o" then return end
+ local nxt = nodenext(curr)
+ if nxt and nxt.id == kernnode and nxt.subtype == 1 and nxt.kern == 0 then
+ nxt.kern = chr_t.italic or 0
+ end
+ end
+ if newfnt then
+ local fntchr = get_font_char(newfnt,newchr)
+ if fntchr then
+ curr.font, curr.char = newfnt, newchr
+ ital_corr(curr,fntchr)
+ end
+ else
+ local ft, id = fonts.constructors.readanddefine(subfnt,fsize)
+ local fntchr = ft and ft.characters[newchr]
+ if id and fntchr then
+ type1fonts[fspec], curr.font, curr.char = id, id, newchr
+ ital_corr(curr,fntchr)
+ end
+ end
+end
+
local function font_substitute(head)
- local noinmath = true
- for curr in traverse(head) do
- if curr.id == mathnode then
- if curr.subtype == 0 then
- noinmath = false
- else
- noinmath = true
- end
- elseif noinmath and curr.id == glyphnode then
+ local curr = head
+ while curr do
+ if curr.id == mathnode and curr.subtype == 0 then
+ curr = end_of_math(curr)
+ elseif curr.id == glyphnode then
local eng = get_font_table(curr.font)
- local engfontchar = nil
+ local myfontchar = nil
if eng and eng.encodingbytes and eng.encodingbytes == 2 -- exclude type1
and hangulpunctuations[curr.char]
and has_attribute(curr, hangulpunctsattr)
- and has_attribute(curr, finemathattr) == 1
+ and (has_attribute(curr, finemathattr) or 0) > 0 -- not ttfamily
and not get_font_char(curr.font, 0xAC00) then -- exclude hangul font
else
- engfontchar = get_font_char(curr.font, curr.char)
+ myfontchar = get_font_char(curr.font, curr.char)
end
- if curr.char and not engfontchar then
- local korid = false
- local hangul = has_attribute(curr, hangfntattr)
- local hanja = has_attribute(curr, hanjfntattr)
+ if curr.char and not myfontchar then
+ local hangul = has_attribute(curr, hangulfntattr)
+ local hanja = has_attribute(curr, hanjafntattr)
local fallback = has_attribute(curr,fallbackfntattr)
local ftable = {hangul, hanja, fallback}
if luatexko.hanjafontforhanja then
@@ -1384,17 +1429,15 @@ local function font_substitute(head)
uni = uni and get_cjk_class(uni)
if uni and uni < 7 then ftable = {hanja, hangul, fallback} end
end
- for i=1,#ftable do
+ for i = 1,3 do
local fid = ftable[i]
- if fid then
- local c = get_font_char(fid, curr.char)
- if c then
- korid = true
- curr.font = fid
+ myfontchar = get_font_char(fid, curr.char)
+ if myfontchar then
+ curr.font = fid
+ local nxt = nodenext(curr)
+ if eng and nxt then
-- adjust next glue by hangul font space
- local nxt = curr.next
- if eng
- and nxt and nxt.id == gluenode
+ if nxt.id == gluenode
and nxt.subtype and nxt.subtype == 0
and nxt.spec and nxt.spec.writable
and get_font_char(fid,32) then
@@ -1404,25 +1447,32 @@ local function font_substitute(head)
hg.width, hg.stretch, hg.shrink = sp, st, sh
nxt.spec = hg
end
+ -- adjust next italic correction kern
+ elseif nxt.id == kernnode
+ and nxt.subtype == 1 and nxt.kern == 0 then
+ local ksl = get_font_table(fid).parameters.slant
+ if ksl and ksl > 0 then
+ nxt.kern = myfontchar.italic or 0
+ end
end
- --- charraise option charraise
- local charraise = get_font_feature(fid, "charraise")
- if charraise then
- charraise = tex_sp(charraise)
- curr.yoffset = curr.yoffset and (curr.yoffset + charraise) or charraise
- end
- ---
- break
end
+ --- charraise option charraise
+ local charraise = get_font_feature(fid, "charraise")
+ if charraise then
+ charraise = tex_sp(charraise)
+ curr.yoffset = charraise + (curr.yoffset or 0)
+ end
+ ---
+ break
end
end
- if not korid and not is_unicode_vs(curr.char) then
- warn("!Missing character: %s U+%04X", utf8char(curr.char),curr.char)
+ if not myfontchar then
+ nanumtype1font(curr)
end
end
end
+ curr = nodenext(curr)
end
- return head
end
-----------------------------
@@ -1440,19 +1490,25 @@ end
-----------------------------
local function reorderTM (head)
for curr in traverse_id(glyphnode, head) do
- if curr.width > 0 then -- old hangul vertical typesetting is broken?
- local uni = get_unicode_char(curr)
- if uni and (uni == 0x302E or uni == 0x302F) then
- local p = curr.prev
+ local uni = get_unicode_char(curr)
+ if uni and (uni == 0x302E or uni == 0x302F) then
+ local unichar = get_font_char(curr.font, uni)
+ if unichar.width > 0 then
+ local p = nodeprev(curr)
while p do
- if p.id ~= glyphnode then break end
- local pc = get_cjk_class(get_unicode_char(p))
- if pc == 7 or pc == 8 then
- head = insert_before(head,p,copy_node(curr))
- head = remove_node(head,curr)
+ if p.id == glyphnode then
+ local pc = get_cjk_class(get_unicode_char(p))
+ if pc == 7 or pc == 8 then
+ head = insert_before(head,p,copy_node(curr))
+ head = remove_node(head,curr)
+ break
+ end
+ elseif unichar.commands and p.id == kernnode then
+ -- kerns in vertical typesetting mode
+ else
break
end
- p = p.prev
+ p = nodeprev(p)
end
end
end
@@ -1467,7 +1523,7 @@ local function hanja_vs_support (head)
for curr in traverse_id(glyphnode, head) do
local cc = curr.char
if is_unicode_vs(cc) then
- local prev = curr.prev
+ local prev = nodeprev(curr)
if prev and prev.id == glyphnode then
local f = get_font_table(prev.font)
local ivs = f and f.resources and f.resources.variants
@@ -1496,9 +1552,9 @@ add_to_callback('hpack_filter', function(head)
end, 'luatexko.hpack_filter_first',1)
add_to_callback('hpack_filter', function(head)
- get_ruby_side_kern(head)
+ if texcount["luakorubyattrcnt"]>0 then get_ruby_side_kern(head) end
cjk_spacing_linebreak(head)
- spread_ruby_base_box(head)
+ if texcount["luakorubyattrcnt"]>0 then spread_ruby_base_box(head) end
head = compress_fullwidth_punctuations(head)
-- head = no_ruby_at_margin(head)
head = reorderTM(head)
@@ -1515,12 +1571,12 @@ add_to_callback('pre_linebreak_filter', function(head)
end, 'luatexko.pre_linebreak_filter_first',1)
add_to_callback('pre_linebreak_filter', function(head)
- get_ruby_side_kern(head)
+ if texcount["luakorubyattrcnt"]>0 then get_ruby_side_kern(head) end
cjk_spacing_linebreak(head)
- spread_ruby_base_box(head)
+ if texcount["luakorubyattrcnt"]>0 then spread_ruby_base_box(head) end
head = compress_fullwidth_punctuations(head)
discourage_char_widow(head, nodeslide(head))
- head = no_ruby_at_margin(head)
+ if texcount["luakorubyattrcnt"]>0 then head = no_ruby_at_margin(head) end
head = reorderTM(head)
return head
end, 'luatexko.pre_linebreak_filter')
@@ -1540,7 +1596,7 @@ local function after_linebreak_dotemph (head)
if cc and (cc == 0 or cc == 7 or cc == 8) then
local basewd = curr.width or 0
if cc == 8 then -- check next char for old hangul jung/jongseong
- local nn = curr.next
+ local nn = nodenext(curr)
while nn do
if nn.id ~= glyphnode then break end
local uni = get_unicode_char(nn)
@@ -1550,7 +1606,7 @@ local function after_linebreak_dotemph (head)
else
break
end
- nn = nn.next
+ nn = nodenext(nn)
end
end
local d = copy_node(dotemphnode[attr])
@@ -1623,7 +1679,7 @@ end
local function after_linebreak_underline(head,glueorder,glueset,gluesign,ulinenum)
local ulstart = ulinenum and head or false
- if ulstart and ulstart.id == gluenode then ulstart = ulstart.next end
+ if ulstart and ulstart.id == gluenode then ulstart = nodenext(ulstart) end
for curr in traverse(head) do
if curr.id == hlistnode then
curr.head,ulinenum = after_linebreak_underline(curr.head,curr.glue_order,curr.glue_set,curr.glue_sign,ulinenum)
@@ -1652,48 +1708,61 @@ end
-- add to callback : post-linebreak
-----------------------------------
add_to_callback('vpack_filter', function(head)
- head = after_linebreak_dotemph(head)
- after_linebreak_ruby(head)
- head = after_linebreak_underline(head)
+ if texcount["luakodotemphcnt"]>0 then head = after_linebreak_dotemph(head) end
+ if texcount["luakorubyattrcnt"]>0 then after_linebreak_ruby(head) end
+ if texcount["luakoulineboxcnt"]>0 then head = after_linebreak_underline(head) end
return head
end, 'luatexko.vpack_filter')
add_to_callback("post_linebreak_filter", function(head)
- head = after_linebreak_dotemph(head)
- after_linebreak_ruby(head)
- head = after_linebreak_underline(head)
+ if texcount["luakodotemphcnt"]>0 then head = after_linebreak_dotemph(head) end
+ if texcount["luakorubyattrcnt"]>0 then after_linebreak_ruby(head) end
+ if texcount["luakoulineboxcnt"]>0 then head = after_linebreak_underline(head) end
return head
end, 'luatexko.post_linebreak_filter')
------------------------------------
--- vertical typesetting: EXPERIMENTAL -- don't use this
+-- vertical typesetting: EXPERIMENTAL
------------------------------------
----[[no vwidth in luaotfload v2
-local tsbtable = {}
-
-local function read_tsb_table(filename)-- for ttx-generated vmtx table
- if tsbtable[filename] then
- return tsbtable[filename]
+local tsbtable, mytime, currtime, cachedir, lfsattributes, lfstouch
+
+local function get_vwidth_tsb_table (filename,fontname)
+ if tsbtable[fontname] then return tsbtable[fontname] end
+ local cachefile = stringformat("%s/luatexko_vertical_metrics_%s.lua",
+ cachedir,stringgsub(fontname,"%W","_"))
+ local cattr = lfs.isfile(cachefile) and lfsattributes(cachefile)
+ local fonttime = lfsattributes(filename,"modification")
+ if cattr and cattr.access > mytime and cattr.modification == fonttime then
+ tsbtable[fontname] = dofile(cachefile)
+ return tsbtable[fontname]
end
- local filepath = kpse.find_file(filename)
- if not filepath then return end
- local file = io.open(filepath, "r")
- if not file then return end
- local tsbtb = {}
- local patt = 'name="(.-)" height="(.-)" tsb="(.-)"'
- while true do
- local l = file:read("*line")
- if not l then break end
- for name, height, tsb in stringgmatch(l,patt) do
- tsbtb[name] = {}
- tsbtb[name].height = height
- tsbtb[name].tsb = tsb
+ local metrics = nil
+ local font = fontloader.open(filename,fontname)
+ if font then
+ metrics = fontloader.to_table(font)
+ fontloader.close(font)
+ local glyph_t = {}
+ if metrics.subfonts then
+ for _,v in ipairs(metrics.subfonts) do
+ for ii,vv in pairs(v.glyphs) do
+ glyph_t[ii] = { ht = vv.vwidth, tsb = vv.tsidebearing }
+ end
+ end
+ else
+ for i,v in ipairs(metrics.glyphs) do
+ glyph_t[i] = { ht = v.vwidth, tsb = v.tsidebearing }
+ end
end
+ if lfstouch then
+ table.tofile(cachefile,glyph_t,"return")
+ if not lfstouch(cachefile,currtime,fonttime) then
+ warn("Writing cache file '%s' failed!",cachefile)
+ end
+ end
+ tsbtable[fontname] = glyph_t
+ return glyph_t
end
- file:close()
- tsbtable[filename] = tsbtb
- return tsbtb
end
local function cjk_vertical_font (vf)
@@ -1702,25 +1771,13 @@ local function cjk_vertical_font (vf)
if not vf.shared.features["vertical"] then return end
if vf.type == "virtual" then return end
- ---[[ for read-ttx
- local filename = vf.filename
- filename = stringgsub(filename,".*/","")
- filename = stringgsub(filename,"[tToO][tT][fF]$","ttx")
- local tsbtable = read_tsb_table(filename)
- if not tsbtable then
- warn("Cannot read %s. Aborting vertical typesetting.",filename)
- return
- end
- --]]
+ -- load font (again)
+ local tsbtable = get_vwidth_tsb_table(vf.filename,vf.fontname)
+ if not tsbtable then return end
local tmp = table.copy(vf) -- fastcopy takes time too long.
local id = fontdefine(tmp)
- local hash = vf.properties and vf.properties.hash and vf.properties.hash..' @ vertical'
- hash = hash or (vf.name and vf.size and vf.name..' @ '..vf.size..' @ vertical')
-
- vf.properties = vf.properties or {}
- vf.properties.hash = hash
vf.type = 'virtual'
vf.fonts = {{ id = id }}
local quad = vf.parameters and vf.parameters.quad or 655360
@@ -1728,31 +1785,21 @@ local function cjk_vertical_font (vf)
local ascender = vf.parameters and vf.parameters.ascender or quad*0.8
local factor = vf.parameters and vf.parameters.factor or 655.36
local xheight = vf.parameters and vf.parameters.x_height or quad/2
- local halfxht = xheight/2
+ local goffset = xheight/2 - quad/2
for i,v in pairs(vf.characters) do
local dsc = descriptions[i]
- local gname = dsc.name
- -- local vw = dsc and dsc.vwidth
- ---[[ for read-ttx
- local vw = tsbtable and tsbtable[gname] and tsbtable[gname].height
- local tsb = tsbtable and tsbtable[gname] and tsbtable[gname].tsb
- if not vw and dsc.index then
- local cid = stringformat("cid%05d", dsc.index)
- vw = tsbtable and tsbtable[cid] and tsbtable[cid].height
- tsb = tsbtable and tsbtable[cid] and tsbtable[cid].tsb
- end
- tsb = tsb and factor and tsb*factor
- --]]
+ local gl = v.index
+ -- from loaded font
+ local vw = tsbtable and tsbtable[gl] and tsbtable[gl].ht
vw = vw and vw * factor or quad
- local hw = v.width or quad
- local offset = hw/2 - quad/2 + halfxht
- local vh = (hw > 0) and hw/2 or nil
+ local tsb = tsbtable and tsbtable[gl] and tsbtable[gl].tsb
local bb4 = dsc and dsc.boundingbox and dsc.boundingbox[4]
- bb4 = bb4 and bb4*factor
- local asc = bb4 and tsb and (bb4 + tsb)
- asc = asc or ascender
+ local asc = bb4 and tsb and (bb4+tsb)*factor or ascender
+ local hw = v.width or quad
+ local offset = hw/2 + goffset
+ local vh = hw > 0 and hw/2 or nil
v.commands = {
- {'right', asc}, -- bbox4 + top_side_bearing! But, tsb not available!
+ {'right', asc}, -- bbox4 + top_side_bearing
{'down', offset},
{'special', 'pdf: q 0 1 -1 0 0 0 cm'},
{'push'},
@@ -1800,6 +1847,15 @@ local function activate_vertical_virtual (tfmdata,value)
local loaded = luatexbase.priority_in_callback("luaotfload.patch_font",
"luatexko.vertical_virtual_font")
if value and not loaded then
+ require "fontloader"
+ require "lfs"
+ lfstouch = lfs.touch
+ lfsattributes = lfs.attributes
+ tsbtable = {}
+ currtime = os.time()
+ mytime = kpse_find_file("luatexko.lua")
+ mytime = mytime and lfsattributes(mytime,"modification")
+ cachedir = caches.getwritablepath("..","luatexko")
add_to_callback("luaotfload.patch_font",
cjk_vertical_font,
"luatexko.vertical_virtual_font")
@@ -1814,7 +1870,6 @@ otffeatures.register {
node = activate_vertical_virtual,
}
}
---no vwidth in luaotfload v2]]
------------------------------------
-- italic correction for fake-slant font
@@ -1834,7 +1889,62 @@ local function fakeslant_itlc (tfmdata)
end
end
+------------------------------------
+-- tounicode for old hangul
+------------------------------------
+local function tounicode_oldhangul (tfmdata)
+ local script = tfmdata.properties and tfmdata.properties.script
+ if script ~= "hang" then return end
+ local desc = tfmdata.shared and tfmdata.shared.rawdata and tfmdata.shared.rawdata.descriptions
+ local chrs = tfmdata.characters
+ if not desc or not chrs then return end
+ if not chrs[0x1100] then return end
+ local last = 0
+ for _,v in ipairs({{0x1100,0x11FF},{0xA960,0xA97C},{0xD7B0,0xD7FB}}) do
+ for i = v[1],v[2] do
+ local ds = desc[i] and desc[i].slookups
+ if ds then
+ for _,s in pairs(ds) do
+ if type(s) == "number" and s >= 0xF0000 and chrs[s] and not chrs[s].tounicode then
+ chrs[s].tounicode = stringformat("%04X",i)
+ last = s > last and s or last
+ end
+ end
+ end
+ end
+ end
+ if stringfind(tfmdata.fontname,"^HCR.+LVT") then
+ local touni = "1112119E"
+ for i = last+1, last+2 do
+ local dsc,chr = desc[i],chrs[i]
+ if dsc and chr and dsc.class == "ligature" and not chr.tounicode then
+ chr.tounicode = touni
+ end
+ touni = touni.."11AB"
+ end
+ end
+end
+
add_to_callback("luaotfload.patch_font",
- fakeslant_itlc,
- "luatexko.fakeslant_itlc")
+ function(tfmdata)
+ fakeslant_itlc(tfmdata)
+ tounicode_oldhangul(tfmdata)
+ end, "luatexko.font_patches")
+
+------------------------------------
+-- Actual Text
+------------------------------------
+local function actualtext (str)
+ local t = {}
+ for uni in string.utfvalues(str) do
+ if uni < 0x10000 then
+ t[#t+1] = stringformat("%04X",uni)
+ else -- surrogate
+ uni = uni - 0x10000
+ t[#t+1] = stringformat("%04X%04X", uni/0x400+0xD800, uni%0x400+0xDC00)
+ end
+ end
+ tex.sprint(stringformat("<FEFF%s>", table.concat(t)))
+end
+luatexko.actualtext = actualtext
diff --git a/Master/texmf-dist/tex/luatex/luatexko/luatexko.sty b/Master/texmf-dist/tex/luatex/luatexko/luatexko.sty
index 5d6d6d69fa8..a34b53bae9a 100644
--- a/Master/texmf-dist/tex/luatex/luatexko/luatexko.sty
+++ b/Master/texmf-dist/tex/luatex/luatexko/luatexko.sty
@@ -1,6 +1,6 @@
% luatexko.sty
%
-% Copyright (c) 2013 Dohyun Kim <nomos at ktug org>
+% Copyright (c) 2013-2014 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
@@ -22,162 +22,282 @@
\expandafter\endinput
\fi
-\ProvidesPackage{luatexko}[2014/01/15 v1.4 Typesetting Korean with LuaLaTeX]
-\RequirePackage{fontspec}
-\RequirePackage{luatexko-core}
-
-%% fontspec Korean options
-\ExplSyntaxOn
-
-\DeclareDocumentCommand \newhangulfontfeature {mmmm}
- {
- \fontspec_define_font_feature:n {#1}
- \keys_define:nn {fontspec}
- {
- #1 .default:n = {#3} ,
- #1 / unknown .code:n = {
- \fontspec_update_fontid:n {#2:##1}
- \fontspec_update_featstr:n {#2=##1}#4
- }
- }
- }
-
-\fontspec_define_font_feature:n {YetHangul}
-\keys_define:nn {fontspec}
- {
- YetHangul .default:n = {On} ,
- YetHangul / On .code:n = {
- \fontspec_update_fontid:n {yethangul:on}
- \fontspec_update_featstr:n {script=hang;+ccmp;+ljmo;+vjmo;+tjmo}
- } ,
- YetHangul / Off .code:n = {
- \fontspec_update_fontid:n {yethangul:off}
- \fontspec_update_featstr:n {-ljmo;-vjmo;-tjmo}
- }
- }
-
-\ExplSyntaxOff
-
-\newhangulfontfeature{InterHangul}{interhangul}{0}{}
-\newhangulfontfeature{InterLatinCJK}{interlatincjk}{0}{}
-\newhangulfontfeature{PunctRaise}{punctraise}{0}{}
-\newhangulfontfeature{CharRaise}{charraise}{0}{}
-\newhangulfontfeature{Protrusion}{protrusion}{default}{\aftergroup\pdfprotrudechars\aftergroup\tw@}
-\newhangulfontfeature{Expansion}{expansion}{default}{\aftergroup\pdfadjustspacing\aftergroup\tw@}
-
-%% macros for Korean fonts
-\protected\def\setmainhangulfont{\newfontfamily\serifhangul@font}
-\protected\def\setmainhanjafont {\newfontfamily\serifhanja@font}
-\protected\def\setmainfallbackfont{\newfontfamily\seriffallback@font}
-\protected\def\setsanshangulfont{\newfontfamily\sanshangul@font}
-\protected\def\setsanshanjafont {\newfontfamily\sanshanja@font}
-\protected\def\setsansfallbackfont{\newfontfamily\sansfallback@font}
-\protected\def\setmonohangulfont{\newfontfamily\monohangul@font}
-\protected\def\setmonohanjafont {\newfontfamily\monohanja@font}
-\protected\def\setmonofallbackfont{\newfontfamily\monofallback@font}
-
-\protected\def\newhangulfontfamily#1{%
- \protected\def#1{\expandafter\let\expandafter\hangul@font
- \csname luatexko@\string#1\endcsname
- \luatexko@hangul@selectfont}\expandafter\newfontfamily
- \csname luatexko@\string#1\endcsname}
-\protected\def\newhanjafontfamily#1{%
- \protected\def#1{\expandafter\let\expandafter\hanja@font
- \csname luatexko@\string#1\endcsname
- \luatexko@hanja@selectfont}\expandafter\newfontfamily
- \csname luatexko@\string#1\endcsname}
-\protected\def\newfallbackfontfamily#1{%
- \protected\def#1{\expandafter\let\expandafter\fallback@font
- \csname luatexko@\string#1\endcsname
- \luatexko@fallback@selectfont}\expandafter\newfontfamily
- \csname luatexko@\string#1\endcsname}
+\ProvidesPackage{luatexko}[2014/05/11 v1.5 Typesetting Korean with LuaLaTeX]
-\protected\def\newhangulfontface#1{%
- \protected\def#1{\expandafter\let\expandafter\hangul@font
- \csname luatexko@\string#1\endcsname
- \luatexko@hangul@selectfont}\expandafter\newfontface
- \csname luatexko@\string#1\endcsname}
-\protected\def\newhanjafontface#1{%
- \protected\def#1{\expandafter\let\expandafter\hanja@font
- \csname luatexko@\string#1\endcsname
- \luatexko@hanja@selectfont}\expandafter\newfontface
- \csname luatexko@\string#1\endcsname}
-\protected\def\newfallbackfontface#1{%
- \protected\def#1{\expandafter\let\expandafter\fallback@font
- \csname luatexko@\string#1\endcsname
- \luatexko@fallback@selectfont}\expandafter\newfontface
- \csname luatexko@\string#1\endcsname}
+%% package options
+\newif\if@hangul
+\newif\if@hanja
+\newif\if@unfonts
+\newif\if@luatexko@loadfontspec\@luatexko@loadfontspectrue
+\DeclareOption{hangul}{\@hangultrue}
+\DeclareOption{hanja}{\@hangultrue\@hanjatrue}
+\DeclareOption{unfonts}{\@unfontstrue}
+\DeclareOption{nofontspec}{\@luatexko@loadfontspecfalse}
+\ProcessOptions\relax
-\protected\def\hangulfontspec#1#{%
- \def\luatexko@fontspec@temp{#1}\hangulfontspec@}
-\def\hangulfontspec@#1{%
- \expandafter\newfontfamily\expandafter\hangul@font\luatexko@fontspec@temp{#1}%
- \luatexko@hangul@selectfont\ignorespaces}
-\let\adhochangulfont\hangulfontspec
-\protected\def\hanjafontspec#1#{%
- \def\luatexko@fontspec@temp{#1}\hanjafontspec@}
-\def\hanjafontspec@#1{%
- \expandafter\newfontfamily\expandafter\hanja@font\luatexko@fontspec@temp{#1}%
- \luatexko@hanja@selectfont\ignorespaces}
-\let\adhochanjafont\hanjafontspec
-\protected\def\fallbackfontspec#1#{%
- \def\luatexko@fontspec@temp{#1}\fallbackfontspec@}
-\def\fallbackfontspec@#1{%
- \expandafter\newfontfamily\expandafter\fallback@font\luatexko@fontspec@temp{#1}%
- \luatexko@fallback@selectfont\ignorespaces}
-\let\adhocfallbackfont\fallbackfontspec
+\if@luatexko@loadfontspec
+ %% euenc redefines \f@size by \DeclareErrorFont. sigh
+ \let\luatexko@f@size\f@size
+ \RequirePackage{fontspec}
+ \let\f@size\luatexko@f@size
+\fi
-% add{hangul/hanja}fontfeature
-\protected\def\addhangulfontfeature#1{%
- \begingroup
- \check@hangul@family
- \ifdefined\hangul@font\hangul@font\fi\addfontfeature{#1}%
- \global\let\luatexko@fontspec@temp\f@family
- \endgroup
- \def\hangul@font{\fontfamily\luatexko@fontspec@temp\selectfont}%
- \luatexko@hangul@selectfont \ignorespaces}
-\let\addhangulfontfeatures\addhangulfontfeature
-\protected\def\addhanjafontfeature#1{%
- \begingroup
- \check@hanja@family
- \ifdefined\hanja@font\hanja@font\fi\addfontfeature{#1}%
- \global\let\luatexko@fontspec@temp\f@family
- \endgroup
- \def\hanja@font{\fontfamily\luatexko@fontspec@temp\selectfont}%
- \luatexko@hanja@selectfont \ignorespaces}
-\let\addhanjafontfeatures\addhanjafontfeature
-\protected\def\addfallbackfontfeature#1{%
- \begingroup
- \check@fallback@family
- \ifdefined\fallback@font\fallback@font\fi\addfontfeature{#1}%
- \global\let\luatexko@fontspec@temp\f@family
- \endgroup
- \def\fallback@font{\fontfamily\luatexko@fontspec@temp\selectfont}%
- \luatexko@fallback@selectfont \ignorespaces}
-\let\addfallbackfontfeatures\addfallbackfontfeature
+\RequirePackage{luatexko-core}
-% check hangul/hanja family
-\def\check@hangul@family{%
- \unless\ifdefined\hangul@font
- \ifx\f@family\sfdefault \let\hangul@font\sanshangul@font
- \else\ifx\f@family\ttdefault \let\hangul@font\monohangul@font
- \else \let\hangul@font\serifhangul@font
- \fi\fi\fi
-}
-\def\check@hanja@family{%
- \unless\ifdefined\hanja@font
- \ifx\f@family\sfdefault \let\hanja@font\sanshanja@font
- \else\ifx\f@family\ttdefault \let\hanja@font\monohanja@font
- \else \let\hanja@font\serifhanja@font
- \fi\fi\fi
-}
-\def\check@fallback@family{%
- \unless\ifdefined\fallback@font
- \ifx\f@family\sfdefault \let\fallback@font\sansfallback@font
- \else\ifx\f@family\ttdefault \let\fallback@font\monofallback@font
- \else \let\fallback@font\seriffallback@font
- \fi\fi\fi
-}
+\if@luatexko@loadfontspec
+ %% fontspec Korean options
+ \newfontfeature{YetHangul}{script=hang}
+ \newfontfeature{InterHangul}{interhangul=#1}
+ \newfontfeature{InterLatinCJK}{interlatincjk=#1}
+ \newfontfeature{PunctRaise}{punctraise=#1}
+ \newfontfeature{CharRaise}{charraise=#1}
+ \ExplSyntaxOn
+ \DeclareDocumentCommand \newhangulfontfeature {mmmm}
+ {
+ \keys_define:nn { fontspec }
+ {
+ #1 .code:n =
+ {
+ \fontspec_update_featstr:n {#2=##1}
+ #4
+ },
+ #1 .default:n = {#3}
+ }
+ }
+ \newhangulfontfeature{Protrusion}{protrusion}{default}
+ {\aftergroup\pdfprotrudechars\aftergroup\tw@}
+ \newhangulfontfeature{Expansion}{expansion}{default}
+ {\aftergroup\pdfadjustspacing\aftergroup\tw@}
+ %% macros for Korean fonts
+ \DeclareDocumentCommand \setmainhangulfont { O{} m }
+ {
+ \newfontfamily \serifhangul@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \rmdefault
+ {
+ \cs_set_eq:NN \hangul@font \serifhangul@font
+ \luatexko@hangul@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \setmainhanjafont { O{} m }
+ {
+ \newfontfamily \serifhanja@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \rmdefault
+ {
+ \cs_set_eq:NN \hanja@font \serifhanja@font
+ \luatexko@hanja@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \setmainfallbackfont { O{} m }
+ {
+ \newfontfamily \seriffallback@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \rmdefault
+ {
+ \cs_set_eq:NN \fallback@font \seriffallback@font
+ \luatexko@fallback@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \setsanshangulfont { O{} m }
+ {
+ \newfontfamily \sanshangul@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \sfdefault
+ {
+ \cs_set_eq:NN \hangul@font \sanshangul@font
+ \luatexko@hangul@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \setsanshanjafont { O{} m }
+ {
+ \newfontfamily \sanshanja@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \sfdefault
+ {
+ \cs_set_eq:NN \hanja@font \sanshanja@font
+ \luatexko@hanja@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \setsansfallbackfont { O{} m }
+ {
+ \newfontfamily \sansfallback@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \sfdefault
+ {
+ \cs_set_eq:NN \fallback@font \sansfallback@font
+ \luatexko@fallback@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \setmonohangulfont { O{} m }
+ {
+ \newfontfamily \monohangul@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \ttdefault
+ {
+ \cs_set_eq:NN \hangul@font \monohangul@font
+ \luatexko@hangul@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \setmonohanjafont { O{} m }
+ {
+ \newfontfamily \monohanja@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \ttdefault
+ {
+ \cs_set_eq:NN \hanja@font \monohanja@font
+ \luatexko@hanja@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \setmonofallbackfont { O{} m }
+ {
+ \newfontfamily \monofallback@font [#1] {#2}
+ \str_if_eq_x:nnT \familydefault \ttdefault
+ {
+ \cs_set_eq:NN \fallback@font \monofallback@font
+ \luatexko@fallback@selectfont
+ }
+ \ignorespaces
+ }
+ \DeclareDocumentCommand \newhangulfontfamily { m O{} m }
+ {
+ \exp_after:wN \newfontfamily
+ \cs:w luatexkofont@ \token_to_str:N #1 \cs_end: [#2] {#3}
+ \DeclareRobustCommand #1
+ {
+ \cs_set_eq:Nc \hangul@font { luatexkofont@ \token_to_str:N #1 }
+ \luatexko@hangul@selectfont
+ }
+ }
+ \DeclareDocumentCommand \newhanjafontfamily { m O{} m }
+ {
+ \exp_after:wN \newfontfamily
+ \cs:w luatexkofont@ \token_to_str:N #1 \cs_end: [#2] {#3}
+ \DeclareRobustCommand #1
+ {
+ \cs_set_eq:Nc \hanja@font { luatexkofont@ \token_to_str:N #1 }
+ \luatexko@hanja@selectfont
+ }
+ }
+ \DeclareDocumentCommand \newfallbackfontfamily { m O{} m }
+ {
+ \exp_after:wN \newfontfamily
+ \cs:w luatexkofont@ \token_to_str:N #1 \cs_end: [#2] {#3}
+ \DeclareRobustCommand #1
+ {
+ \cs_set_eq:Nc \fallback@font { luatexkofont@ \token_to_str:N #1 }
+ \luatexko@fallback@selectfont
+ }
+ }
+ \DeclareDocumentCommand \newhangulfontface { m O{} m }
+ {
+ \exp_after:wN \newfontface
+ \cs:w luatexkofont@ \token_to_str:N #1 \cs_end: [#2] {#3}
+ \DeclareRobustCommand #1
+ {
+ \cs_set_eq:Nc \hangul@font { luatexkofont@ \token_to_str:N #1 }
+ \luatexko@hangul@selectfont
+ }
+ }
+ \DeclareDocumentCommand \newhanjafontface { m O{} m }
+ {
+ \exp_after:wN \newfontface
+ \cs:w luatexkofont@ \token_to_str:N #1 \cs_end: [#2] {#3}
+ \DeclareRobustCommand #1
+ {
+ \cs_set_eq:Nc \hanja@font { luatexkofont@ \token_to_str:N #1 }
+ \luatexko@hanja@selectfont
+ }
+ }
+ \DeclareDocumentCommand \newfallbackfontface { m O{} m }
+ {
+ \exp_after:wN \newfontface
+ \cs:w luatexkofont@ \token_to_str:N #1 \cs_end: [#2] {#3}
+ \DeclareRobustCommand #1
+ {
+ \cs_set_eq:Nc \fallback@font { luatexkofont@ \token_to_str:N #1 }
+ \luatexko@fallback@selectfont
+ }
+ }
+ \DeclareDocumentCommand \hangulfontspec { O{} m }
+ {
+ \newfontfamily \hangul@font [#1] {#2}
+ \luatexko@hangul@selectfont
+ \ignorespaces
+ }
+ \cs_set_eq:NN \adhochangulfont \hangulfontspec
+ \DeclareDocumentCommand \hanjafontspec { O{} m }
+ {
+ \newfontfamily \hanja@font [#1] {#2}
+ \luatexko@hanja@selectfont
+ \ignorespaces
+ }
+ \cs_set_eq:NN \adhochanjafont \hanjafontspec
+ \DeclareDocumentCommand \fallbackfontspec { O{} m }
+ {
+ \newfontfamily \fallback@font [#1] {#2}
+ \luatexko@fallback@selectfont
+ \ignorespaces
+ }
+ \cs_set_eq:NN \adhocfallbackfont \fallbackfontspec
+ \DeclareDocumentCommand \addhangulfontfeature { m }
+ {
+ \group_begin:
+ \cs_if_exist:NT \hangul@font { \hangul@font }
+ \addfontfeature {#1}
+ \use:x
+ {
+ \group_end:
+ \exp_not:N \tl_set:Nn \exp_not:N \hangul@font
+ {
+ \exp_not:N \fontfamily { \f@family } \exp_not:N \selectfont
+ }
+ }
+ \luatexko@hangul@selectfont
+ \ignorespaces
+ }
+ \cs_set_eq:NN \addhangulfontfeatures \addhangulfontfeature
+ \DeclareDocumentCommand \addhanjafontfeature { m }
+ {
+ \group_begin:
+ \cs_if_exist:NT \hanja@font { \hanja@font }
+ \addfontfeature {#1}
+ \use:x
+ {
+ \group_end:
+ \exp_not:N \tl_set:Nn \exp_not:N \hanja@font
+ {
+ \exp_not:N \fontfamily { \f@family } \exp_not:N \selectfont
+ }
+ }
+ \luatexko@hanja@selectfont
+ \ignorespaces
+ }
+ \cs_set_eq:NN \addhanjafontfeatures \addhanjafontfeature
+ \DeclareDocumentCommand \addfallbackfontfeature { m }
+ {
+ \group_begin:
+ \cs_if_exist:NT \fallback@font { \fallback@font }
+ \addfontfeature {#1}
+ \use:x
+ {
+ \group_end:
+ \exp_not:N \tl_set:Nn \exp_not:N \fallback@font
+ {
+ \exp_not:N \fontfamily { \f@family } \exp_not:N \selectfont
+ }
+ }
+ \luatexko@fallback@selectfont
+ \ignorespaces
+ }
+ \cs_set_eq:NN \addfallbackfontfeatures \addfallbackfontfeature
+ % hangul math font command
+ \DeclareDocumentCommand \setmathhangulfont { O{} m }
+ {
+ \fontspec_set_family:Nnn \luatexko@math@hangul@family {#1} {#2}
+ }
+ \ExplSyntaxOff
+\fi
\RequirePackage{everysel}
\EverySelectfont{%
@@ -186,33 +306,55 @@
\luatexko@fallback@selectfont
}
-% don't forget to redefine \normalfont
-\protected\edef\normalfont{\unexpanded{%
- \let\hangul@font\luatexko@undefined
- \let\hanja@font\luatexko@undefined
- \let\fallback@font\luatexko@undefined
- }%
- \unexpanded\expandafter{\normalfont}}
-\let\reset@font\normalfont
-
-% normal : finemathattr = 1
+% serif : finemathattr = 2
+% sans : finemathattr = 1
% tt : finemathattr = 0
-% verbatim : finemathattr = off
-\protected\edef\ttfamily{\unexpanded\expandafter{\ttfamily
- \finemathattr\z@}}
+% verbatim : finemathattr = nil
+\def\luatexko@serif@fonts{%
+ \let\hangul@font\serifhangul@font
+ \let\hanja@font\serifhanja@font
+ \let\fallback@font\seriffallback@font
+ \finemathattr\tw@
+}
+\def\luatexko@sans@fonts{%
+ \let\hangul@font\sanshangul@font
+ \let\hanja@font\sanshanja@font
+ \let\fallback@font\sansfallback@font
+ \finemathattr\@ne
+}
+\def\luatexko@mono@fonts{%
+ \let\hangul@font\monohangul@font
+ \let\hanja@font\monohanja@font
+ \let\fallback@font\monofallback@font
+ \finemathattr\z@
+}
+
+\protected\edef\rmfamily{%
+ \unexpanded{\luatexko@serif@fonts}\unexpanded\expandafter{\rmfamily}}
+\protected\edef\sffamily{%
+ \unexpanded{\luatexko@sans@fonts}\unexpanded\expandafter{\sffamily}}
+\protected\edef\ttfamily{%
+ \unexpanded{\luatexko@mono@fonts}\unexpanded\expandafter{\ttfamily}}
\edef\verbatim@font{\unexpanded\expandafter{\verbatim@font
\unsetluatexattribute\finemathattr}}
-%% package options
-\newif\if@hangul
-\newif\if@hanja
-\newif\if@unfonts
-\DeclareOption{hangul}{\@hangultrue}
-\DeclareOption{hanja}{\@hangultrue\@hanjatrue}
-\DeclareOption{unfonts}{\@unfontstrue}
-\ProcessOptions\relax
+% don't forget to redefine \normalfont
+\expandafter\ifx\familydefault\rmdefault
+ \protected\edef\normalfont{%
+ \unexpanded{\luatexko@serif@fonts}\unexpanded\expandafter{\normalfont}}
+ \finemathattr\tw@
+\else\expandafter\ifx\familydefault\sfdefault
+ \protected\edef\normalfont{%
+ \unexpanded{\luatexko@sans@fonts}\unexpanded\expandafter{\normalfont}}
+ \finemathattr\@ne
+\else
+ \protected\edef\normalfont{%
+ \unexpanded{\luatexko@mono@fonts}\unexpanded\expandafter{\normalfont}}
+ \finemathattr\z@
+\fi\fi
+\let\reset@font\normalfont
-\if@unfonts
+\if@unfonts\if@luatexko@loadfontspec
\setmainhangulfont[
InterHangul=-0.04em,
InterLatinCJK=0.125em,
@@ -238,15 +380,15 @@
BoldSlantedFont=*Bold, BoldSlantedFeatures={FakeSlant=0.2},
BoldItalicFont=*Bold, BoldItalicFeatures={FakeSlant=0.2},
]{UnDotum}
-\fi
+\fi\fi
\AtBeginDocument{
\unless\ifdefined\serifhangul@font\let\serifhangul@font\sanshangul@font\fi
\unless\ifdefined\sanshangul@font \let\sanshangul@font\serifhangul@font\fi
\unless\ifdefined\monohangul@font \let\monohangul@font\sanshangul@font \fi
-\luatexko@hangul@selectfont
-\luatexko@hanja@selectfont
-\luatexko@fallback@selectfont
+\unless\ifdefined\serifhangul@font\unless\ifdefined\sanshangul@font
+ \hangulpunctuations=0 % nanumtype1
+\fi\fi
% for hyperref
\@ifpackageloaded{hyperref}{\pdfstringdefDisableCommands{%
\let\dotemph\@firstofone
@@ -258,6 +400,8 @@
\let\uwave\@firstofone
\let\dashuline\@firstofone
\let\dotuline\@firstofone
+ \let\actualtext\@firstofone
+ \let\inhibitglue\empty
\def\는{는}%
\def\은{은}%
\def\을{을}%
@@ -272,25 +416,24 @@
}}{}
}
-%% hangul in math --- latex
-\protected\def\setmathhangulfont{%
- \@ifnextchar[{\setmathhangul@font@}{\setmathhangul@font@[]}}
-\def\setmathhangul@font@[#1]#2{%
- \zf@fontspec{#1}{#2}\xdef\luatexko@math@hangul@family{\zf@family}}
-\AtBeginDocument{%
- \begingroup
- \unless\ifdefined\luatexko@math@hangul@family
- \check@hangul@family
- \ifdefined\hangul@font \hangul@font \fi
- \xdef\luatexko@math@hangul@family{\f@family}%
+\if@luatexko@loadfontspec
+ %% hangul in math --- latex
+ \AtBeginDocument{
+ \begingroup
+ \unless\ifdefined\luatexko@math@hangul@family
+ \ifdefined\hangul@font \hangul@font \fi
+ \xdef\luatexko@math@hangul@family{\f@family}%
+ \fi
+ \endgroup
+ \DeclareSymbolFont{mathhangul}%
+ \zf@enc\luatexko@math@hangul@family\mddefault\updefault
+ \ifcsname\zf@enc/\luatexko@math@hangul@family/\bfdefault/\updefault\endcsname
+ \SetSymbolFont{mathhangul}{bold}%
+ \zf@enc\luatexko@math@hangul@family\bfdefault\updefault
\fi
- \endgroup
- \DeclareSymbolFont{mathhangul}\zf@enc\luatexko@math@hangul@family\mddefault\updefault
- \ifcsname\zf@enc/\luatexko@math@hangul@family/\bfdefault/\updefault\endcsname
- \SetSymbolFont{mathhangul}{bold}\zf@enc\luatexko@math@hangul@family\bfdefault\updefault
- \fi
- \setmathhangulblock{AC00}{D7A3}
-}
+ \setmathhangulblock{AC00}{D7A3}
+ }
+\fi
\RequirePackage{kolabels-utf}
\if@hangul