summaryrefslogtreecommitdiff
path: root/tex/context/base/font-afm.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/font-afm.lua')
-rw-r--r--tex/context/base/font-afm.lua101
1 files changed, 86 insertions, 15 deletions
diff --git a/tex/context/base/font-afm.lua b/tex/context/base/font-afm.lua
index adb4281b2..a96c6686e 100644
--- a/tex/context/base/font-afm.lua
+++ b/tex/context/base/font-afm.lua
@@ -15,6 +15,14 @@ n='otf'/>.</p>
<p>The following code still has traces of intermediate font support
where we handles font encodings. Eventually font encoding goes
away.</p>
+
+<p>The embedding of a font involves creating temporary files and
+depending on your system setup that can fail. It took more than a
+day to figure out why sometimes embedding failed in mingw luatex
+where running on a real path like c:\... failed while running on
+say e:\... being a link worked well. The native windows binaries
+don't have this issue.</p>
+
--ldx]]--
local fonts, logs, trackers, containers, resolvers = fonts, logs, trackers, containers, resolvers
@@ -32,19 +40,26 @@ local trace_defining = false trackers.register("fonts.defining", function(v
local report_afm = logs.reporter("fonts","afm loading")
+local setmetatableindex = table.setmetatableindex
+
local findbinfile = resolvers.findbinfile
local definers = fonts.definers
local readers = fonts.readers
local constructors = fonts.constructors
+local fontloader = fontloader
+local font_to_table = fontloader.to_table
+local open_font = fontloader.open
+local close_font = fontloader.close
+
local afm = constructors.newhandler("afm")
local pfb = constructors.newhandler("pfb")
local afmfeatures = constructors.newfeatures("afm")
local registerafmfeature = afmfeatures.register
-afm.version = 1.410 -- incrementing this number one up will force a re-cache
+afm.version = 1.500 -- incrementing this number one up will force a re-cache
afm.cache = containers.define("fonts", "afm", afm.version, true)
afm.autoprefixed = true -- this will become false some day (catches texnansi-blabla.*)
@@ -54,6 +69,8 @@ afm.addligatures = true -- best leave this set to true
afm.addtexligatures = true -- best leave this set to true
afm.addkerns = true -- best leave this set to true
+local overloads = fonts.mappings.overloads
+
local applyruntimefixes = fonts.treatments and fonts.treatments.applyfixes
local function setmode(tfmdata,value)
@@ -210,10 +227,10 @@ end
local function get_indexes(data,pfbname)
data.resources.filename = resolvers.unresolve(pfbname) -- no shortcut
- local pfbblob = fontloader.open(pfbname)
+ local pfbblob = open_font(pfbname)
if pfbblob then
local characters = data.characters
- local pfbdata = fontloader.to_table(pfbblob)
+ local pfbdata = font_to_table(pfbblob)
if pfbdata then
local glyphs = pfbdata.glyphs
if glyphs then
@@ -221,6 +238,7 @@ local function get_indexes(data,pfbname)
report_afm("getting index data from %a",pfbname)
end
for index, glyph in next, glyphs do
+ -- for index, glyph in table.sortedhash(glyphs) do
local name = glyph.name
if name then
local char = characters[name]
@@ -238,7 +256,7 @@ local function get_indexes(data,pfbname)
elseif trace_loading then
report_afm("no data in pfb file %a",pfbname)
end
- fontloader.close(pfbblob)
+ close_font(pfbblob)
elseif trace_loading then
report_afm("invalid pfb file %a",pfbname)
end
@@ -306,7 +324,7 @@ by adding ligatures and kern information to the afm derived data. That
way we can set them faster when defining a font.</p>
--ldx]]--
-local addkerns, addligatures, addtexligatures, unify, normalize -- we will implement these later
+local addkerns, addligatures, addtexligatures, unify, normalize, fixnames -- we will implement these later
function afm.load(filename)
-- hm, for some reasons not resolved yet
@@ -336,6 +354,7 @@ function afm.load(filename)
get_indexes(data,pfbname)
elseif trace_loading then
report_afm("no pfb file for %a",filename)
+ -- data.resources.filename = "unset" -- better than loading the afm file
end
report_afm("unifying %a",filename)
unify(data,filename)
@@ -352,6 +371,7 @@ function afm.load(filename)
addkerns(data)
end
normalize(data)
+ fixnames(data)
report_afm("add tounicode data")
fonts.mappings.addtounicode(data,filename)
data.size = size
@@ -359,6 +379,7 @@ function afm.load(filename)
data.pfbsize = pfbsize
data.pfbtime = pfbtime
report_afm("saving %a in cache",name)
+ data.resources.unicodes = nil -- consistent with otf but here we save not much
data = containers.write(afm.cache, name, data)
data = containers.read(afm.cache,name)
end
@@ -410,7 +431,7 @@ unify = function(data, filename)
if unicode then
krn[unicode] = kern
else
- print(unicode,name)
+ -- print(unicode,name)
end
end
description.kerns = krn
@@ -422,13 +443,29 @@ unify = function(data, filename)
resources.filename = resolvers.unresolve(filename) -- no shortcut
resources.unicodes = unicodes -- name to unicode
resources.marks = { } -- todo
- resources.names = names -- name to index
+ -- resources.names = names -- name to index
resources.private = private
end
normalize = function(data)
end
+fixnames = function(data)
+ for k, v in next, data.descriptions do
+ local n = v.name
+ local r = overloads[n]
+ if r then
+ local name = r.name
+ if trace_indexing then
+ report_afm("renaming characters %a to %a",n,name)
+ end
+ v.name = name
+ v.unicode = r.unicode
+ end
+ end
+end
+
+
--[[ldx--
<p>These helpers extend the basic table with extra ligatures, texligatures
and extra kerns. This saves quite some lookups later.</p>
@@ -439,7 +476,7 @@ local addthem = function(rawdata,ligatures)
local descriptions = rawdata.descriptions
local resources = rawdata.resources
local unicodes = resources.unicodes
- local names = resources.names
+ -- local names = resources.names
for ligname, ligdata in next, ligatures do
local one = descriptions[unicodes[ligname]]
if one then
@@ -598,8 +635,8 @@ local function copytotfm(data)
local filename = constructors.checkedfilename(resources)
local fontname = metadata.fontname or metadata.fullname
local fullname = metadata.fullname or metadata.fontname
- local endash = unicodes['space']
- local emdash = unicodes['emdash']
+ local endash = 0x0020 -- space
+ local emdash = 0x2014
local spacer = "space"
local spaceunits = 500
--
@@ -659,7 +696,7 @@ local function copytotfm(data)
parameters.x_height = charxheight
else
-- same as otf
- local x = unicodes['x']
+ local x = 0x0078 -- x
if x then
local x = descriptions[x]
if x then
@@ -719,7 +756,34 @@ function afm.setfeatures(tfmdata,features)
end
end
-local function checkfeatures(specification)
+local function addtables(data)
+ local resources = data.resources
+ local lookuptags = resources.lookuptags
+ local unicodes = resources.unicodes
+ if not lookuptags then
+ lookuptags = { }
+ resources.lookuptags = lookuptags
+ end
+ setmetatableindex(lookuptags,function(t,k)
+ local v = type(k) == "number" and ("lookup " .. k) or k
+ t[k] = v
+ return v
+ end)
+ if not unicodes then
+ unicodes = { }
+ resources.unicodes = unicodes
+ setmetatableindex(unicodes,function(t,k)
+ setmetatableindex(unicodes,nil)
+ for u, d in next, data.descriptions do
+ local n = d.name
+ if n then
+ t[n] = u
+ end
+ end
+ return rawget(t,k)
+ end)
+ end
+ constructors.addcoreunicodes(unicodes) -- do we really need this?
end
local function afmtotfm(specification)
@@ -749,6 +813,7 @@ local function afmtotfm(specification)
if not tfmdata then
local rawdata = afm.load(afmname)
if rawdata and next(rawdata) then
+ addtables(rawdata)
adddimensions(rawdata)
tfmdata = copytotfm(rawdata)
if tfmdata and next(tfmdata) then
@@ -798,6 +863,7 @@ those that make sense for this format.</p>
local function prepareligatures(tfmdata,ligatures,value)
if value then
local descriptions = tfmdata.descriptions
+ local hasligatures = false
for unicode, character in next, tfmdata.characters do
local description = descriptions[unicode]
local dligatures = description.ligatures
@@ -813,17 +879,20 @@ local function prepareligatures(tfmdata,ligatures,value)
type = 0
}
end
+ hasligatures = true
end
end
+ tfmdata.properties.hasligatures = hasligatures
end
end
local function preparekerns(tfmdata,kerns,value)
if value then
- local rawdata = tfmdata.shared.rawdata
- local resources = rawdata.resources
- local unicodes = resources.unicodes
+ local rawdata = tfmdata.shared.rawdata
+ local resources = rawdata.resources
+ local unicodes = resources.unicodes
local descriptions = tfmdata.descriptions
+ local haskerns = false
for u, chr in next, tfmdata.characters do
local d = descriptions[u]
local newkerns = d[kerns]
@@ -839,8 +908,10 @@ local function preparekerns(tfmdata,kerns,value)
kerns[uk] = v
end
end
+ haskerns = true
end
end
+ tfmdata.properties.haskerns = haskerns
end
end