summaryrefslogtreecommitdiff
path: root/texmf-dist/tex/generic/harftex/harf-load.lua
diff options
context:
space:
mode:
Diffstat (limited to 'texmf-dist/tex/generic/harftex/harf-load.lua')
-rw-r--r--texmf-dist/tex/generic/harftex/harf-load.lua75
1 files changed, 72 insertions, 3 deletions
diff --git a/texmf-dist/tex/generic/harftex/harf-load.lua b/texmf-dist/tex/generic/harftex/harf-load.lua
index c467cedd..06af2706 100644
--- a/texmf-dist/tex/generic/harftex/harf-load.lua
+++ b/texmf-dist/tex/generic/harftex/harf-load.lua
@@ -205,6 +205,32 @@ local function loadfont(spec)
end
end
+-- Drop illegal characters from PS Name, per the spec
+-- https://docs.microsoft.com/en-us/typography/opentype/spec/name#nid6
+local function sanitize(psname)
+ local new = psname:gsub(".", function(c)
+ local b = c:byte()
+ if (b < 33 or b > 126)
+ or c == "["
+ or c == "]"
+ or c == "("
+ or c == ")"
+ or c == "{"
+ or c == "}"
+ or c == "<"
+ or c == ">"
+ or c == "/"
+ or c == "%"
+ then
+ return "-"
+ end
+ return c
+ end)
+ return new
+end
+
+local tlig = hb.texlig
+
local function scalefont(data, spec)
local size = spec.size
local options = spec.options
@@ -248,22 +274,63 @@ local function scalefont(data, spec)
local letterspace = tonumber(options.letterspace or 0) / 100 * upem
space = space + letterspace
- local slantfactor = tonumber(options.slant or 0)
+ local slantfactor = nil
+ if options.slant then
+ slantfactor = tonumber(options.slant) * 1000
+ end
+
+ local mode = nil
+ local width = nil
+ if options.embolden then
+ mode = 2
+ -- The multiplication by 7200.0/7227 is to undo the opposite conversion
+ -- LuaTeX is doing and make the final number written in the PDF file match
+ -- XeTeX's.
+ width = (size * tonumber(options.embolden) / 6553.6) * (7200.0/7227)
+ end
+
+ local hscale = upem
+ local extendfactor = nil
+ if options.extend then
+ extendfactor = tonumber(options.extend) * 1000
+ hscale = hscale * tonumber(options.extend)
+ end
+
+ local vscale = upem
+ local squeezefactor = nil
+ if options.squeeze then
+ squeezefactor = tonumber(options.squeeze) * 1000
+ vscale = vscale * tonumber(options.squeeze)
+ end
+
+ if options.texlig then
+ for char in next, characters do
+ local ligatures = tlig[char]
+ if ligatures then
+ characters[char].ligatures = ligatures
+ end
+ end
+ end
return {
name = spec.specification,
filename = spec.path,
designsize = size,
- psname = data.psname,
+ psname = sanitize(data.psname),
fullname = data.fullname,
index = spec.index,
size = size,
+ units_per_em = upem,
type = "real",
embedding = "subset",
tounicode = 1,
nomath = true,
format = data.fonttype,
- slant = slantfactor * 1000,
+ slant = slantfactor,
+ mode = mode,
+ width = width,
+ extend = extendfactor,
+ squeeze = squeezefactor,
characters = characters,
parameters = {
slant = data.slant,
@@ -281,6 +348,8 @@ local function scalefont(data, spec)
palette = palette,
shared = data,
letterspace = letterspace,
+ hscale = hscale,
+ vscale = vscale,
},
}
end