summaryrefslogtreecommitdiff
path: root/luaotfload-loaders.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-08-25 11:47:01 -0700
committerPhilipp Gesang <phg42.2a@gmail.com>2013-08-25 11:47:01 -0700
commit0812209b5d7566de272739ada26eca08f216b876 (patch)
treed2dddab1c57956fabfb89c443267fceb6d8e7a0a /luaotfload-loaders.lua
parent6c668c8f2624a22a1f4ddd99d9f561ddf2f4bf0a (diff)
parent54aa74688bba09a538a98d6852fc3848c6c5f52c (diff)
downloadluaotfload-0812209b5d7566de272739ada26eca08f216b876.tar.gz
Merge pull request #126 from phi-gamma/master
improved afm integration
Diffstat (limited to 'luaotfload-loaders.lua')
-rw-r--r--luaotfload-loaders.lua152
1 files changed, 13 insertions, 139 deletions
diff --git a/luaotfload-loaders.lua b/luaotfload-loaders.lua
index 6d6f409..20eb277 100644
--- a/luaotfload-loaders.lua
+++ b/luaotfload-loaders.lua
@@ -11,158 +11,32 @@ local readers = fonts.readers
local handlers = fonts.handlers
local formats = fonts.formats
-local lfsisfile = lfs.isfile
-local fileaddsuffix = file.addsuffix
-local filebasename = file.basename
-local stringsub = string.sub
-local stringlower = string.lower
-local stringupper = string.upper
-local findbinfile = resolvers.findbinfile
-
-local lpeg = require "lpeg"
-local lpegmatch = lpeg.match
-local P, S, Cp = lpeg.P, lpeg.S, lpeg.Cp
-
-resolvers.openbinfile = function (filename)
- if filename and filename ~= "" then
- local f = io.open(filename,"rb")
- if f then
- --logs.show_load(filename)
- local s = f:read("*a") -- io.readall(f) is faster but we never have large files here
- if checkgarbage then
- checkgarbage(#s)
- end
- f:close()
- if s then
- return true, s, #s
- end
- end
- end
- return loaders.notfound()
-end
-
-resolvers.loadbinfile = function (filename, filetype)
-
- local fname = kpse.find_file (filename, filetype)
-
- if fname and fname ~= "" then
- return resolvers.openbinfile(fname)
- else
- return resolvers.loaders.notfound()
- end
-
-end
-
---- this function is required because AFM precedes TFM in the reader
---- chain (see definers.loadfont() in font-def.lua
-
-local check_tfm = function (specification, fullname)
-
- local foundname = findbinfile (fullname, "tfm") or ""
-
- if foundname == "" then
- foundname = findbinfile (fullname, "ofm") or ""
- end
-
- if foundname == "" then
- foundname = fonts.names.getfilename (fullname,"tfm") or ""
- end
-
- if foundname ~= "" then
- specification.filename = foundname
- specification.format = "ofm"
- return font.read_tfm (specification.filename,
- specification.size)
- end
-end
-
-readers.check_tfm = check_tfm
-
---[[ <EXPERIMENTAL> ]]
-
--[[doc--
- Here we load extra AFM libraries from Context.
- In fact, part of the AFM support is contained in font-ext.lua, for
- which the font loader has a replacement: luatex-fonts-ext.lua.
- However, this is only a stripped down version with everything AFM
- removed. For example, it lacks definitions of several AFM features
- like italic correction, protrusion, expansion and so on. In order to
- achieve full-fledged AFM support we will either have to implement our
- own version of these or consult with Hans whether he would consider
- including the AFM code with the font loader.
+ As of 2013-08-25 AFM support has been included in the fontloader
+ package.
- For the time being we stick with two AFM-specific libraries:
- font-afm.lua and font-afk.lua. When combined, these already supply us
- with basic features like kerning and ligatures. The rest can be added
- in due time.
+ We still have to load the font feature definitions (font-afk.lua) to
+ achieve kerning and ligatures.
--doc]]--
-require "luaotfload-font-afm.lua"
require "luaotfload-font-afk.lua"
---[[ </EXPERIMENTAL> ]]
-
---[[doc--
-
- The PFB/PFA reader checks whether there is a corresponding AFM file
- and hands the spec over to the AFM loader if appropriate. Context
- uses string.gsub() to accomplish this but that can cause collateral
- damage.
-
---doc]]--
-
-local mk_type1_reader = function (format)
-
- format = stringlower (format)
- local first = stringsub (format, 1, 1)
- local second = stringsub (format, 2, 2)
- local third = stringsub (format, 3, 3)
-
- local p_format = P"."
- * (P(first) + P(stringupper (first)))
- * (P(second) + P(stringupper (second)))
- * (P(third) + P(stringupper (third)))
- --- we have to be careful here so we don’t affect
- --- harmless substrings
- * (P"(" --- subfont
- + P":" --- feature list
- + P(-1)) --- end of string
- local no_format = 1 - p_format
- local p_format_file = no_format^1 * Cp() * p_format * Cp()
-
- local reader = function (specification, method)
-
- local afmfile = fileaddsuffix (specification.name, "afm")
-
- if lfsisfile (afmfile) then
- --- switch to afm reader
- logs.names_report ("log", 0, "type1",
- "Found corresponding AFM file %s, using that.",
- filebasename (afmfile))
- local oldspec = specification.specification
- local before, after = lpegmatch (p_format_file, oldspec)
- specification.specification = stringsub (oldspec, 1, before)
- .. "afm"
- .. stringsub (oldspec, after - 1)
- specification.forced = "afm"
- return readers.afm (specification, method)
- end
-
- --- else read pfb via opentype mechanism
- return readers.opentype (specification, format, "type1")
- end
-
- return reader
+local pfb_reader = function (specification)
+ return readers.opentype (specification, "pfb", "type1")
+end
+
+local pfa_reader = function (specification)
+ return readers.opentype (specification, "pfa", "type1")
end
formats.pfa = "type1"
-readers.pfa = mk_type1_reader "pfa"
+readers.pfa = pfa_reader
handlers.pfa = { }
formats.pfb = "type1"
-readers.pfb = mk_type1_reader "pfb"
-handlers.pfb = { } --- empty, as with tfm
+readers.pfb = pfb_reader
+handlers.pfb = { }
-- vim:tw=71:sw=2:ts=2:expandtab