diff options
Diffstat (limited to 'otfl-font-con.lua')
-rw-r--r-- | otfl-font-con.lua | 218 |
1 files changed, 175 insertions, 43 deletions
diff --git a/otfl-font-con.lua b/otfl-font-con.lua index 75d90f1..42ac8c2 100644 --- a/otfl-font-con.lua +++ b/otfl-font-con.lua @@ -7,6 +7,8 @@ if not modules then modules = { } end modules ['font-con'] = { } +-- some names of table entries will be changed (no _) + local utf = unicode.utf8 local next, tostring, rawget = next, tostring, rawget @@ -51,7 +53,104 @@ constructors.cache = containers.define("fonts", "constructors", constr constructors.privateoffset = 0xF0000 -- 0x10FFFF --- This might become an interface; +-- Some experimental helpers (handy for tracing): +-- +-- todo: extra: +-- +-- extra_space => space.extra +-- space => space.width +-- space_stretch => space.stretch +-- space_shrink => space.shrink + +-- We do keep the x-height, extra_space, space_shrink and space_stretch +-- around as these are low level official names. + +constructors.keys = { + properties = { + encodingbytes = "number", + embedding = "number", + cidinfo = { + }, + format = "string", + fontname = "string", + fullname = "string", + filename = "filename", + psname = "string", + name = "string", + virtualized = "boolean", + hasitalics = "boolean", + autoitalicamount = "basepoints", + nostackmath = "boolean", + noglyphnames = "boolean", + mode = "string", + hasmath = "boolean", + mathitalics = "boolean", + textitalics = "boolean", + finalized = "boolean", + }, + parameters = { + mathsize = "scaledpoints", + scriptpercentage = "float", + scriptscriptpercentage = "float", + units = "cardinal", + designsize = "scaledpoints", + expansion = { + stretch = "integerscale", -- might become float + shrink = "integerscale", -- might become float + step = "integerscale", -- might become float + auto = "boolean", + }, + protrusion = { + auto = "boolean", + }, + slantfactor = "float", + extendfactor = "float", + factor = "float", + hfactor = "float", + vfactor = "float", + size = "scaledpoints", + units = "scaledpoints", + scaledpoints = "scaledpoints", + slantperpoint = "scaledpoints", + spacing = { + width = "scaledpoints", + stretch = "scaledpoints", + shrink = "scaledpoints", + extra = "scaledpoints", + }, + xheight = "scaledpoints", + quad = "scaledpoints", + ascender = "scaledpoints", + descender = "scaledpoints", + synonyms = { + space = "spacing.width", + spacestretch = "spacing.stretch", + spaceshrink = "spacing.shrink", + extraspace = "spacing.extra", + x_height = "xheight", + space_stretch = "spacing.stretch", + space_shrink = "spacing.shrink", + extra_space = "spacing.extra", + em = "quad", + ex = "xheight", + slant = "slantperpoint", + }, + }, + description = { + width = "basepoints", + height = "basepoints", + depth = "basepoints", + boundingbox = { }, + }, + character = { + width = "scaledpoints", + height = "scaledpoints", + depth = "scaledpoints", + italic = "scaledpoints", + }, +} + +-- This might become an interface: local designsizes = allocate() constructors.designsizes = designsizes @@ -100,7 +199,7 @@ excessive memory usage in CJK fonts, we no longer pass the boundingbox.)</p> -- The scaler is only used for otf and afm and virtual fonts. If -- a virtual font has italic correction make sure to set the --- italic_correction flag. Some more flags will be added in +-- hasitalics flag. Some more flags will be added in -- the future. --[[ldx-- @@ -179,6 +278,29 @@ function constructors.assignmathparameters(target,original) -- simple variant, n end end +function constructors.enhanceparameters(parameters) + local xheight = parameters.x_height + local quad = parameters.quad + local space = parameters.space + local stretch = parameters.space_stretch + local shrink = parameters.space_shrink + local extra = parameters.extra_space + local slant = parameters.slant + parameters.xheight = xheight + parameters.spacestretch = stretch + parameters.spaceshrink = shrink + parameters.extraspace = extra + parameters.em = quad + parameters.ex = xheight + parameters.slantperpoint = slant + parameters.spacing = { + width = space, + stretch = stretch, + shrink = shrink, + extra = extra, + } +end + function constructors.scale(tfmdata,specification) local target = { } -- the new table -- @@ -308,17 +430,17 @@ function constructors.scale(tfmdata,specification) target.auto_protrude = protrusion.auto end -- widening - local extend_factor = parameters.extend_factor or 0 - if extend_factor ~= 0 and extend_factor ~= 1 then - hdelta = hdelta * extend_factor - target.extend = extend_factor * 1000 -- extent ? + local extendfactor = parameters.extendfactor or 0 + if extendfactor ~= 0 and extendfactor ~= 1 then + hdelta = hdelta * extendfactor + target.extend = extendfactor * 1000 -- extent ? else target.extend = 1000 -- extent ? end -- slanting - local slant_factor = parameters.slant_factor or 0 - if slant_factor ~= 0 then - target.slant = slant_factor * 1000 + local slantfactor = parameters.slantfactor or 0 + if slantfactor ~= 0 then + target.slant = slantfactor * 1000 else target.slant = 0 end @@ -330,20 +452,20 @@ function constructors.scale(tfmdata,specification) targetparameters.units = units targetparameters.scaledpoints = askedscaledpoints -- - local isvirtual = properties.virtualized or tfmdata.type == "virtual" - local hasquality = target.auto_expand or target.auto_protrude - local hasitalic = properties.italic_correction - local autoitalic = properties.auto_italic_correction - local stackmath = not properties.no_stackmath - local nonames = properties.noglyphnames - local nodemode = properties.mode == "node" + local isvirtual = properties.virtualized or tfmdata.type == "virtual" + local hasquality = target.auto_expand or target.auto_protrude + local hasitalics = properties.hasitalics + local autoitalicamount = properties.autoitalicamount + local stackmath = not properties.nostackmath + local nonames = properties.noglyphnames + local nodemode = properties.mode == "node" -- if changed and not next(changed) then changed = false end -- target.type = isvirtual and "virtual" or "real" - -- this will move to some subtable so that it is copied at once + -- target.postprocessors = tfmdata.postprocessors -- local targetslant = (parameters.slant or parameters[1] or 0) @@ -354,7 +476,7 @@ function constructors.scale(tfmdata,specification) local targetquad = (parameters.quad or parameters[6] or 0)*hdelta local targetextra_space = (parameters.extra_space or parameters[7] or 0)*hdelta -- - targetparameters.slant = targetslant + targetparameters.slant = targetslant -- slantperpoint targetparameters.space = targetspace targetparameters.space_stretch = targetspace_stretch targetparameters.space_shrink = targetspace_shrink @@ -370,11 +492,8 @@ function constructors.scale(tfmdata,specification) if descender then targetparameters.descender = delta * descender end - -- copies, might disappear - targetparameters.xheight = targetparameters.xheight or targetparameters.x_height or parameters.x_height - targetparameters.extraspace = targetparameters.extraspace or targetparameters.extra_space or parameters.extra_space - targetparameters.spacestretch = targetparameters.spacestretch or targetparameters.space_stretch or parameters.space_stretch - targetparameters.spaceshrink = targetparameters.spaceshrink or targetparameters.space_shrink or parameters.space_shrink + -- + constructors.enhanceparameters(targetparameters) -- official copies for us -- local protrusionfactor = (targetquad ~= 0 and 1000/targetquad) or 0 local scaledwidth = defaultwidth * hdelta @@ -386,14 +505,14 @@ function constructors.scale(tfmdata,specification) hdelta,vdelta,name or "noname",fullname or "nofullname",filename or "nofilename") end -- - local hasmath = (properties.has_math or next(mathparameters)) and true + local hasmath = (properties.hasmath or next(mathparameters)) and true if hasmath then if trace_defining then report_defining("math enabled for: name '%s', fullname: '%s', filename: '%s'", name or "noname",fullname or "nofullname",filename or "nofilename") end constructors.assignmathparameters(target,tfmdata) -- does scaling and whatever is needed - properties.has_math = true + properties.hasmath = true target.nomath = false target.MathConstants = target.mathparameters else @@ -401,31 +520,39 @@ function constructors.scale(tfmdata,specification) report_defining("math disabled for: name '%s', fullname: '%s', filename: '%s'", name or "noname",fullname or "nofullname",filename or "nofilename") end - properties.has_math = false + properties.hasmath = false target.nomath = true target.mathparameters = nil -- nop end -- local italickey = "italic" + -- + -- some context specific trickery (we might move this to a plug in into here + -- if hasmath then - if properties.no_mathitalics then - italickey = "italic_correction" -- context specific trickery + if properties.mathitalics then + italickey = "italic_correction" if trace_defining then report_defining("math italics disabled for: name '%s', fullname: '%s', filename: '%s'", name or "noname",fullname or "nofullname",filename or "nofilename") end end - autoitalic = false -- new + autoitalicamount = false -- new else - if properties.no_textitalics then - italickey = "italic_correction" -- context specific trickery + if properties.textitalics then + italickey = "italic_correction" if trace_defining then report_defining("text italics disabled for: name '%s', fullname: '%s', filename: '%s'", name or "noname",fullname or "nofullname",filename or "nofilename") end + if properties.delaytextitalics then + autoitalicamount = false + end end end -- + -- end of context specific trickery + -- local sharedkerns = { } -- -- we can have a dumb mode (basemode without math etc) that skips most @@ -524,13 +651,18 @@ function constructors.scale(tfmdata,specification) end end -- - if autoitalic then - local vi = description.italic or (description.boundingbox[3] - description.width + autoitalic) - if vi and vi ~= 0 then + if autoitalicamount then + local vi = description.italic + if not vi then + local vi = description.boundingbox[3] - description.width + autoitalicamount + if vi > 0 then -- < 0 indicates no overshoot or a very small auto italic + chr[italickey] = vi*hdelta + end + elseif vi ~= 0 then chr[italickey] = vi*hdelta end - elseif hasitalic then - local vi = description.italic -- or character.italic hm, already scaled ! + elseif hasitalics then + local vi = description.italic if vi and vi ~= 0 then chr[italickey] = vi*hdelta end @@ -703,12 +835,12 @@ function constructors.finalize(tfmdata) parameters.size = tfmdata.size end -- - if not parameters.extend_factor then - parameters.extend_factor = tfmdata.extend or 0 + if not parameters.extendfactor then + parameters.extendfactor = tfmdata.extend or 0 end -- - if not parameters.slant_factor then - parameters.slant_factor = tfmdata.slant or 0 + if not parameters.slantfactor then + parameters.slantfactor = tfmdata.slant or 0 end -- if not parameters.designsize then @@ -761,8 +893,8 @@ function constructors.finalize(tfmdata) -- tfmdata.fonts -- tfmdata.unscaled -- - if not properties.has_math then - properties.has_math = not tfmdata.nomath + if not properties.hasmath then + properties.hasmath = not tfmdata.nomath end -- tfmdata.MathConstants = nil @@ -1047,7 +1179,7 @@ a helper function.</p> function constructors.checkedfeatures(what,features) local defaults = handlers[what].features.defaults if features and next(features) then - features = fastcopy(features) -- can be inherited + features = fastcopy(features) -- can be inherited (mt) but then no loops possible for key, value in next, defaults do if features[key] == nil then features[key] = value |