OSDN Git Service

ltj-otf.lua: \CID{} (only AJ16) works in TrueType fonts.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 19 Mar 2013 01:17:17 +0000 (10:17 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Tue, 19 Mar 2013 01:17:17 +0000 (10:17 +0900)
src/ltj-otf.lua
src/ltj-rmlgbm.lua
test/test10a-otf-ttf.pdf [new file with mode: 0644]
test/test10a-otf-ttf.tex [new file with mode: 0644]

index c16e15b..e2f8cad 100644 (file)
@@ -11,6 +11,7 @@ module('luatexja.otf', package.seeall)
 
 luatexja.load_module('base');      local ltjb = luatexja.base
 luatexja.load_module('jfont');     local ltjf = luatexja.jfont
+luatexja.load_module('rmlgbm');    local ltjr = luatexja.rmlgbm
 
 local id_glyph = node.id('glyph')
 local id_whatsit = node.id('whatsit')
@@ -32,9 +33,34 @@ local attr_ykblshift = luatexbase.attributes['ltj@ykblshift']
 
 local ltjf_font_metric_table = ltjf.font_metric_table
 local ltjf_find_char_class = ltjf.find_char_class
+local ltjr_cidfont_data = ltjr.cidfont_data
 
 local OTF = luatexja.userid_table.OTF
 
+function get_ucs_from_rmlgbm(c)
+   local v = ltjr_cidfont_data["Adobe-Japan1"].unicodes["Japan1." .. tostring(c)]
+   if not v then -- AJ1 範囲外
+      return 0
+   elseif v<0xF0000 then -- 素直に Unicode にマップ可能
+      return v
+   else
+      local w = ltjr_cidfont_data["Adobe-Japan1"].characters[v]. tounicode
+      -- must be non-nil!
+      local i = string.len(w)
+      if i==4 then -- UCS2
+         return tonumber(w,16)
+      elseif i==8 then 
+         i,w = tonumber(string.sub(w,1,4),16), tonumber(string.sub(w,-4),16)
+         if (w>=0xD800) and (w<=0xDB7F) and (i>=0xDC00) and (i<=0xDFFF) then -- Surrogate pair
+            return (w-0xD800)*0x400 + (i-0xDC00)
+         else
+            return 0
+         end
+      end
+      --print(c, v, w) 
+   end
+end
+
 -- Append a whatsit node to the list.
 -- This whatsit node will be extracted to a glyph_node
 function append_jglyph(char)
@@ -51,16 +77,19 @@ function cid(key)
           curjfnt.cidinfo.ordering ~= "GB1" and
           curjfnt.cidinfo.ordering ~= "CNS1" and
           curjfnt.cidinfo.ordering ~= "Korea1" then
-      ltjb.package_error('luatexja-otf',
-                         'Current Japanese font (or other CJK font) "'..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)', 
-                         'Select a CID-Keyed font using \\jfont.')
-      return
+           ltjb.package_warning('luatexja-otf',
+                                'Current Japanese font (or other CJK font) "'
+                                   ..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)')
+           return append_jglyph(get_ucs_from_rmlgbm(key))
    end
    local char = curjfnt.unicodes[curjfnt.cidinfo.ordering..'.'..tostring(key)]
    if not char then
       ltjb.package_warning('luatexja-otf',
-                         'Current Japanese font (or other CJK font) "'..curjfnt.psname..'" does not include the specified CID character ('..tostring(key)..')', 
-                         'Use a font including the specified CID character.')
+                           'Current Japanese font (or other CJK font) "'
+                              ..curjfnt.psname..'" does not have the specified CID character ('
+                              ..tostring(key)..')', 
+                           'Use a font including the specified CID character.')
+      char = 0
       return
    end
    append_jglyph(char)
index 56e8b1f..3ecf55d 100644 (file)
@@ -12,7 +12,8 @@ local err, warn, info, log = luatexbase.errwarinf(_NAME)
 
 luatexja.load_module('base');      local ltjb = luatexja.base
 
-local cidfont_data = {}
+cidfont_data = {}
+local cidfont_data = cidfont_data
 local cache_chars = {}
 local path           = {
     localdir  = file.join(kpse.expand_var("$TEXMFVAR"), aux_dir),
@@ -60,8 +61,8 @@ local cid_replace = {
 -- reading CID maps
 do
    local line, fh -- line, file handler
-   local tt, cidm  -- characters, cid->glyph_index
-   
+   local tt,cidm -- characters, cid->(Unicode)
+
    local function load_cid_char(cid_dec, mke)
       local cid, ucs, ucsa
       line = fh:read("*l")
@@ -348,4 +349,4 @@ function fonts.define.read(name, size, id)
 end
 
 cid_reg, cid_order, cid_name = 'Adobe', 'Japan1', 'Adobe-Japan1'
-read_cid_font()
\ No newline at end of file
+read_cid_font()
diff --git a/test/test10a-otf-ttf.pdf b/test/test10a-otf-ttf.pdf
new file mode 100644 (file)
index 0000000..dbe0f85
Binary files /dev/null and b/test/test10a-otf-ttf.pdf differ
diff --git a/test/test10a-otf-ttf.tex b/test/test10a-otf-ttf.tex
new file mode 100644 (file)
index 0000000..6aac9dc
--- /dev/null
@@ -0,0 +1,32 @@
+%#! luajitlatex
+\documentclass{ltjsarticle}
+\usepackage{luacode}
+\usepackage[ipaex]{luatexja-preset}
+\usepackage{luatexja-otf}
+
+\textwidth=600pt
+\def\ox{\hbox to 10pt{%
+  \CID{\the\tb}\hss}%
+  \global\advance\tb1\relax}
+\def\BOUND{15444}
+
+\catcode`\_=11
+\newcount\tb
+\def\out_one_line{%
+  \par\noindent
+  \hbox to 3\zw{\hfil \the\tb}\quad
+  \ox\ox\ox\ox\ox\ox\ox\ox\ox\ox\quad
+  \ox\ox\ox\ox\ox\ox\ox\ox\ox\ox\quad
+  \ox\ox\ox\ox\ox\ox\ox\ox\ox\ox\quad
+  \ox\ox\ox\ox\ox\ox\ox\ox\ox\ox\par
+}
+\begin{document}
+\paragraph{Adobe-Japan1-4のグリフをIPAex明朝で表示させてみる}
+\
+
+
+\loop
+  \out_one_line
+  \ifnum\tb<\BOUND
+\repeat
+\end{document}