summaryrefslogtreecommitdiff
path: root/fonts/ptex-fontmaps/jis04cmap_exp/cmapdec.lua
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /fonts/ptex-fontmaps/jis04cmap_exp/cmapdec.lua
Initial commit
Diffstat (limited to 'fonts/ptex-fontmaps/jis04cmap_exp/cmapdec.lua')
-rw-r--r--fonts/ptex-fontmaps/jis04cmap_exp/cmapdec.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/fonts/ptex-fontmaps/jis04cmap_exp/cmapdec.lua b/fonts/ptex-fontmaps/jis04cmap_exp/cmapdec.lua
new file mode 100644
index 0000000000..3438b1f9e6
--- /dev/null
+++ b/fonts/ptex-fontmaps/jis04cmap_exp/cmapdec.lua
@@ -0,0 +1,54 @@
+local line, fh -- line, file handler
+local tt -- 作業用 table
+
+local function load_cid_char()
+ local cid, ucs, ucsa
+ line = fh:read("*l")
+ while line do
+ if string.find(line, "end...?char") then
+ line = fh:read("*l"); return
+ else -- WMA l is in the form "<%x+>%s%d+"
+ ucs, cid = string.match(line, "<(%x+)>%s+<?(%x+)>?")
+ cid = tonumber(cid); ucs = tonumber(ucs, 16);
+ tt[ucs] = cid
+ end
+ line = fh:read("*l")
+ end
+end
+
+local function load_cid_range()
+ local bucs, eucs, cid
+ line = fh:read("*l")
+ while line do
+ if string.find(line, "end...?range") then
+ line = fh:read("*l"); return
+ else -- WMA l is in the form "<%x+>%s+<%x+>"
+ bucs, eucs, cid = string.match(line, "<(%x+)>%s+<(%x+)>%s+<?(%x+)>?")
+ cid = tonumber(cid);
+ bucs = tonumber(bucs, 16); eucs = tonumber(eucs, 16)
+ for ucs = bucs, eucs do
+ tt[ucs], cid = cid, cid + 1
+ end
+ end
+ line = fh:read("*l")
+ end
+ end
+
+local function open_cmap_file(cmap_name, out_table)
+ fh = io.open(kpse.find_file(cmap_name, 'cmap files'), "r")
+ if not out_table then tt = {} else tt = out_table end
+ line = fh:read("*l")
+ while line do
+ if string.find(line, "%x+%s+begin...?char") then
+ load_cid_char()
+ elseif string.find(line, "%x+%s+begin...?range") then
+ load_cid_range()
+ else
+ line = fh:read("*l")
+ end
+ end
+ fh:close();
+ return tt
+end
+
+return { open_cmap_file = open_cmap_file }; \ No newline at end of file