diff options
author | Karl Berry <karl@freefriends.org> | 2014-05-13 22:13:08 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-05-13 22:13:08 +0000 |
commit | 8ed901e81f474c7cf2946183f99b5836d40ffcd7 (patch) | |
tree | 0022083d26affb19815426f497b91ad443d74ebe /Master/texmf-dist/tex/luatex/luatexko/luatexko-normalize.lua | |
parent | bd7687e8abb5975905db822498e640ca7e2e1b2c (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/luatexko/luatexko-normalize.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luatexko/luatexko-normalize.lua | 90 |
1 files changed, 42 insertions, 48 deletions
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 |