luametalatex/luametalatex-pdf-font-t1.lua

58 lines
2.4 KiB
Lua
Raw Normal View History

2020-07-15 04:51:59 +02:00
local readfile = require'luametalatex-readfile'
2019-07-17 21:14:34 +02:00
-- Some helpers:
local serialize_cff = require'luametalatex-font-cff'
local serializet2 = require'luametalatex-font-t2'
local parseT1 = require'luametalatex-font-t1'
local t1tot2 = require'luametalatex-font-t1tot2'
return function(filename, reencode)
2020-07-15 16:36:11 +02:00
local file <close> = readfile('type1', filename)
2020-07-15 04:51:59 +02:00
local parsed_t1 = parseT1(file())
2019-07-17 21:14:34 +02:00
return function(f, usedcids)
f.bbox = parsed_t1.FontBBox
local fonttable = {
version = parsed_t1.FontInfo.version,
Notice = parsed_t1.FontInfo.Notice,
FullName = parsed_t1.FontInfo.FullName,
FamilyName = parsed_t1.FontInfo.FamilyName,
Weight = parsed_t1.FontInfo.Weight,
ItalicAngle = parsed_t1.FontInfo.ItalicAngle,
isFixedPitch = parsed_t1.FontInfo.isFixedPitch,
UnderlinePosition = parsed_t1.FontInfo.UnderlinePosition,
UnderlineThickness = parsed_t1.FontInfo.UnderlineThickness,
FontName = parsed_t1.FontName,
FontMatrix = parsed_t1.FontMatrix,
FontBBox = parsed_t1.FontBBox,
-- UniqueID = parsed_t1.UniqueID,
-- ? = parsed_t1.Metrics,
---- PRIVATE ----
BlueValues = parsed_t1.Private.BlueValues,
OtherBlues = parsed_t1.Private.OtherBlues,
-- FamilyBlues?
BlueScale = parsed_t1.Private.BlueScale,
BlueShift = parsed_t1.Private.BlueShift,
BlueFuzz = parsed_t1.Private.BlueFuzz,
StdHW = (parsed_t1.Private.StdHW or {})[1], -- Why are these arrays in T1?
StdVW = (parsed_t1.Private.StdVW or {})[1], -- They are also undocumented in the spec...
StemSnapH = parsed_t1.Private.StemSnapH,
StemSnapV = parsed_t1.Private.StemSnapV,
ForceBold = parsed_t1.Private.ForceBold,
-- LanguageGroup = parsed_t1.Private.LanguageGroup,
}
if not reencode and parsed_t1.Encoding == "StandardEncoding" then
2020-07-15 16:36:11 +02:00
reencode = '8a'
2019-07-17 21:14:34 +02:00
end
if reencode then
2020-06-16 21:17:43 +02:00
parsed_t1.Encoding = require'luametalatex-font-enc'(reencode)
2019-07-17 21:14:34 +02:00
end
-- parsed_t1.Encoding[0] = ".notdef"
local glyphs = {}
fonttable.glyphs = glyphs
for i=1,#usedcids do
local name = parsed_t1.Encoding[usedcids[i][1]] -- TODO: Reencoding and StandardEncoding
glyphs[#glyphs + 1] = {index = usedcids[i][1], name = name, cs = serializet2(t1tot2(parsed_t1.CharStrings[name], parsed_t1.Private.Subrs))} -- TODO: Missing glyphs
end
return serialize_cff(fonttable)
end
end