summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/tex4ht/fontspec-4ht.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-12-09 00:59:23 +0000
committerKarl Berry <karl@freefriends.org>2016-12-09 00:59:23 +0000
commit438ebe1713d2fa77faf62b8bc742dcda69b8d4db (patch)
treeef08c599f418bdeda6b29af2c8db68ec66f228f9 /Master/texmf-dist/tex/generic/tex4ht/fontspec-4ht.lua
parent1fadcb4880650da2921edf82249f2b889269c9e7 (diff)
fontspec support, tex4ht r205 r210 et al., https://puszcza.gnu.org.ua/bugs/?123
git-svn-id: svn://tug.org/texlive/trunk@42654 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/tex4ht/fontspec-4ht.lua')
-rw-r--r--Master/texmf-dist/tex/generic/tex4ht/fontspec-4ht.lua88
1 files changed, 88 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/generic/tex4ht/fontspec-4ht.lua b/Master/texmf-dist/tex/generic/tex4ht/fontspec-4ht.lua
new file mode 100644
index 00000000000..b7e0873e1c9
--- /dev/null
+++ b/Master/texmf-dist/tex/generic/tex4ht/fontspec-4ht.lua
@@ -0,0 +1,88 @@
+-- fontspec-4ht.lua (2016-12-08-16:38), generated from tex4ht-4ht.tex
+-- Copyright 2016 TeX Users Group
+--[[
+% Copyright 2009-2016 TeX Users Group
+
+--]]
+local M = {}
+
+local glyph_id = node.id "glyph"
+local whatsit_id = node.id "whatsit"
+local special_subtype = node.subtype "special"
+local dir_id = node.id "dir"
+local glue_id = node.id "glue"
+
+local escape = function(char)
+ -- prepare tex4ht special for entity with unicode value
+ return string.format("t4ht@+&{35}x%x{59}", char)
+end
+
+local make_node = function(data)
+ -- make special whathsit
+ local n = node.new(whatsit_id,special_subtype)
+ n.data = data
+ return n
+end
+
+-- this should be table with patterns for allowed fonts
+local allowed_names = {"^cmr", "^cmb","^cmt", "^cmb", "^cmcs", "^rm%-l"}
+
+local testfont = function(name)
+ -- test font name for all allowed names, when it is found, return true
+ for _, x in ipairs(allowed_names) do
+ local r = name:match(x)
+ if r then
+ return true
+ end
+ end
+ return false
+end
+
+local fonttypes = {}
+local get_font_type = function(id)
+ if fonttypes[id]~=nil then return fonttypes[id] end
+ local f = font.getfont(id)
+ local name = f.name
+ local type = testfont(string.lower(name))
+ if not type then
+ print("Unsupported font", name)
+ end
+ fonttypes[id] = type
+ return type
+end
+
+local xchar = string.byte("x")
+
+local utfchar = unicode.utf8.char
+function M.char_to_entity(head)
+ -- traverse characters
+ for n in node.traverse(head) do
+ if n.id == glyph_id then
+ -- we need to process only default text font, ie cmr, because user may request special mathematical fonts,
+ -- which should be processed via htf files as usual
+ local t = get_font_type(n.font)
+ if t == true then
+ local char = n.char
+ if char > 127 then
+ local new = escape(char)
+ local x = make_node(new)
+ -- insert tex4ht special before char, it will replace the char
+ node.insert_before(head, n, x)
+ -- in standard tex4ht accented characters are replaced with "x" char. they are later removed anyway
+ -- maybe we don't need to do that, but we can, so why not?
+ n.char = xchar
+ end
+ end
+ elseif n.id == dir_id then
+ -- when text direction is TRT, the spaces in the DVI file have negative width and they are not recognized by tex4ht
+ -- so we just change the direction to normal TLT
+ n.dir = "TLT"
+ end
+ end
+ return head
+end
+
+M.allowed = allowed_names
+
+return M
+