| 1 |
if not modules then modules = { } end modules ['font-con'] = { |
| 2 |
version = 1.001, |
| 3 |
comment = "companion to font-ini.mkiv", |
| 4 |
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", |
| 5 |
copyright = "PRAGMA ADE / ConTeXt Development Team", |
| 6 |
license = "see context related readme files" |
| 7 |
} |
| 8 |
|
| 9 |
-- Todo: Enable fixes from the lmt to here. Also in font-oto.lua wrt the changed |
| 10 |
-- assignments. (Around texlive 2024 in order not to disturb generic.) |
| 11 |
|
| 12 |
-- some names of table entries will be changed (no _) |
| 13 |
|
| 14 |
local next, tostring, tonumber, rawget = next, tostring, tonumber, rawget |
| 15 |
local format, match, lower, gsub, find = string.format, string.match, string.lower, string.gsub, string.find |
| 16 |
local sort, insert, concat = table.sort, table.insert, table.concat |
| 17 |
local sortedkeys, sortedhash, serialize, fastcopy = table.sortedkeys, table.sortedhash, table.serialize, table.fastcopy |
| 18 |
local derivetable = table.derive |
| 19 |
local ioflush = io.flush |
| 20 |
local round = math.round |
| 21 |
local setmetatable, getmetatable, rawget, rawset = setmetatable, getmetatable, rawget, rawset |
| 22 |
|
| 23 |
local trace_defining = false trackers.register("fonts.defining", function(v) trace_defining = v end) |
| 24 |
local trace_scaling = false trackers.register("fonts.scaling", function(v) trace_scaling = v end) |
| 25 |
|
| 26 |
local report_defining = logs.reporter("fonts","defining") |
| 27 |
|
| 28 |
-- Watch out: no negative depths and negative heights are permitted in regular |
| 29 |
-- fonts. Also, the code in LMTX is a bit different. Here we only implement a |
| 30 |
-- few helper functions. |
| 31 |
|
| 32 |
local fonts = fonts |
| 33 |
local constructors = fonts.constructors or { } |
| 34 |
fonts.constructors = constructors |
| 35 |
local handlers = fonts.handlers or { } -- can have preloaded tables |
| 36 |
fonts.handlers = handlers |
| 37 |
|
| 38 |
local allocate = utilities.storage.allocate |
| 39 |
local setmetatableindex = table.setmetatableindex |
| 40 |
|
| 41 |
-- will be directives |
| 42 |
|
| 43 |
constructors.dontembed = allocate() |
| 44 |
constructors.namemode = "fullpath" -- will be a function |
| 45 |
|
| 46 |
constructors.version = 1.01 |
| 47 |
constructors.cache = containers.define("fonts", "constructors", constructors.version, false) |
| 48 |
|
| 49 |
constructors.privateoffset = fonts.privateoffsets.textbase or 0xF0000 |
| 50 |
constructors.cacheintex = true -- so we see the original table in fonts.font |
| 51 |
|
| 52 |
constructors.addtounicode = true |
| 53 |
|
| 54 |
constructors.fixprotrusion = true |
| 55 |
|
| 56 |
-- This might become an interface: |
| 57 |
|
| 58 |
local designsizes = allocate() |
| 59 |
constructors.designsizes = designsizes |
| 60 |
local loadedfonts = allocate() |
| 61 |
constructors.loadedfonts = loadedfonts |
| 62 |
|
| 63 |
-- We need to normalize the scale factor (in scaled points). This has to do with the |
| 64 |
-- fact that TeX uses a negative multiple of 1000 as a signal for a font scaled |
| 65 |
-- based on the design size. |
| 66 |
|
| 67 |
local factors = { |
| 68 |
pt = 65536.0, |
| 69 |
bp = 65781.8, |
| 70 |
} |
| 71 |
|
| 72 |
function constructors.setfactor(f) |
| 73 |
constructors.factor = factors[f or 'pt'] or factors.pt |
| 74 |
end |
| 75 |
|
| 76 |
constructors.setfactor() |
| 77 |
|
| 78 |
function constructors.scaled(scaledpoints, designsize) -- handles designsize in sp as well |
| 79 |
if scaledpoints < 0 then |
| 80 |
local factor = constructors.factor |
| 81 |
if designsize then |
| 82 |
if designsize > factor then -- or just 1000 / when? mp? |
| 83 |
return (- scaledpoints/1000) * designsize -- sp's |
| 84 |
else |
| 85 |
return (- scaledpoints/1000) * designsize * factor |
| 86 |
end |
| 87 |
else |
| 88 |
return (- scaledpoints/1000) * 10 * factor |
| 89 |
end |
| 90 |
else |
| 91 |
return scaledpoints |
| 92 |
end |
| 93 |
end |
| 94 |
|
| 95 |
function constructors.getprivate(tfmdata) |
| 96 |
local properties = tfmdata.properties |
| 97 |
local private = properties.private |
| 98 |
properties.private = private + 1 |
| 99 |
return private |
| 100 |
end |
| 101 |
|
| 102 |
function constructors.setmathparameter(tfmdata,name,value) |
| 103 |
local m = tfmdata.mathparameters |
| 104 |
local c = tfmdata.MathConstants |
| 105 |
if m then |
| 106 |
m[name] = value |
| 107 |
end |
| 108 |
if c and c ~= m then |
| 109 |
c[name] = value |
| 110 |
end |
| 111 |
end |
| 112 |
|
| 113 |
function constructors.getmathparameter(tfmdata,name) |
| 114 |
local p = tfmdata.mathparameters or tfmdata.MathConstants |
| 115 |
if p then |
| 116 |
return p[name] |
| 117 |
end |
| 118 |
end |
| 119 |
|
| 120 |
-- Beware, the boundingbox is passed as reference so we may not overwrite it in the |
| 121 |
-- process; numbers are of course copies. Here 65536 equals 1pt. (Due to excessive |
| 122 |
-- memory usage in CJK fonts, we no longer pass the boundingbox.) |
| 123 |
-- |
| 124 |
-- The scaler is only used for OTF and AFM and virtual fonts. If a virtual font has |
| 125 |
-- italic correction make sure to set the hasitalics flag. Some more flags will be |
| 126 |
-- added in the future. |
| 127 |
-- |
| 128 |
-- The reason why the scaler was originally split, is that for a while we |
| 129 |
-- experimented with a helper function. However, in practice the API calls are too |
| 130 |
-- slow to make this profitable and the Lua based variant was just faster. A days |
| 131 |
-- wasted day but an experience richer. |
| 132 |
|
| 133 |
function constructors.cleanuptable(tfmdata) |
| 134 |
-- This no longer makes sense because the addition of font.getcopy and its |
| 135 |
-- possible usage in generic implicates that we need to return the whole |
| 136 |
-- lot now. |
| 137 |
end |
| 138 |
|
| 139 |
-- experimental, sharing kerns (unscaled and scaled) saves memory |
| 140 |
-- local sharedkerns, basekerns = constructors.check_base_kerns(tfmdata) |
| 141 |
-- loop over descriptions (afm and otf have descriptions, tfm not) |
| 142 |
-- there is no need (yet) to assign a value to chr.tonunicode |
| 143 |
|
| 144 |
-- constructors.prepare_base_kerns(tfmdata) -- optimalization |
| 145 |
|
| 146 |
-- we have target.name=metricfile and target.fullname=RealName and target.filename=diskfilename |
| 147 |
-- when collapsing fonts, luatex looks as both target.name and target.fullname as ttc files |
| 148 |
-- can have multiple subfonts |
| 149 |
|
| 150 |
function constructors.calculatescale(tfmdata,scaledpoints) |
| 151 |
local parameters = tfmdata.parameters |
| 152 |
if scaledpoints < 0 then |
| 153 |
scaledpoints = (- scaledpoints/1000) * (tfmdata.designsize or parameters.designsize) -- already in sp |
| 154 |
end |
| 155 |
return scaledpoints, scaledpoints / (parameters.units or 1000) -- delta |
| 156 |
end |
| 157 |
|
| 158 |
local unscaled = { |
| 159 |
ScriptPercentScaleDown = true, |
| 160 |
ScriptScriptPercentScaleDown = true, |
| 161 |
RadicalDegreeBottomRaisePercent = true, |
| 162 |
NoLimitSupFactor = true, |
| 163 |
NoLimitSubFactor = true, |
| 164 |
} |
| 165 |
|
| 166 |
function constructors.assignmathparameters(target,original) -- simple variant, not used in context |
| 167 |
-- when a tfm file is loaded, it has already been scaled |
| 168 |
-- and it never enters the scaled so this is otf only and |
| 169 |
-- even then we do some extra in the context math plugins |
| 170 |
local mathparameters = original.mathparameters |
| 171 |
if mathparameters and next(mathparameters) then |
| 172 |
local targetparameters = target.parameters |
| 173 |
local targetproperties = target.properties |
| 174 |
local targetmathparameters = { } |
| 175 |
local factor = targetproperties.math_is_scaled and 1 or targetparameters.factor |
| 176 |
for name, value in next, mathparameters do |
| 177 |
if unscaled[name] then |
| 178 |
targetmathparameters[name] = value |
| 179 |
else |
| 180 |
targetmathparameters[name] = value * factor |
| 181 |
end |
| 182 |
end |
| 183 |
if not targetmathparameters.FractionDelimiterSize then |
| 184 |
targetmathparameters.FractionDelimiterSize = 1.01 * targetparameters.size |
| 185 |
end |
| 186 |
if not mathparameters.FractionDelimiterDisplayStyleSize then |
| 187 |
targetmathparameters.FractionDelimiterDisplayStyleSize = 2.40 * targetparameters.size |
| 188 |
end |
| 189 |
if not targetmathparameters.SpaceBeforeScript then |
| 190 |
targetmathparameters.SpaceBeforeScript = targetmathparameters.SpaceAfterScript |
| 191 |
end |
| 192 |
target.mathparameters = targetmathparameters |
| 193 |
end |
| 194 |
end |
| 195 |
|
| 196 |
function constructors.beforecopyingcharacters(target,original) |
| 197 |
-- can be used for additional tweaking |
| 198 |
end |
| 199 |
|
| 200 |
function constructors.aftercopyingcharacters(target,original) |
| 201 |
-- can be used for additional tweaking |
| 202 |
end |
| 203 |
|
| 204 |
-- It's probably ok to hash just the indices because there is not that much |
| 205 |
-- chance that one will shift slots and leave the others unset then. Anyway, |
| 206 |
-- there is of course some overhead here, but it might as well get compensated |
| 207 |
-- by less time spent on including the font resource twice. For the moment |
| 208 |
-- we default to false, so a macro package has to enable it explicitly. In |
| 209 |
-- LuaTeX the fullname is used to identify a font as being unique. |
| 210 |
|
| 211 |
local nofinstances = 0 |
| 212 |
local instances = setmetatableindex(function(t,k) |
| 213 |
nofinstances = nofinstances + 1 |
| 214 |
t[k] = nofinstances |
| 215 |
return nofinstances |
| 216 |
end) |
| 217 |
|
| 218 |
function constructors.trytosharefont(target,tfmdata) |
| 219 |
local properties = target.properties |
| 220 |
local instance = properties.instance |
| 221 |
if instance then |
| 222 |
local fullname = target.fullname |
| 223 |
local fontname = target.fontname |
| 224 |
local psname = target.psname |
| 225 |
local format = tfmdata.properties.format |
| 226 |
if format == "opentype" then |
| 227 |
target.streamprovider = 1 |
| 228 |
elseif format == "truetype" then |
| 229 |
target.streamprovider = 2 |
| 230 |
else |
| 231 |
target.streamprovider = 0 |
| 232 |
end |
| 233 |
if target.streamprovider > 0 then |
| 234 |
if fullname then |
| 235 |
fullname = fullname .. ":" .. instances[instance] |
| 236 |
target.fullname = fullname |
| 237 |
end |
| 238 |
if fontname then |
| 239 |
fontname = fontname .. ":" .. instances[instance] |
| 240 |
target.fontname = fontname |
| 241 |
end |
| 242 |
if psname then |
| 243 |
psname = psname .. ":" .. instances[instance] |
| 244 |
target.psname = psname |
| 245 |
end |
| 246 |
end |
| 247 |
end |
| 248 |
end |
| 249 |
|
| 250 |
local synonyms = { |
| 251 |
exheight = "x_height", |
| 252 |
xheight = "x_height", |
| 253 |
ex = "x_height", |
| 254 |
emwidth = "quad", |
| 255 |
em = "quad", |
| 256 |
spacestretch = "space_stretch", |
| 257 |
stretch = "space_stretch", |
| 258 |
spaceshrink = "space_shrink", |
| 259 |
shrink = "space_shrink", |
| 260 |
extraspace = "extra_space", |
| 261 |
xspace = "extra_space", |
| 262 |
slantperpoint = "slant", |
| 263 |
} |
| 264 |
|
| 265 |
function constructors.enhanceparameters(parameters) |
| 266 |
local mt = getmetatable(parameters) |
| 267 |
local getter = function(t,k) |
| 268 |
if not k then |
| 269 |
return nil |
| 270 |
end |
| 271 |
local s = synonyms[k] |
| 272 |
if s then |
| 273 |
return rawget(t,s) or (mt and mt[s]) or nil |
| 274 |
end |
| 275 |
if k == "spacing" then |
| 276 |
return { |
| 277 |
width = t.space, |
| 278 |
stretch = t.space_stretch, |
| 279 |
shrink = t.space_shrink, |
| 280 |
extra = t.extra_space, |
| 281 |
} |
| 282 |
end |
| 283 |
return mt and mt[k] or nil |
| 284 |
end |
| 285 |
local setter = function(t,k,v) |
| 286 |
if not k then |
| 287 |
return 0 |
| 288 |
end |
| 289 |
local s = synonyms[k] |
| 290 |
if s then |
| 291 |
rawset(t,s,v) |
| 292 |
elseif k == "spacing" then |
| 293 |
if type(v) == "table" then |
| 294 |
rawset(t,"space",v.width or 0) |
| 295 |
rawset(t,"space_stretch",v.stretch or 0) |
| 296 |
rawset(t,"space_shrink",v.shrink or 0) |
| 297 |
rawset(t,"extra_space",v.extra or 0) |
| 298 |
end |
| 299 |
else |
| 300 |
rawset(t,k,v) |
| 301 |
end |
| 302 |
end |
| 303 |
setmetatable(parameters, { |
| 304 |
__index = getter, |
| 305 |
__newindex = setter, |
| 306 |
}) |
| 307 |
end |
| 308 |
|
| 309 |
local function mathkerns(v,vdelta) |
| 310 |
local k = { } |
| 311 |
for i=1,#v do |
| 312 |
local entry = v[i] |
| 313 |
local height = entry.height |
| 314 |
local kern = entry.kern |
| 315 |
k[i] = { |
| 316 |
height = height and vdelta*height or 0, |
| 317 |
kern = kern and vdelta*kern or 0, |
| 318 |
} |
| 319 |
end |
| 320 |
return k |
| 321 |
end |
| 322 |
|
| 323 |
local psfake = 0 |
| 324 |
|
| 325 |
local function fixedpsname(psname,fallback) |
| 326 |
local usedname = psname |
| 327 |
if psname and psname ~= "" then |
| 328 |
if find(psname," ",1,true) then |
| 329 |
usedname = gsub(psname,"[%s]+","-") |
| 330 |
else |
| 331 |
-- we assume that the name is sane enough (we might sanitize completely some day) |
| 332 |
end |
| 333 |
elseif not fallback or fallback == "" then |
| 334 |
psfake = psfake + 1 |
| 335 |
psname = "fakename-" .. psfake |
| 336 |
else |
| 337 |
-- filenames can be a mess so we do a drastic cleanup |
| 338 |
psname = fallback |
| 339 |
usedname = gsub(psname,"[^a-zA-Z0-9]+","-") |
| 340 |
end |
| 341 |
return usedname, psname ~= usedname |
| 342 |
end |
| 343 |
|
| 344 |
function constructors.scale(tfmdata,specification) |
| 345 |
local target = { } -- the new table |
| 346 |
-- |
| 347 |
if tonumber(specification) then |
| 348 |
specification = { size = specification } |
| 349 |
end |
| 350 |
target.specification = specification |
| 351 |
-- |
| 352 |
local scaledpoints = specification.size |
| 353 |
local relativeid = specification.relativeid |
| 354 |
-- |
| 355 |
local properties = tfmdata.properties or { } |
| 356 |
local goodies = tfmdata.goodies or { } |
| 357 |
local resources = tfmdata.resources or { } |
| 358 |
local descriptions = tfmdata.descriptions or { } -- bad news if empty |
| 359 |
local characters = tfmdata.characters or { } -- bad news if empty |
| 360 |
local changed = tfmdata.changed or { } -- for base mode |
| 361 |
local shared = tfmdata.shared or { } |
| 362 |
local parameters = tfmdata.parameters or { } |
| 363 |
local mathparameters = tfmdata.mathparameters or { } |
| 364 |
-- |
| 365 |
local targetcharacters = { } |
| 366 |
local targetdescriptions = derivetable(descriptions) |
| 367 |
local targetparameters = derivetable(parameters) |
| 368 |
local targetproperties = derivetable(properties) |
| 369 |
local targetgoodies = goodies -- we need to loop so no metatable |
| 370 |
target.characters = targetcharacters |
| 371 |
target.descriptions = targetdescriptions |
| 372 |
target.parameters = targetparameters |
| 373 |
-- target.mathparameters = targetmathparameters -- happens elsewhere |
| 374 |
target.properties = targetproperties |
| 375 |
target.goodies = targetgoodies |
| 376 |
target.shared = shared |
| 377 |
target.resources = resources |
| 378 |
target.unscaled = tfmdata -- the original unscaled one |
| 379 |
-- |
| 380 |
-- specification.mathsize : 1=text 2=script 3=scriptscript |
| 381 |
-- specification.textsize : natural (text)size |
| 382 |
-- parameters.mathsize : 1=text 2=script 3=scriptscript >1000 enforced size (feature value other than yes) |
| 383 |
-- |
| 384 |
local mathsize = tonumber(specification.mathsize) or 0 |
| 385 |
local textsize = tonumber(specification.textsize) or scaledpoints |
| 386 |
-- local forcedsize = tonumber(parameters.mathsize ) or 0 -- can be set by the feature "mathsize" |
| 387 |
local extrafactor = tonumber(specification.factor ) or 1 |
| 388 |
-- if context then |
| 389 |
-- -- do nothing, as we moved this upstream |
| 390 |
-- elseif (mathsize == 2 or forcedsize == 2) and parameters.scriptpercentage then |
| 391 |
-- scaledpoints = parameters.scriptpercentage * textsize / 100 |
| 392 |
-- elseif (mathsize == 3 or forcedsize == 3) and parameters.scriptscriptpercentage then |
| 393 |
-- scaledpoints = parameters.scriptscriptpercentage * textsize / 100 |
| 394 |
-- elseif forcedsize > 1000 then -- safeguard |
| 395 |
-- scaledpoints = forcedsize |
| 396 |
-- end |
| 397 |
targetparameters.mathsize = mathsize -- context specific |
| 398 |
targetparameters.textsize = textsize -- context specific |
| 399 |
-- targetparameters.forcedsize = forcedsize -- context specific |
| 400 |
targetparameters.extrafactor = extrafactor -- context specific |
| 401 |
-- |
| 402 |
local addtounicode = constructors.addtounicode |
| 403 |
-- |
| 404 |
local tounicode = fonts.mappings.tounicode |
| 405 |
local unknowncode = tounicode(0xFFFD) |
| 406 |
-- |
| 407 |
local defaultwidth = resources.defaultwidth or 0 |
| 408 |
local defaultheight = resources.defaultheight or 0 |
| 409 |
local defaultdepth = resources.defaultdepth or 0 |
| 410 |
local units = parameters.units or 1000 |
| 411 |
-- |
| 412 |
-- boundary keys are no longer needed as we now have a string 'right_boundary' |
| 413 |
-- that can be used in relevant tables (kerns and ligatures) ... not that I ever |
| 414 |
-- used them |
| 415 |
-- |
| 416 |
-- boundarychar_label = 0, -- not needed |
| 417 |
-- boundarychar = 65536, -- there is now a string 'right_boundary' |
| 418 |
-- false_boundarychar = 65536, -- produces invalid tfm in luatex |
| 419 |
-- |
| 420 |
targetproperties.language = properties.language or "dflt" -- inherited |
| 421 |
targetproperties.script = properties.script or "dflt" -- inherited |
| 422 |
targetproperties.mode = properties.mode or "base" -- inherited |
| 423 |
targetproperties.method = properties.method |
| 424 |
-- |
| 425 |
local askedscaledpoints = scaledpoints |
| 426 |
local scaledpoints, delta = constructors.calculatescale(tfmdata,scaledpoints,nil,specification) -- no shortcut, dan be redefined |
| 427 |
-- |
| 428 |
local hdelta = delta |
| 429 |
local vdelta = delta |
| 430 |
-- |
| 431 |
target.designsize = parameters.designsize -- not really needed so it might become obsolete |
| 432 |
target.units = units |
| 433 |
target.units_per_em = units -- just a trigger for the backend |
| 434 |
-- |
| 435 |
local direction = properties.direction or tfmdata.direction or 0 -- pointless, as we don't use omf fonts at all |
| 436 |
target.direction = direction |
| 437 |
properties.direction = direction |
| 438 |
-- |
| 439 |
target.size = scaledpoints |
| 440 |
-- |
| 441 |
target.encodingbytes = properties.encodingbytes or 1 |
| 442 |
target.subfont = properties.subfont |
| 443 |
target.embedding = properties.embedding or "subset" |
| 444 |
target.tounicode = 1 |
| 445 |
target.cidinfo = properties.cidinfo |
| 446 |
target.format = properties.format |
| 447 |
target.cache = constructors.cacheintex and "yes" or "renew" |
| 448 |
-- |
| 449 |
local original = properties.original or tfmdata.original |
| 450 |
local fontname = properties.fontname or tfmdata.fontname |
| 451 |
local fullname = properties.fullname or tfmdata.fullname |
| 452 |
local filename = properties.filename or tfmdata.filename |
| 453 |
local psname = properties.psname or tfmdata.psname |
| 454 |
local name = properties.name or tfmdata.name |
| 455 |
-- |
| 456 |
-- The psname used in pdf file as well as for selecting subfont in ttc although |
| 457 |
-- we don't need that subfont look up here (mapfile stuff). |
| 458 |
-- |
| 459 |
local psname, psfixed = fixedpsname(psname,fontname or fullname or file.nameonly(filename)) |
| 460 |
-- |
| 461 |
target.original = original |
| 462 |
target.fontname = fontname |
| 463 |
target.fullname = fullname |
| 464 |
target.filename = filename |
| 465 |
target.psname = psname |
| 466 |
target.name = name |
| 467 |
-- |
| 468 |
properties.fontname = fontname |
| 469 |
properties.fullname = fullname |
| 470 |
properties.filename = filename |
| 471 |
properties.psname = psname |
| 472 |
properties.name = name |
| 473 |
-- expansion (hz) |
| 474 |
local expansion = parameters.expansion |
| 475 |
if expansion then |
| 476 |
target.stretch = expansion.stretch |
| 477 |
target.shrink = expansion.shrink |
| 478 |
target.step = expansion.step |
| 479 |
end |
| 480 |
-- slanting |
| 481 |
local slantfactor = parameters.slantfactor or 0 |
| 482 |
if slantfactor ~= 0 then |
| 483 |
target.slant = slantfactor * 1000 |
| 484 |
else |
| 485 |
target.slant = 0 |
| 486 |
end |
| 487 |
-- widening |
| 488 |
local extendfactor = parameters.extendfactor or 0 |
| 489 |
if extendfactor ~= 0 and extendfactor ~= 1 then |
| 490 |
hdelta = hdelta * extendfactor |
| 491 |
target.extend = extendfactor * 1000 |
| 492 |
else |
| 493 |
target.extend = 1000 -- extent ? |
| 494 |
end |
| 495 |
-- squeezing |
| 496 |
local squeezefactor = parameters.squeezefactor or 0 |
| 497 |
if squeezefactor ~= 0 and squeezefactor ~= 1 then |
| 498 |
vdelta = vdelta * squeezefactor |
| 499 |
target.squeeze = squeezefactor * 1000 |
| 500 |
else |
| 501 |
target.squeeze = 1000 -- extent ? |
| 502 |
end |
| 503 |
-- effects |
| 504 |
local mode = parameters.mode or 0 |
| 505 |
if mode ~= 0 then |
| 506 |
target.mode = mode |
| 507 |
end |
| 508 |
local width = parameters.width or 0 |
| 509 |
if width ~= 0 then |
| 510 |
target.width = width * delta * 1000 / 655360 |
| 511 |
end |
| 512 |
-- |
| 513 |
targetparameters.factor = delta |
| 514 |
targetparameters.hfactor = hdelta |
| 515 |
targetparameters.vfactor = vdelta |
| 516 |
targetparameters.size = scaledpoints |
| 517 |
targetparameters.units = units |
| 518 |
targetparameters.scaledpoints = askedscaledpoints |
| 519 |
targetparameters.mode = mode |
| 520 |
targetparameters.width = width |
| 521 |
-- |
| 522 |
local isvirtual = properties.virtualized or tfmdata.type == "virtual" |
| 523 |
local hasquality = parameters.expansion or parameters.protrusion |
| 524 |
local hasitalics = properties.hasitalics |
| 525 |
local autoitalicamount = properties.autoitalicamount |
| 526 |
local stackmath = not properties.nostackmath |
| 527 |
local haskerns = properties.haskerns or properties.mode == "base" -- we can have afm in node mode |
| 528 |
local hasligatures = properties.hasligatures or properties.mode == "base" -- we can have afm in node mode |
| 529 |
local realdimensions = properties.realdimensions |
| 530 |
local writingmode = properties.writingmode or "horizontal" |
| 531 |
local identity = properties.identity or "horizontal" |
| 532 |
local vfonts = target.fonts |
| 533 |
if vfonts and #vfonts > 0 then |
| 534 |
target.fonts = fastcopy(vfonts) -- maybe we virtualize more afterwards |
| 535 |
elseif isvirtual then |
| 536 |
target.fonts = { { id = 0 } } -- catch error |
| 537 |
end |
| 538 |
-- |
| 539 |
if changed and not next(changed) then |
| 540 |
changed = false |
| 541 |
end |
| 542 |
-- |
| 543 |
target.type = isvirtual and "virtual" or "real" |
| 544 |
target.writingmode = writingmode == "vertical" and "vertical" or "horizontal" |
| 545 |
target.identity = identity == "vertical" and "vertical" or "horizontal" |
| 546 |
-- |
| 547 |
target.postprocessors = tfmdata.postprocessors |
| 548 |
-- |
| 549 |
local targetslant = (parameters.slant or parameters[1] or 0) * factors.pt -- per point |
| 550 |
local targetspace = (parameters.space or parameters[2] or 0) * hdelta |
| 551 |
local targetspace_stretch = (parameters.space_stretch or parameters[3] or 0) * hdelta |
| 552 |
local targetspace_shrink = (parameters.space_shrink or parameters[4] or 0) * hdelta |
| 553 |
local targetx_height = (parameters.x_height or parameters[5] or 0) * vdelta |
| 554 |
local targetquad = (parameters.quad or parameters[6] or 0) * hdelta |
| 555 |
local targetextra_space = (parameters.extra_space or parameters[7] or 0) * hdelta |
| 556 |
-- |
| 557 |
targetparameters.slant = targetslant -- slantperpoint |
| 558 |
targetparameters.space = targetspace |
| 559 |
targetparameters.space_stretch = targetspace_stretch |
| 560 |
targetparameters.space_shrink = targetspace_shrink |
| 561 |
targetparameters.x_height = targetx_height |
| 562 |
targetparameters.quad = targetquad |
| 563 |
targetparameters.extra_space = targetextra_space |
| 564 |
-- |
| 565 |
local hshift = parameters.hshift |
| 566 |
if hshift then |
| 567 |
targetparameters.hshift = delta * hshift |
| 568 |
end |
| 569 |
local vshift = parameters.vshift |
| 570 |
if vshift then |
| 571 |
targetparameters.vshift = delta * vshift |
| 572 |
end |
| 573 |
-- |
| 574 |
local ascender = parameters.ascender |
| 575 |
if ascender then |
| 576 |
targetparameters.ascender = delta * ascender |
| 577 |
end |
| 578 |
local descender = parameters.descender |
| 579 |
if descender then |
| 580 |
targetparameters.descender = delta * descender |
| 581 |
end |
| 582 |
-- |
| 583 |
constructors.enhanceparameters(targetparameters) -- official copies for us, now virtual |
| 584 |
-- |
| 585 |
-- I need to fix this in luatex ... get rid of quad there so that we can omit this here. |
| 586 |
-- |
| 587 |
local protrusionfactor = constructors.fixprotrusion and ((targetquad ~= 0 and 1000/targetquad) or 1) or 1 |
| 588 |
-- |
| 589 |
local scaledwidth = defaultwidth * hdelta |
| 590 |
local scaledheight = defaultheight * vdelta |
| 591 |
local scaleddepth = defaultdepth * vdelta |
| 592 |
-- |
| 593 |
local hasmath = (properties.hasmath or next(mathparameters)) and true |
| 594 |
-- |
| 595 |
if hasmath then |
| 596 |
constructors.assignmathparameters(target,tfmdata) -- does scaling and whatever is needed |
| 597 |
properties.hasmath = true |
| 598 |
target.nomath = false |
| 599 |
target.MathConstants = target.mathparameters |
| 600 |
-- |
| 601 |
local oldmath = properties.oldmath |
| 602 |
targetproperties.oldmath = oldmath |
| 603 |
target.oldmath = oldmath |
| 604 |
else |
| 605 |
properties.hasmath = false |
| 606 |
target.nomath = true |
| 607 |
target.mathparameters = nil -- nop |
| 608 |
end |
| 609 |
-- |
| 610 |
-- Here we support some context specific trickery (this might move to a plugin). During the |
| 611 |
-- transition to opentype the engine had troubles with italics so we had some additional code |
| 612 |
-- for fixing that. In node mode (text) we don't care much if italics gets passed because |
| 613 |
-- the engine does nothign with them then. |
| 614 |
-- |
| 615 |
if hasmath then |
| 616 |
local mathitalics = properties.mathitalics |
| 617 |
if mathitalics == false then |
| 618 |
if trace_defining then |
| 619 |
report_defining("%s italics %s for font %a, fullname %a, filename %a","math",hasitalics and "ignored" or "disabled",name,fullname,filename) |
| 620 |
end |
| 621 |
hasitalics = false |
| 622 |
autoitalicamount = false |
| 623 |
end |
| 624 |
else |
| 625 |
local textitalics = properties.textitalics |
| 626 |
if textitalics == false then |
| 627 |
if trace_defining then |
| 628 |
report_defining("%s italics %s for font %a, fullname %a, filename %a","text",hasitalics and "ignored" or "disabled",name,fullname,filename) |
| 629 |
end |
| 630 |
hasitalics = false |
| 631 |
autoitalicamount = false |
| 632 |
end |
| 633 |
end |
| 634 |
-- |
| 635 |
-- end of context specific trickery |
| 636 |
-- |
| 637 |
if trace_defining then |
| 638 |
report_defining("defining tfm, name %a, fullname %a, filename %a, %spsname %a, hscale %a, vscale %a, math %a, italics %a", |
| 639 |
name,fullname,filename,psfixed and "(fixed) " or "",psname,hdelta,vdelta, |
| 640 |
hasmath and "enabled" or "disabled",hasitalics and "enabled" or "disabled") |
| 641 |
end |
| 642 |
-- |
| 643 |
constructors.beforecopyingcharacters(target,tfmdata) |
| 644 |
-- |
| 645 |
local sharedkerns = { } |
| 646 |
-- |
| 647 |
-- we can have a dumb mode (basemode without math etc) that skips most |
| 648 |
-- |
| 649 |
for unicode, character in next, characters do |
| 650 |
local chr, description, index |
| 651 |
if changed then |
| 652 |
local c = changed[unicode] |
| 653 |
if c and c ~= unicode then |
| 654 |
local cc = changed[c] |
| 655 |
if cc then |
| 656 |
while cc do |
| 657 |
c = cc |
| 658 |
cc = changed[c] |
| 659 |
end |
| 660 |
end |
| 661 |
-- check not needed: |
| 662 |
if c then |
| 663 |
description = descriptions[c] or descriptions[unicode] or character |
| 664 |
character = characters[c] or character |
| 665 |
index = description.index or c |
| 666 |
else |
| 667 |
description = descriptions[unicode] or character |
| 668 |
index = description.index or unicode |
| 669 |
end |
| 670 |
else |
| 671 |
description = descriptions[unicode] or character |
| 672 |
index = description.index or unicode |
| 673 |
end |
| 674 |
else |
| 675 |
description = descriptions[unicode] or character |
| 676 |
index = description.index or unicode |
| 677 |
end |
| 678 |
local width = description.width |
| 679 |
local height = description.height |
| 680 |
local depth = description.depth |
| 681 |
local isunicode = description.unicode |
| 682 |
if realdimensions then |
| 683 |
-- this is mostly for checking issues |
| 684 |
if not height or height == 0 then |
| 685 |
local bb = description.boundingbox |
| 686 |
local ht = bb[4] |
| 687 |
if ht ~= 0 then |
| 688 |
height = ht |
| 689 |
end |
| 690 |
if not depth or depth == 0 then |
| 691 |
local dp = -bb[2] |
| 692 |
if dp ~= 0 then |
| 693 |
depth = dp |
| 694 |
end |
| 695 |
end |
| 696 |
elseif not depth or depth == 0 then |
| 697 |
local dp = -description.boundingbox[2] |
| 698 |
if dp ~= 0 then |
| 699 |
depth = dp |
| 700 |
end |
| 701 |
end |
| 702 |
end |
| 703 |
if width then width = hdelta*width else width = scaledwidth end |
| 704 |
if height then height = vdelta*height else height = scaledheight end |
| 705 |
-- if depth then depth = vdelta*depth else depth = scaleddepth end |
| 706 |
if depth and depth ~= 0 then |
| 707 |
depth = delta*depth |
| 708 |
if isunicode then |
| 709 |
chr = { |
| 710 |
index = index, |
| 711 |
height = height, |
| 712 |
depth = depth, |
| 713 |
width = width, |
| 714 |
unicode = isunicode, |
| 715 |
} |
| 716 |
else |
| 717 |
chr = { |
| 718 |
index = index, |
| 719 |
height = height, |
| 720 |
depth = depth, |
| 721 |
width = width, |
| 722 |
} |
| 723 |
end |
| 724 |
else |
| 725 |
if isunicode then |
| 726 |
chr = { |
| 727 |
index = index, |
| 728 |
height = height, |
| 729 |
width = width, |
| 730 |
unicode = isunicode, |
| 731 |
} |
| 732 |
else |
| 733 |
chr = { |
| 734 |
index = index, |
| 735 |
height = height, |
| 736 |
width = width, |
| 737 |
} |
| 738 |
end |
| 739 |
end |
| 740 |
if addtounicode then |
| 741 |
chr.tounicode = isunicode and tounicode(isunicode) or unknowncode |
| 742 |
end |
| 743 |
if hasquality then |
| 744 |
-- we could move these calculations elsewhere (saves calculations) |
| 745 |
local ve = character.expansion_factor |
| 746 |
if ve then |
| 747 |
chr.expansion_factor = ve*1000 -- expansionfactor, hm, can happen elsewhere |
| 748 |
end |
| 749 |
local vl = character.left_protruding |
| 750 |
if vl then |
| 751 |
chr.left_protruding = protrusionfactor*width*vl |
| 752 |
end |
| 753 |
local vr = character.right_protruding |
| 754 |
if vr then |
| 755 |
chr.right_protruding = protrusionfactor*width*vr |
| 756 |
end |
| 757 |
end |
| 758 |
-- |
| 759 |
if hasmath then |
| 760 |
-- |
| 761 |
-- todo, just operate on descriptions.math |
| 762 |
local vn = character.next |
| 763 |
if vn then |
| 764 |
chr.next = vn |
| 765 |
else |
| 766 |
local vv = character.vert_variants |
| 767 |
if vv then |
| 768 |
local t = { } |
| 769 |
for i=1,#vv do |
| 770 |
local vvi = vv[i] |
| 771 |
local s = vvi["start"] or 0 |
| 772 |
local e = vvi["end"] or 0 |
| 773 |
local a = vvi["advance"] or 0 |
| 774 |
t[i] = { -- zero check nicer for 5.3 |
| 775 |
["start"] = s == 0 and 0 or s * vdelta, |
| 776 |
["end"] = e == 0 and 0 or e * vdelta, |
| 777 |
["advance"] = a == 0 and 0 or a * vdelta, |
| 778 |
["extender"] = vvi["extender"], |
| 779 |
["glyph"] = vvi["glyph"], |
| 780 |
} |
| 781 |
end |
| 782 |
chr.vert_variants = t |
| 783 |
else |
| 784 |
local hv = character.horiz_variants |
| 785 |
if hv then |
| 786 |
local t = { } |
| 787 |
for i=1,#hv do |
| 788 |
local hvi = hv[i] |
| 789 |
local s = hvi["start"] or 0 |
| 790 |
local e = hvi["end"] or 0 |
| 791 |
local a = hvi["advance"] or 0 |
| 792 |
t[i] = { -- zero check nicer for 5.3 |
| 793 |
["start"] = s == 0 and 0 or s * hdelta, |
| 794 |
["end"] = e == 0 and 0 or e * hdelta, |
| 795 |
["advance"] = a == 0 and 0 or a * hdelta, |
| 796 |
["extender"] = hvi["extender"], |
| 797 |
["glyph"] = hvi["glyph"], |
| 798 |
} |
| 799 |
end |
| 800 |
chr.horiz_variants = t |
| 801 |
end |
| 802 |
end |
| 803 |
-- todo also check mathitalics (or that one can go away) |
| 804 |
end |
| 805 |
local vi = character.vert_italic |
| 806 |
if vi and vi ~= 0 then |
| 807 |
chr.vert_italic = vi*hdelta |
| 808 |
end |
| 809 |
local va = character.accent |
| 810 |
if va then |
| 811 |
chr.top_accent = vdelta*va |
| 812 |
end |
| 813 |
if stackmath then |
| 814 |
local mk = character.mathkerns |
| 815 |
if mk then |
| 816 |
local tr = mk.topright |
| 817 |
local tl = mk.topleft |
| 818 |
local br = mk.bottomright |
| 819 |
local bl = mk.bottomleft |
| 820 |
chr.mathkern = { -- singular -> should be patched in luatex ! |
| 821 |
top_right = tr and mathkerns(tr,vdelta) or nil, |
| 822 |
top_left = tl and mathkerns(tl,vdelta) or nil, |
| 823 |
bottom_right = br and mathkerns(br,vdelta) or nil, |
| 824 |
bottom_left = bl and mathkerns(bl,vdelta) or nil, |
| 825 |
} |
| 826 |
end |
| 827 |
end |
| 828 |
if hasitalics then |
| 829 |
local vi = character.italic |
| 830 |
if vi and vi ~= 0 then |
| 831 |
chr.italic = vi*hdelta |
| 832 |
end |
| 833 |
end |
| 834 |
elseif autoitalicamount then -- itlc feature |
| 835 |
local vi = description.italic |
| 836 |
if not vi then |
| 837 |
local bb = description.boundingbox |
| 838 |
if bb then |
| 839 |
local vi = bb[3] - description.width + autoitalicamount |
| 840 |
if vi > 0 then -- < 0 indicates no overshoot or a very small auto italic |
| 841 |
chr.italic = vi*hdelta |
| 842 |
end |
| 843 |
else |
| 844 |
-- report_defining("no boundingbox for character %C in font %a, fullname %a, filename %a",unicode,name,fullname,filename) |
| 845 |
end |
| 846 |
elseif vi ~= 0 then |
| 847 |
chr.italic = vi*hdelta |
| 848 |
end |
| 849 |
elseif hasitalics then -- unlikely |
| 850 |
local vi = character.italic |
| 851 |
if vi and vi ~= 0 then |
| 852 |
chr.italic = vi*hdelta |
| 853 |
end |
| 854 |
end |
| 855 |
if haskerns then |
| 856 |
local vk = character.kerns |
| 857 |
if vk then |
| 858 |
local s = sharedkerns[vk] |
| 859 |
if not s then |
| 860 |
s = { } |
| 861 |
for k,v in next, vk do s[k] = v*hdelta end |
| 862 |
sharedkerns[vk] = s |
| 863 |
end |
| 864 |
chr.kerns = s |
| 865 |
end |
| 866 |
end |
| 867 |
if hasligatures then |
| 868 |
local vl = character.ligatures |
| 869 |
if vl then |
| 870 |
if true then |
| 871 |
chr.ligatures = vl -- shared |
| 872 |
else |
| 873 |
local tt = { } |
| 874 |
for i, l in next, vl do |
| 875 |
tt[i] = l |
| 876 |
end |
| 877 |
chr.ligatures = tt |
| 878 |
end |
| 879 |
end |
| 880 |
end |
| 881 |
if isvirtual then |
| 882 |
local vc = character.commands |
| 883 |
if vc then |
| 884 |
-- we assume non scaled commands here |
| 885 |
-- tricky .. we need to scale pseudo math glyphs too |
| 886 |
-- which is why we deal with rules too |
| 887 |
local ok = false |
| 888 |
for i=1,#vc do |
| 889 |
local key = vc[i][1] |
| 890 |
if key == "right" or key == "down" or key == "rule" then |
| 891 |
ok = true |
| 892 |
break |
| 893 |
end |
| 894 |
end |
| 895 |
if ok then |
| 896 |
local tt = { } |
| 897 |
for i=1,#vc do |
| 898 |
local ivc = vc[i] |
| 899 |
local key = ivc[1] |
| 900 |
if key == "right" then |
| 901 |
tt[i] = { key, ivc[2]*hdelta } |
| 902 |
elseif key == "down" then |
| 903 |
tt[i] = { key, ivc[2]*vdelta } |
| 904 |
elseif key == "rule" then |
| 905 |
tt[i] = { key, ivc[2]*vdelta, ivc[3]*hdelta } |
| 906 |
else -- not comment |
| 907 |
tt[i] = ivc -- shared since in cache and untouched |
| 908 |
end |
| 909 |
end |
| 910 |
chr.commands = tt |
| 911 |
else |
| 912 |
chr.commands = vc |
| 913 |
end |
| 914 |
-- chr.index = nil |
| 915 |
end |
| 916 |
end |
| 917 |
targetcharacters[unicode] = chr |
| 918 |
end |
| 919 |
-- |
| 920 |
properties.setitalics = hasitalics -- for postprocessing |
| 921 |
-- |
| 922 |
constructors.aftercopyingcharacters(target,tfmdata) |
| 923 |
-- |
| 924 |
constructors.trytosharefont(target,tfmdata) |
| 925 |
-- |
| 926 |
-- catch inconsistencies |
| 927 |
-- |
| 928 |
local vfonts = target.fonts |
| 929 |
if isvirtual or target.type == "virtual" or properties.virtualized then |
| 930 |
properties.virtualized = true |
| 931 |
target.type = "virtual" |
| 932 |
if not vfonts or #vfonts == 0 then |
| 933 |
target.fonts = { { id = 0 } } |
| 934 |
end |
| 935 |
elseif vfonts then |
| 936 |
properties.virtualized = true |
| 937 |
target.type = "virtual" |
| 938 |
if #vfonts == 0 then |
| 939 |
target.fonts = { { id = 0 } } |
| 940 |
end |
| 941 |
end |
| 942 |
-- |
| 943 |
return target |
| 944 |
end |
| 945 |
|
| 946 |
function constructors.finalize(tfmdata) |
| 947 |
if tfmdata.properties and tfmdata.properties.finalized then |
| 948 |
return |
| 949 |
end |
| 950 |
-- |
| 951 |
if not tfmdata.characters then |
| 952 |
return nil |
| 953 |
end |
| 954 |
-- |
| 955 |
if not tfmdata.goodies then |
| 956 |
tfmdata.goodies = { } -- context specific |
| 957 |
end |
| 958 |
-- |
| 959 |
local parameters = tfmdata.parameters |
| 960 |
if not parameters then |
| 961 |
return nil |
| 962 |
end |
| 963 |
-- |
| 964 |
if not parameters.expansion then |
| 965 |
parameters.expansion = { |
| 966 |
stretch = tfmdata.stretch or 0, |
| 967 |
shrink = tfmdata.shrink or 0, |
| 968 |
step = tfmdata.step or 0, |
| 969 |
} |
| 970 |
end |
| 971 |
-- |
| 972 |
if not parameters.size then |
| 973 |
parameters.size = tfmdata.size |
| 974 |
end |
| 975 |
-- |
| 976 |
if not parameters.mode then |
| 977 |
parameters.mode = 0 |
| 978 |
end |
| 979 |
-- |
| 980 |
if not parameters.width then |
| 981 |
parameters.width = 0 |
| 982 |
end |
| 983 |
-- |
| 984 |
if not parameters.slantfactor then |
| 985 |
parameters.slantfactor = (tfmdata.slant or 0)/1000 |
| 986 |
end |
| 987 |
-- |
| 988 |
if not parameters.extendfactor then |
| 989 |
parameters.extendfactor = (tfmdata.extend or 1000)/1000 |
| 990 |
end |
| 991 |
-- |
| 992 |
if not parameters.squeezefactor then |
| 993 |
parameters.squeezefactor = (tfmdata.squeeze or 1000)/1000 |
| 994 |
end |
| 995 |
-- |
| 996 |
local designsize = parameters.designsize |
| 997 |
if designsize then |
| 998 |
parameters.minsize = tfmdata.minsize or designsize |
| 999 |
parameters.maxsize = tfmdata.maxsize or designsize |
| 1000 |
else |
| 1001 |
designsize = factors.pt * 10 |
| 1002 |
parameters.designsize = designsize |
| 1003 |
parameters.minsize = designsize |
| 1004 |
parameters.maxsize = designsize |
| 1005 |
end |
| 1006 |
parameters.minsize = tfmdata.minsize or parameters.designsize |
| 1007 |
parameters.maxsize = tfmdata.maxsize or parameters.designsize |
| 1008 |
-- |
| 1009 |
if not parameters.units then |
| 1010 |
parameters.units = tfmdata.units or tfmdata.units_per_em or 1000 |
| 1011 |
end |
| 1012 |
-- |
| 1013 |
if not tfmdata.descriptions then |
| 1014 |
local descriptions = { } -- yes or no |
| 1015 |
setmetatableindex(descriptions, function(t,k) local v = { } t[k] = v return v end) |
| 1016 |
tfmdata.descriptions = descriptions |
| 1017 |
end |
| 1018 |
-- |
| 1019 |
local properties = tfmdata.properties |
| 1020 |
if not properties then |
| 1021 |
properties = { } |
| 1022 |
tfmdata.properties = properties |
| 1023 |
end |
| 1024 |
-- |
| 1025 |
if not properties.virtualized then |
| 1026 |
properties.virtualized = tfmdata.type == "virtual" |
| 1027 |
end |
| 1028 |
-- |
| 1029 |
properties.fontname = properties.fontname or tfmdata.fontname |
| 1030 |
properties.filename = properties.filename or tfmdata.filename |
| 1031 |
properties.fullname = properties.fullname or tfmdata.fullname |
| 1032 |
properties.name = properties.name or tfmdata.name |
| 1033 |
properties.psname = properties.psname or tfmdata.psname |
| 1034 |
-- |
| 1035 |
properties.encodingbytes = tfmdata.encodingbytes or 1 |
| 1036 |
properties.subfont = tfmdata.subfont or nil |
| 1037 |
properties.embedding = tfmdata.embedding or "subset" |
| 1038 |
properties.tounicode = tfmdata.tounicode or 1 |
| 1039 |
properties.cidinfo = tfmdata.cidinfo or nil |
| 1040 |
properties.format = tfmdata.format or "type1" |
| 1041 |
properties.direction = tfmdata.direction or 0 |
| 1042 |
properties.writingmode = tfmdata.writingmode or "horizontal" |
| 1043 |
properties.identity = tfmdata.identity or "horizontal" |
| 1044 |
properties.usedbitmap = tfmdata.usedbitmap |
| 1045 |
-- |
| 1046 |
if not tfmdata.resources then |
| 1047 |
tfmdata.resources = { } |
| 1048 |
end |
| 1049 |
if not tfmdata.shared then |
| 1050 |
tfmdata.shared = { } |
| 1051 |
end |
| 1052 |
-- |
| 1053 |
-- tfmdata.fonts |
| 1054 |
-- tfmdata.unscaled |
| 1055 |
-- |
| 1056 |
if not properties.hasmath then |
| 1057 |
properties.hasmath = not tfmdata.nomath |
| 1058 |
end |
| 1059 |
-- |
| 1060 |
tfmdata.MathConstants = nil |
| 1061 |
tfmdata.postprocessors = nil |
| 1062 |
-- |
| 1063 |
tfmdata.fontname = nil |
| 1064 |
tfmdata.filename = nil |
| 1065 |
tfmdata.fullname = nil |
| 1066 |
tfmdata.name = nil -- most tricky part |
| 1067 |
tfmdata.psname = nil |
| 1068 |
-- |
| 1069 |
tfmdata.encodingbytes = nil |
| 1070 |
tfmdata.subfont = nil |
| 1071 |
tfmdata.embedding = nil |
| 1072 |
tfmdata.tounicode = nil |
| 1073 |
tfmdata.cidinfo = nil |
| 1074 |
tfmdata.format = nil |
| 1075 |
tfmdata.direction = nil |
| 1076 |
tfmdata.type = nil |
| 1077 |
tfmdata.nomath = nil |
| 1078 |
tfmdata.designsize = nil |
| 1079 |
-- |
| 1080 |
tfmdata.size = nil |
| 1081 |
tfmdata.stretch = nil |
| 1082 |
tfmdata.shrink = nil |
| 1083 |
tfmdata.step = nil |
| 1084 |
tfmdata.slant = nil |
| 1085 |
tfmdata.extend = nil |
| 1086 |
tfmdata.squeeze = nil |
| 1087 |
tfmdata.mode = nil |
| 1088 |
tfmdata.width = nil |
| 1089 |
tfmdata.units = nil |
| 1090 |
tfmdata.units_per_em = nil |
| 1091 |
-- |
| 1092 |
tfmdata.cache = nil |
| 1093 |
-- |
| 1094 |
properties.finalized = true |
| 1095 |
-- |
| 1096 |
return tfmdata |
| 1097 |
end |
| 1098 |
|
| 1099 |
-- A unique hash value is generated by: |
| 1100 |
|
| 1101 |
local hashmethods = { } |
| 1102 |
constructors.hashmethods = hashmethods |
| 1103 |
|
| 1104 |
function constructors.hashfeatures(specification) -- will be overloaded |
| 1105 |
local features = specification.features |
| 1106 |
if features then |
| 1107 |
local t, n = { }, 0 |
| 1108 |
for category, list in sortedhash(features) do |
| 1109 |
if next(list) then |
| 1110 |
local hasher = hashmethods[category] |
| 1111 |
if hasher then |
| 1112 |
local hash = hasher(list) |
| 1113 |
if hash then |
| 1114 |
n = n + 1 |
| 1115 |
t[n] = category .. ":" .. hash |
| 1116 |
end |
| 1117 |
end |
| 1118 |
end |
| 1119 |
end |
| 1120 |
if n > 0 then |
| 1121 |
return concat(t," & ") |
| 1122 |
end |
| 1123 |
end |
| 1124 |
return "unknown" |
| 1125 |
end |
| 1126 |
|
| 1127 |
hashmethods.normal = function(list) |
| 1128 |
local s = { } |
| 1129 |
local n = 0 |
| 1130 |
for k, v in next, list do |
| 1131 |
if not k then |
| 1132 |
-- no need to add to hash |
| 1133 |
elseif k == "number" or k == "features" then |
| 1134 |
-- no need to add to hash (maybe we need a skip list) |
| 1135 |
else |
| 1136 |
n = n + 1 |
| 1137 |
if type(v) == "table" then |
| 1138 |
-- table.sequenced |
| 1139 |
local t = { } |
| 1140 |
local m = 0 |
| 1141 |
for k, v in next, v do |
| 1142 |
m = m + 1 |
| 1143 |
t[m] = k .. '=' .. tostring(v) |
| 1144 |
end |
| 1145 |
sort(t) |
| 1146 |
s[n] = k .. '={' .. concat(t,",") .. "}" |
| 1147 |
else |
| 1148 |
s[n] = k .. '=' .. tostring(v) |
| 1149 |
end |
| 1150 |
end |
| 1151 |
end |
| 1152 |
if n > 0 then |
| 1153 |
sort(s) |
| 1154 |
return concat(s,"+") |
| 1155 |
end |
| 1156 |
end |
| 1157 |
|
| 1158 |
-- In principle we can share tfm tables when we are in need for a font, but then we |
| 1159 |
-- need to define a font switch as an id/attr switch which is no fun, so in that |
| 1160 |
-- case users can best use dynamic features ... so, we will not use that speedup. |
| 1161 |
-- Okay, when we get rid of base mode we can optimize even further by sharing, but |
| 1162 |
-- then we loose our testcases for LuaTeX. |
| 1163 |
|
| 1164 |
function constructors.hashinstance(specification,force) |
| 1165 |
local hash = specification.hash |
| 1166 |
local size = specification.size |
| 1167 |
local fallbacks = specification.fallbacks |
| 1168 |
if force or not hash then |
| 1169 |
hash = constructors.hashfeatures(specification) |
| 1170 |
specification.hash = hash |
| 1171 |
end |
| 1172 |
if size < 1000 and designsizes[hash] then |
| 1173 |
size = round(constructors.scaled(size,designsizes[hash])) |
| 1174 |
else |
| 1175 |
size = round(size) |
| 1176 |
end |
| 1177 |
specification.size = size |
| 1178 |
if fallbacks then |
| 1179 |
return hash .. ' @ ' .. size .. ' @ ' .. fallbacks |
| 1180 |
else |
| 1181 |
return hash .. ' @ ' .. size |
| 1182 |
end |
| 1183 |
end |
| 1184 |
|
| 1185 |
function constructors.setname(tfmdata,specification) -- todo: get specification from tfmdata |
| 1186 |
if constructors.namemode == "specification" then |
| 1187 |
-- not to be used in context ! |
| 1188 |
local specname = specification.specification |
| 1189 |
if specname then |
| 1190 |
tfmdata.properties.name = specname |
| 1191 |
if trace_defining then |
| 1192 |
report_otf("overloaded fontname %a",specname) |
| 1193 |
end |
| 1194 |
end |
| 1195 |
end |
| 1196 |
end |
| 1197 |
|
| 1198 |
function constructors.checkedfilename(data) |
| 1199 |
local foundfilename = data.foundfilename |
| 1200 |
if not foundfilename then |
| 1201 |
local askedfilename = data.filename or "" |
| 1202 |
if askedfilename ~= "" then |
| 1203 |
askedfilename = resolvers.resolve(askedfilename) -- no shortcut |
| 1204 |
foundfilename = resolvers.findbinfile(askedfilename,"") or "" |
| 1205 |
if foundfilename == "" then |
| 1206 |
report_defining("source file %a is not found",askedfilename) |
| 1207 |
foundfilename = resolvers.findbinfile(file.basename(askedfilename),"") or "" |
| 1208 |
if foundfilename ~= "" then |
| 1209 |
report_defining("using source file %a due to cache mismatch",foundfilename) |
| 1210 |
end |
| 1211 |
end |
| 1212 |
end |
| 1213 |
data.foundfilename = foundfilename |
| 1214 |
end |
| 1215 |
return foundfilename |
| 1216 |
end |
| 1217 |
|
| 1218 |
local formats = allocate() |
| 1219 |
fonts.formats = formats |
| 1220 |
|
| 1221 |
setmetatableindex(formats, function(t,k) |
| 1222 |
local l = lower(k) |
| 1223 |
if rawget(t,k) then |
| 1224 |
t[k] = l |
| 1225 |
return l |
| 1226 |
end |
| 1227 |
return rawget(t,file.suffix(l)) |
| 1228 |
end) |
| 1229 |
|
| 1230 |
do |
| 1231 |
|
| 1232 |
local function setindeed(mode,source,target,group,name,position) |
| 1233 |
local action = source[mode] |
| 1234 |
if not action then |
| 1235 |
return |
| 1236 |
end |
| 1237 |
local t = target[mode] |
| 1238 |
if not t then |
| 1239 |
report_defining("fatal error in setting feature %a, group %a, mode %a",name,group,mode) |
| 1240 |
os.exit() |
| 1241 |
elseif position then |
| 1242 |
-- todo: remove existing |
| 1243 |
insert(t, position, { name = name, action = action }) |
| 1244 |
else |
| 1245 |
for i=1,#t do |
| 1246 |
local ti = t[i] |
| 1247 |
if ti.name == name then |
| 1248 |
ti.action = action |
| 1249 |
return |
| 1250 |
end |
| 1251 |
end |
| 1252 |
insert(t, { name = name, action = action }) |
| 1253 |
end |
| 1254 |
end |
| 1255 |
|
| 1256 |
local function set(group,name,target,source) |
| 1257 |
target = target[group] |
| 1258 |
if not target then |
| 1259 |
report_defining("fatal target error in setting feature %a, group %a",name,group) |
| 1260 |
os.exit() |
| 1261 |
end |
| 1262 |
local source = source[group] |
| 1263 |
if not source then |
| 1264 |
report_defining("fatal source error in setting feature %a, group %a",name,group) |
| 1265 |
os.exit() |
| 1266 |
end |
| 1267 |
local position = source.position |
| 1268 |
setindeed("node",source,target,group,name,position) |
| 1269 |
setindeed("base",source,target,group,name,position) |
| 1270 |
setindeed("plug",source,target,group,name,position) |
| 1271 |
end |
| 1272 |
|
| 1273 |
local function register(where,specification) |
| 1274 |
local name = specification.name |
| 1275 |
if name and name ~= "" then |
| 1276 |
local default = specification.default |
| 1277 |
local description = specification.description |
| 1278 |
local initializers = specification.initializers |
| 1279 |
local processors = specification.processors |
| 1280 |
local manipulators = specification.manipulators |
| 1281 |
local modechecker = specification.modechecker |
| 1282 |
if default then |
| 1283 |
where.defaults[name] = default |
| 1284 |
end |
| 1285 |
if description and description ~= "" then |
| 1286 |
where.descriptions[name] = description |
| 1287 |
end |
| 1288 |
if initializers then |
| 1289 |
set('initializers',name,where,specification) |
| 1290 |
end |
| 1291 |
if processors then |
| 1292 |
set('processors', name,where,specification) |
| 1293 |
end |
| 1294 |
if manipulators then |
| 1295 |
set('manipulators',name,where,specification) |
| 1296 |
end |
| 1297 |
if modechecker then |
| 1298 |
where.modechecker = modechecker |
| 1299 |
end |
| 1300 |
end |
| 1301 |
end |
| 1302 |
|
| 1303 |
constructors.registerfeature = register |
| 1304 |
|
| 1305 |
function constructors.getfeatureaction(what,where,mode,name) |
| 1306 |
what = handlers[what].features |
| 1307 |
if what then |
| 1308 |
where = what[where] |
| 1309 |
if where then |
| 1310 |
mode = where[mode] |
| 1311 |
if mode then |
| 1312 |
for i=1,#mode do |
| 1313 |
local m = mode[i] |
| 1314 |
if m.name == name then |
| 1315 |
return m.action |
| 1316 |
end |
| 1317 |
end |
| 1318 |
end |
| 1319 |
end |
| 1320 |
end |
| 1321 |
end |
| 1322 |
|
| 1323 |
local newfeatures = { } |
| 1324 |
constructors.newfeatures = newfeatures -- downward compatible |
| 1325 |
constructors.features = newfeatures |
| 1326 |
|
| 1327 |
local function setnewfeatures(what) |
| 1328 |
local handler = handlers[what] |
| 1329 |
local features = handler.features |
| 1330 |
if not features then |
| 1331 |
local tables = handler.tables -- can be preloaded |
| 1332 |
local statistics = handler.statistics -- can be preloaded |
| 1333 |
features = allocate { |
| 1334 |
defaults = { }, |
| 1335 |
descriptions = tables and tables.features or { }, |
| 1336 |
used = statistics and statistics.usedfeatures or { }, |
| 1337 |
initializers = { base = { }, node = { }, plug = { } }, |
| 1338 |
processors = { base = { }, node = { }, plug = { } }, |
| 1339 |
manipulators = { base = { }, node = { }, plug = { } }, |
| 1340 |
} |
| 1341 |
features.register = function(specification) return register(features,specification) end |
| 1342 |
handler.features = features -- will also become hidden |
| 1343 |
end |
| 1344 |
return features |
| 1345 |
end |
| 1346 |
|
| 1347 |
setmetatable(newfeatures, { |
| 1348 |
__call = function(t,k) local v = t[k] return v end, |
| 1349 |
__index = function(t,k) local v = setnewfeatures(k) t[k] = v return v end, |
| 1350 |
}) |
| 1351 |
|
| 1352 |
end |
| 1353 |
|
| 1354 |
do |
| 1355 |
|
| 1356 |
local newhandler = { } |
| 1357 |
constructors.handlers = newhandler -- downward compatible |
| 1358 |
constructors.newhandler = newhandler |
| 1359 |
|
| 1360 |
local function setnewhandler(what) -- could be a metatable newindex |
| 1361 |
local handler = handlers[what] |
| 1362 |
if not handler then |
| 1363 |
handler = { } |
| 1364 |
handlers[what] = handler |
| 1365 |
end |
| 1366 |
return handler |
| 1367 |
end |
| 1368 |
|
| 1369 |
setmetatable(newhandler, { |
| 1370 |
__call = function(t,k) local v = t[k] return v end, |
| 1371 |
__index = function(t,k) local v = setnewhandler(k) t[k] = v return v end, |
| 1372 |
}) |
| 1373 |
|
| 1374 |
end |
| 1375 |
|
| 1376 |
do |
| 1377 |
-- a pitty that we need to be generic as we have nicer mechanisms for this ... |
| 1378 |
|
| 1379 |
local newenhancer = { } |
| 1380 |
constructors.enhancers = newenhancer |
| 1381 |
constructors.newenhancer = newenhancer |
| 1382 |
|
| 1383 |
local function setnewenhancer(format) |
| 1384 |
|
| 1385 |
local handler = handlers[format] |
| 1386 |
local enhancers = handler.enhancers |
| 1387 |
|
| 1388 |
if not enhancers then |
| 1389 |
|
| 1390 |
local actions = allocate() -- no need to allocate thee |
| 1391 |
local before = allocate() |
| 1392 |
local after = allocate() |
| 1393 |
local order = allocate() |
| 1394 |
local known = { } |
| 1395 |
local nofsteps = 0 |
| 1396 |
local patches = { before = before, after = after } |
| 1397 |
|
| 1398 |
local trace = false |
| 1399 |
local report = logs.reporter("fonts",format .. " enhancing") |
| 1400 |
|
| 1401 |
trackers.register(format .. ".loading", function(v) trace = v end) |
| 1402 |
|
| 1403 |
local function enhance(name,data,filename,raw) |
| 1404 |
local enhancer = actions[name] |
| 1405 |
if enhancer then |
| 1406 |
if trace then |
| 1407 |
report("apply enhancement %a to file %a",name,filename) |
| 1408 |
ioflush() |
| 1409 |
end |
| 1410 |
enhancer(data,filename,raw) |
| 1411 |
else |
| 1412 |
-- no message as we can have private ones |
| 1413 |
end |
| 1414 |
end |
| 1415 |
|
| 1416 |
local function apply(data,filename,raw) |
| 1417 |
local basename = file.basename(lower(filename)) |
| 1418 |
if trace then |
| 1419 |
report("%s enhancing file %a","start",filename) |
| 1420 |
end |
| 1421 |
ioflush() -- we want instant messages |
| 1422 |
for e=1,nofsteps do |
| 1423 |
local enhancer = order[e] |
| 1424 |
local b = before[enhancer] |
| 1425 |
if b then |
| 1426 |
for pattern, action in next, b do |
| 1427 |
if find(basename,pattern) then |
| 1428 |
action(data,filename,raw) |
| 1429 |
end |
| 1430 |
end |
| 1431 |
end |
| 1432 |
enhance(enhancer,data,filename,raw) -- we have one installed: check extra features |
| 1433 |
local a = after[enhancer] |
| 1434 |
if a then |
| 1435 |
for pattern, action in next, a do |
| 1436 |
if find(basename,pattern) then |
| 1437 |
action(data,filename,raw) |
| 1438 |
end |
| 1439 |
end |
| 1440 |
end |
| 1441 |
ioflush() -- we want instant messages |
| 1442 |
end |
| 1443 |
if trace then |
| 1444 |
report("%s enhancing file %a","stop",filename) |
| 1445 |
end |
| 1446 |
ioflush() -- we want instant messages |
| 1447 |
end |
| 1448 |
|
| 1449 |
local function register(what,action) |
| 1450 |
if action then |
| 1451 |
if actions[what] then |
| 1452 |
-- overloading, e.g."check extra features" |
| 1453 |
else |
| 1454 |
nofsteps = nofsteps + 1 |
| 1455 |
order[nofsteps] = what |
| 1456 |
known[what] = nofsteps |
| 1457 |
end |
| 1458 |
actions[what] = action |
| 1459 |
else |
| 1460 |
report("bad enhancer %a",what) |
| 1461 |
end |
| 1462 |
end |
| 1463 |
|
| 1464 |
-- We used to have a lot of enhancers but no longer with the new font loader. The order of enhancers |
| 1465 |
-- is the order of definition. The before/after patches are there for old times sake and happen |
| 1466 |
-- before or after a (named) enhancer. An example of a set enhancer is "check extra features" so one |
| 1467 |
-- one set patches before or after that is applied. Unknown enhancers are auto-registered. It's a bit |
| 1468 |
-- messy but we keep it for compatibility reasons. |
| 1469 |
-- |
| 1470 |
-- fonts.handlers.otf.enhancers.patches.register("before","some patches","somefont",function(data,filename) |
| 1471 |
-- print("!!!!!!!") -- before | after |
| 1472 |
-- end) |
| 1473 |
-- |
| 1474 |
-- fonts.handlers.otf.enhancers.register("more patches",function(data,filename) |
| 1475 |
-- print("???????") -- enhance |
| 1476 |
-- end) |
| 1477 |
|
| 1478 |
local function patch(what,where,pattern,action) |
| 1479 |
local pw = patches[what] |
| 1480 |
if pw then |
| 1481 |
local ww = pw[where] |
| 1482 |
if ww then |
| 1483 |
ww[pattern] = action |
| 1484 |
else |
| 1485 |
pw[where] = { [pattern] = action } |
| 1486 |
if not known[where] then |
| 1487 |
nofsteps = nofsteps + 1 |
| 1488 |
order[nofsteps] = where |
| 1489 |
known[where] = nofsteps |
| 1490 |
end |
| 1491 |
end |
| 1492 |
end |
| 1493 |
end |
| 1494 |
|
| 1495 |
enhancers = { |
| 1496 |
register = register, |
| 1497 |
apply = apply, |
| 1498 |
patch = patch, |
| 1499 |
report = report, |
| 1500 |
patches = { |
| 1501 |
register = patch, |
| 1502 |
report = report, |
| 1503 |
}, -- for old times sake |
| 1504 |
} |
| 1505 |
|
| 1506 |
handler.enhancers = enhancers |
| 1507 |
end |
| 1508 |
return enhancers |
| 1509 |
end |
| 1510 |
|
| 1511 |
setmetatable(newenhancer, { |
| 1512 |
__call = function(t,k) local v = t[k] return v end, |
| 1513 |
__index = function(t,k) local v = setnewenhancer(k) t[k] = v return v end, |
| 1514 |
}) |
| 1515 |
|
| 1516 |
end |
| 1517 |
|
| 1518 |
-- We need to check for default features. For this we provide a helper function. |
| 1519 |
|
| 1520 |
function constructors.checkedfeatures(what,features) |
| 1521 |
local defaults = handlers[what].features.defaults |
| 1522 |
if features and next(features) then |
| 1523 |
features = fastcopy(features) -- can be inherited (mt) but then no loops possible |
| 1524 |
for key, value in next, defaults do |
| 1525 |
if features[key] == nil then |
| 1526 |
features[key] = value |
| 1527 |
end |
| 1528 |
end |
| 1529 |
return features |
| 1530 |
else |
| 1531 |
return fastcopy(defaults) -- we can change features in place |
| 1532 |
end |
| 1533 |
end |
| 1534 |
|
| 1535 |
-- before scaling |
| 1536 |
|
| 1537 |
function constructors.initializefeatures(what,tfmdata,features,trace,report) |
| 1538 |
if features and next(features) then |
| 1539 |
local properties = tfmdata.properties or { } -- brrr |
| 1540 |
local whathandler = handlers[what] |
| 1541 |
local whatfeatures = whathandler.features |
| 1542 |
local whatmodechecker = whatfeatures.modechecker |
| 1543 |
-- properties.mode can be enforces (for instance in font-otd) |
| 1544 |
local mode = properties.mode or (whatmodechecker and whatmodechecker(tfmdata,features,features.mode)) or features.mode or "base" |
| 1545 |
properties.mode = mode -- also status |
| 1546 |
features.mode = mode -- both properties.mode or features.mode can be changed |
| 1547 |
-- |
| 1548 |
local done = { } |
| 1549 |
while true do |
| 1550 |
local redo = false |
| 1551 |
local initializers = whatfeatures.initializers[mode] |
| 1552 |
if initializers then |
| 1553 |
for i=1,#initializers do |
| 1554 |
local step = initializers[i] |
| 1555 |
local feature = step.name |
| 1556 |
-- we could intercept mode here .. needs a rewrite of this whole loop then but it's cleaner that way |
| 1557 |
local value = features[feature] |
| 1558 |
if not value then |
| 1559 |
-- disabled |
| 1560 |
elseif done[feature] then |
| 1561 |
-- already done |
| 1562 |
else |
| 1563 |
local action = step.action |
| 1564 |
if trace then |
| 1565 |
report("initializing feature %a to %a for mode %a for font %a",feature, |
| 1566 |
value,mode,tfmdata.properties.fullname) |
| 1567 |
end |
| 1568 |
action(tfmdata,value,features) -- can set mode (e.g. goodies) so it can trigger a restart |
| 1569 |
if mode ~= properties.mode or mode ~= features.mode then |
| 1570 |
if whatmodechecker then |
| 1571 |
properties.mode = whatmodechecker(tfmdata,features,properties.mode) -- force checking |
| 1572 |
features.mode = properties.mode |
| 1573 |
end |
| 1574 |
if mode ~= properties.mode then |
| 1575 |
mode = properties.mode |
| 1576 |
redo = true |
| 1577 |
end |
| 1578 |
end |
| 1579 |
done[feature] = true |
| 1580 |
end |
| 1581 |
if redo then |
| 1582 |
break |
| 1583 |
end |
| 1584 |
end |
| 1585 |
if not redo then |
| 1586 |
break |
| 1587 |
end |
| 1588 |
else |
| 1589 |
break |
| 1590 |
end |
| 1591 |
end |
| 1592 |
properties.mode = mode -- to be sure |
| 1593 |
return true |
| 1594 |
else |
| 1595 |
return false |
| 1596 |
end |
| 1597 |
end |
| 1598 |
|
| 1599 |
-- while typesetting |
| 1600 |
|
| 1601 |
function constructors.collectprocessors(what,tfmdata,features,trace,report) |
| 1602 |
local processes = { } |
| 1603 |
local nofprocesses = 0 |
| 1604 |
if features and next(features) then |
| 1605 |
local properties = tfmdata.properties |
| 1606 |
local whathandler = handlers[what] |
| 1607 |
local whatfeatures = whathandler.features |
| 1608 |
local whatprocessors = whatfeatures.processors |
| 1609 |
local mode = properties.mode |
| 1610 |
local processors = whatprocessors[mode] |
| 1611 |
if processors then |
| 1612 |
for i=1,#processors do |
| 1613 |
local step = processors[i] |
| 1614 |
local feature = step.name |
| 1615 |
if features[feature] then |
| 1616 |
local action = step.action |
| 1617 |
if trace then |
| 1618 |
report("installing feature processor %a for mode %a for font %a",feature,mode,tfmdata.properties.fullname) |
| 1619 |
end |
| 1620 |
if action then |
| 1621 |
nofprocesses = nofprocesses + 1 |
| 1622 |
processes[nofprocesses] = action |
| 1623 |
end |
| 1624 |
end |
| 1625 |
end |
| 1626 |
elseif trace then |
| 1627 |
report("no feature processors for mode %a for font %a",mode,properties.fullname) |
| 1628 |
end |
| 1629 |
end |
| 1630 |
return processes |
| 1631 |
end |
| 1632 |
|
| 1633 |
-- after scaling |
| 1634 |
|
| 1635 |
function constructors.applymanipulators(what,tfmdata,features,trace,report) |
| 1636 |
if features and next(features) then |
| 1637 |
local properties = tfmdata.properties |
| 1638 |
local whathandler = handlers[what] |
| 1639 |
local whatfeatures = whathandler.features |
| 1640 |
local whatmanipulators = whatfeatures.manipulators |
| 1641 |
local mode = properties.mode |
| 1642 |
local manipulators = whatmanipulators[mode] |
| 1643 |
if manipulators then |
| 1644 |
for i=1,#manipulators do |
| 1645 |
local step = manipulators[i] |
| 1646 |
local feature = step.name |
| 1647 |
local value = features[feature] |
| 1648 |
if value then |
| 1649 |
local action = step.action |
| 1650 |
if trace then |
| 1651 |
report("applying feature manipulator %a for mode %a for font %a",feature,mode,properties.fullname) |
| 1652 |
end |
| 1653 |
if action then |
| 1654 |
action(tfmdata,feature,value) |
| 1655 |
end |
| 1656 |
end |
| 1657 |
end |
| 1658 |
end |
| 1659 |
end |
| 1660 |
end |
| 1661 |
|
| 1662 |
function constructors.addcoreunicodes(unicodes) -- maybe make this a metatable if used at all |
| 1663 |
if not unicodes then |
| 1664 |
unicodes = { } |
| 1665 |
end |
| 1666 |
unicodes.space = 0x0020 |
| 1667 |
unicodes.hyphen = 0x002D |
| 1668 |
unicodes.zwj = 0x200D |
| 1669 |
unicodes.zwnj = 0x200C |
| 1670 |
return unicodes |
| 1671 |
end |
| 1672 |
|
| 1673 |
-- -- keep for a while: old tounicode code |
| 1674 |
-- |
| 1675 |
-- if changed then |
| 1676 |
-- -- basemode hack (we try to catch missing tounicodes, e.g. needed for ssty in math cambria) |
| 1677 |
-- local c = changed[unicode] |
| 1678 |
-- if c then |
| 1679 |
-- -- local ligatures = character.ligatures -- the original ligatures (as we cannot rely on remapping) |
| 1680 |
-- description = descriptions[c] or descriptions[unicode] or character |
| 1681 |
-- character = characters[c] or character |
| 1682 |
-- index = description.index or c |
| 1683 |
-- if tounicode then |
| 1684 |
-- touni = tounicode[index] -- nb: index! |
| 1685 |
-- if not touni then -- goodie |
| 1686 |
-- local d = descriptions[unicode] or characters[unicode] |
| 1687 |
-- local i = d.index or unicode |
| 1688 |
-- touni = tounicode[i] -- nb: index! |
| 1689 |
-- end |
| 1690 |
-- end |
| 1691 |
-- -- if ligatures and not character.ligatures then |
| 1692 |
-- -- character.ligatures = ligatures -- the original targets (for now at least.. see libertine smallcaps) |
| 1693 |
-- -- end |
| 1694 |
-- else |
| 1695 |
-- description = descriptions[unicode] or character |
| 1696 |
-- index = description.index or unicode |
| 1697 |
-- if tounicode then |
| 1698 |
-- touni = tounicode[index] -- nb: index! |
| 1699 |
-- end |
| 1700 |
-- end |
| 1701 |
-- else |
| 1702 |
-- description = descriptions[unicode] or character |
| 1703 |
-- index = description.index or unicode |
| 1704 |
-- if tounicode then |
| 1705 |
-- touni = tounicode[index] -- nb: index! |
| 1706 |
-- end |
| 1707 |
-- end |