[latex3-commits] [git/LaTeX3-latex3-luaotfload] harfnode-dev: Reorganisation + Load harfbuzz if available (4f05a6f)
Marcel Fabian Krüger
tex at 2krueger.de
Thu Oct 10 14:57:20 CEST 2019
Repository : https://github.com/latex3/luaotfload
On branch : harfnode-dev
Link : https://github.com/latex3/luaotfload/commit/4f05a6fb2f84c620e8d19e0a6b012e7227289bbd
>---------------------------------------------------------------
commit 4f05a6fb2f84c620e8d19e0a6b012e7227289bbd
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Thu Oct 10 14:57:20 2019 +0200
Reorganisation + Load harfbuzz if available
>---------------------------------------------------------------
4f05a6fb2f84c620e8d19e0a6b012e7227289bbd
.../harf-load.lua => luaotfload-harf-define.lua} | 31 +++++++++-
.../harf-node.lua => luaotfload-harf-plug.lua} | 36 ++++++++---
.../harf-luaotfload.lua => luaotfload-harf.lua} | 70 ----------------------
src/luaotfload-main.lua | 6 ++
4 files changed, 61 insertions(+), 82 deletions(-)
diff --git a/src/harf/harf-load.lua b/src/luaotfload-harf-define.lua
similarity index 90%
rename from src/harf/harf-load.lua
rename to src/luaotfload-harf-define.lua
index 0c8911e..317d129 100644
--- a/src/harf/harf-load.lua
+++ b/src/luaotfload-harf-define.lua
@@ -1,7 +1,6 @@
local hb = luaharfbuzz or require'luaharfbuzz'
-local hbfonts = hb.fonts
-local hbfonts = hbfonts or {}
+local hbfonts = {}
local cfftag = hb.Tag.new("CFF ")
local cff2tag = hb.Tag.new("CFF2")
@@ -322,7 +321,33 @@ local function scalefont(data, spec)
return tfmdata
end
-return function(spec)
+-- Register a reader for `harf` mode (`mode=harf` font option) so that we only
+-- load fonts when explicitly requested. Fonts we load will be shaped by the
+-- harf plugin in luaotfload-harf-plug.
+fonts.readers.harf = function(spec)
if not spec.resolved then return end
+ local rawfeatures = spec.features.raw
+ local hb_features = {}
+ spec.hb_features = hb_features
+
+ if rawfeatures.language then
+ spec.language = harf.Language.new(rawfeatures.language)
+ end
+ if rawfeatures.script then
+ spec.script = harf.Script.new(rawfeatures.script)
+ end
+ for key, val in next, rawfeatures do
+ if key:len() == 4 then
+ -- 4-letter options are likely font features, but not always, so we do
+ -- some checks below. We put non feature options in the `options` dict.
+ if val == true or val == false then
+ val = (val and '+' or '-')..key
+ hb_features[#hb_features + 1] = harf.Feature.new(val)
+ elseif tonumber(val) then
+ val = '+'..key..'='..tonumber(val) - 1
+ hb_features[#hb_features + 1] = harf.Feature.new(val)
+ end
+ end
+ end
return scalefont(loadfont(spec), spec)
end
diff --git a/src/harf/harf-node.lua b/src/luaotfload-harf-plug.lua
similarity index 96%
rename from src/harf/harf-node.lua
rename to src/luaotfload-harf-plug.lua
index 576b446..e543b17 100644
--- a/src/harf/harf-node.lua
+++ b/src/luaotfload-harf-plug.lua
@@ -913,6 +913,7 @@ end
local function run_cleanup()
-- Remove temporary PNG files that we created, if any.
+ -- FIXME: It would be nice if we wouldn't need this
for _, path in next, pngcache do
osremove(path)
end
@@ -931,14 +932,13 @@ local function set_tounicode()
for gid = 0, #glyphs do
local glyph = glyphs[gid]
if glyph.used then
- local tounicode = glyph.tounicode or "FFFD"
local character = characters[gid + gid_offset]
newcharacters[gid + gid_offset] = character
local unicode = nominals[gid]
if unicode then
newcharacters[unicode] = character
end
- character.tounicode = tounicode
+ character.tounicode = glyph.tounicode or "FFFD"
character.used = true
end
end
@@ -956,10 +956,28 @@ end
fonts.handlers.otf.registerplugin('harf', process)
-return {
- -- process = process_nodes,
- post_process = post_process_nodes,
- cleanup = run_cleanup,
- set_tounicode = set_tounicode,
- get_glyph_string = get_glyph_string,
-}
+-- luatexbase does not know how to handle `wrapup_run` callback, teach it.
+luatexbase.callbacktypes.wrapup_run = 1 -- simple
+luatexbase.callbacktypes.get_glyph_string = 1 -- simple
+
+local base_callback_descriptions = luatexbase.callback_descriptions
+local base_add_to_callback = luatexbase.add_to_callback
+local base_remove_from_callback = luatexbase.remove_from_callback
+
+-- Remove all existing functions from given callback, insert ours, then
+-- reinsert the removed ones, so ours takes a priority.
+local function add_to_callback(name, func)
+ local saved_callbacks = {}, ff, dd
+ for k, v in next, base_callback_descriptions(name) do
+ saved_callbacks[k] = { base_remove_from_callback(name, v) }
+ end
+ base_add_to_callback(name, func, "Harf "..name.." callback")
+ for _, v in next, saved_callbacks do
+ base_add_to_callback(name, v[1], v[2])
+ end
+end
+
+add_to_callback('pre_output_filter', post_process_nodes) -- FIXME: Wrong callback, but I want to get rid of the whole function anyway
+add_to_callback('wrapup_run', run_cleanup)
+add_to_callback('finish_pdffile', set_tounicode)
+add_to_callback('get_glyph_string', get_glyph_string)
diff --git a/src/harf/harf-luaotfload.lua b/src/luaotfload-harf.lua
similarity index 62%
rename from src/harf/harf-luaotfload.lua
rename to src/luaotfload-harf.lua
index 96c98d2..3b63a37 100644
--- a/src/harf/harf-luaotfload.lua
+++ b/src/luaotfload-harf.lua
@@ -1,49 +1,5 @@
local harf = luaharfbuzz or require'luaharfbuzz'
-local define_font = require("harf-load")
-local harf_node = require("harf-node")
-
-local callback_warning = true
-if callback_warning then
- local callbacks = callback.list()
- if callbacks["get_glyph_string"] == nil then
- luatexbase.module_warning("harf",
- "'get_glyph_string' callback is missing, " ..
- "log messages might show garbage.")
- end
- callback_warning = false
-end
-
--- Register a reader for `harf` mode (`mode=harf` font option) so that we only
--- load fonts when explicitly requested. Fonts we load will be shaped by the
--- callbacks we register below.
-fonts.readers.harf = function(spec)
- local rawfeatures = spec.features.raw
- local hb_features = {}
- spec.hb_features = hb_features
-
- if rawfeatures.language then
- spec.language = harf.Language.new(rawfeatures.language)
- end
- if rawfeatures.script then
- spec.script = harf.Script.new(rawfeatures.script)
- end
- for key, val in next, rawfeatures do
- if key:len() == 4 then
- -- 4-letter options are likely font features, but not always, so we do
- -- some checks below. We put non feature options in the `options` dict.
- if val == true or val == false then
- val = (val and '+' or '-')..key
- hb_features[#hb_features + 1] = harf.Feature.new(val)
- elseif tonumber(val) then
- val = '+'..key..'='..tonumber(val) - 1
- hb_features[#hb_features + 1] = harf.Feature.new(val)
- end
- end
- end
- return define_font(spec)
-end
-
local GSUBtag = harf.Tag.new("GSUB")
local GPOStag = harf.Tag.new("GPOS")
local dflttag = harf.Tag.new("dflt")
@@ -176,29 +132,3 @@ aux.name_of_slot = function(fontid, codepoint)
end
return aux_name_of_slot(fontid, codepoint)
end
-
--- luatexbase does not know how to handle `wrapup_run` callback, teach it.
-luatexbase.callbacktypes.wrapup_run = 1 -- simple
-luatexbase.callbacktypes.get_glyph_string = 1 -- simple
-
-local base_callback_descriptions = luatexbase.callback_descriptions
-local base_add_to_callback = luatexbase.add_to_callback
-local base_remove_from_callback = luatexbase.remove_from_callback
-
--- Remove all existing functions from given callback, insert ours, then
--- reinsert the removed ones, so ours takes a priority.
-local function add_to_callback(name, func)
- local saved_callbacks = {}, ff, dd
- for k, v in next, base_callback_descriptions(name) do
- saved_callbacks[k] = { base_remove_from_callback(name, v) }
- end
- base_add_to_callback(name, func, "Harf "..name.." callback")
- for _, v in next, saved_callbacks do
- base_add_to_callback(name, v[1], v[2])
- end
-end
-
-add_to_callback('pre_output_filter', harf_node.post_process)
-add_to_callback('wrapup_run', harf_node.cleanup)
-add_to_callback('finish_pdffile', harf_node.set_tounicode)
-add_to_callback('get_glyph_string', harf_node.get_glyph_string)
diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua
index c340253..cc0461a 100644
--- a/src/luaotfload-main.lua
+++ b/src/luaotfload-main.lua
@@ -297,10 +297,16 @@ luaotfload.main = function ()
end
initialize "features" --- font request and feature handling
+
loadmodule "letterspace" --- extra character kerning
loadmodule "embolden" --- fake bold
loadmodule "notdef" --- missing glyph handling
initialize "auxiliary" --- additional high-level functionality
+ if pcall(require, 'luaharfbuzz') then
+ loadmodule "harf"
+ loadmodule "harf-define"
+ loadmodule "harf-plug"
+ end
loadmodule "multiscript" --- ...
luaotfload.aux.start_rewrite_fontname () --- to be migrated to fontspec
More information about the latex3-commits
mailing list