diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2011-11-09 01:50:29 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2011-11-09 01:50:29 +0200 |
commit | 674498b3ebba014a7f4e086fde3972a84e8a9770 (patch) | |
tree | a65dc792d16b7fc30f46804594ca7da3b8fd9e0b | |
parent | 767f4e426583d6b437ac1bb77361cbf08f1cf9ab (diff) | |
download | luaotfload-674498b3ebba014a7f4e086fde3972a84e8a9770.tar.gz |
Sync with ConTeXt beta 2011.11.08 19:35
-rw-r--r-- | otfl-font-con.lua | 218 | ||||
-rw-r--r-- | otfl-font-otf.lua | 21 | ||||
-rw-r--r-- | otfl-font-otn.lua | 5 | ||||
-rw-r--r-- | otfl-fonts-ext.lua | 6 |
4 files changed, 194 insertions, 56 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 diff --git a/otfl-font-otf.lua b/otfl-font-otf.lua index cab6fae..924e9a6 100644 --- a/otfl-font-otf.lua +++ b/otfl-font-otf.lua @@ -12,6 +12,8 @@ if not modules then modules = { } end modules ['font-otf'] = { -- to_table -> totable -- ascent descent +-- more checking against low level calls of functions + local utf = unicode.utf8 local utfbyte = utf.byte @@ -515,7 +517,7 @@ local mt = { } actions["prepare tables"] = function(data,filename,raw) - data.properties.italic_correction = false + data.properties.hasitalics = false end actions["add dimensions"] = function(data,filename) @@ -600,7 +602,7 @@ local function somecopy(old) -- fast one end end --- not setting italic_correction and class (when nil) during +-- not setting hasitalics and class (when nil) during -- table cronstruction can save some mem actions["prepare glyphs"] = function(data,filename,raw) @@ -844,7 +846,7 @@ actions["analyze glyphs"] = function(data,filename,raw) -- maybe integrate this local resources = data.resources local metadata = data.metadata local properties = data.properties - local italic_correction = false + local hasitalics = false local widths = { } local marks = { } for unicode, description in next, descriptions do @@ -856,7 +858,7 @@ actions["analyze glyphs"] = function(data,filename,raw) -- maybe integrate this -- skip else description.italic = italic - italic_correction = true + hasitalics = true end local width = glyph.width widths[width] = (widths[width] or 0) + 1 @@ -869,7 +871,7 @@ actions["analyze glyphs"] = function(data,filename,raw) -- maybe integrate this end end -- flag italic - properties.italic_correction = italic_correction + properties.hasitalics = hasitalics -- flag marks resources.marks = marks -- share most common width for cjk fonts @@ -1309,8 +1311,6 @@ actions["reorganize lookups"] = function(data,filename,raw) end end --- to be checked italic_correction - local function check_variants(unicode,the_variants,splitter,unicodes) local variants = the_variants.variants if variants then -- use splitter @@ -1928,9 +1928,9 @@ local function otftotfm(specification) tfmdata.shared = shared end shared.rawdata = rawdata - shared.features = features -- default + -- shared.features = features -- default shared.dynamics = { } - shared.processes = { } + -- shared.processes = { } tfmdata.changed = { } shared.features = features shared.processes = otf.setfeatures(tfmdata,features) @@ -1949,7 +1949,8 @@ local function read_from_otf(specification) tfmdata.properties.sub = specification.sub -- tfmdata = constructors.scale(tfmdata,specification) - constructors.applymanipulators("otf",tfmdata,specification.features.normal,trace_features,report_otf) + local allfeatures = tfmdata.shared.features or specification.features.normal + constructors.applymanipulators("otf",tfmdata,allfeatures,trace_features,report_otf) constructors.setname(tfmdata,specification) -- only otf? fonts.loggers.register(tfmdata,file.extname(specification.filename),specification) end diff --git a/otfl-font-otn.lua b/otfl-font-otn.lua index beb3ae7..af82649 100644 --- a/otfl-font-otn.lua +++ b/otfl-font-otn.lua @@ -399,6 +399,11 @@ local function toligature(kind,lookupname,start,stop,char,markflag,discfound) -- start = start.next end end + -- we do need components in funny kerning mode but maybe I can better reconstruct then + -- as we do have the font components info available; removing components makes the + -- previous code much simpler + -- + -- flush_node_list(head.components) return head end end diff --git a/otfl-fonts-ext.lua b/otfl-fonts-ext.lua index 951afcc..d8884cc 100644 --- a/otfl-fonts-ext.lua +++ b/otfl-fonts-ext.lua @@ -29,7 +29,7 @@ local function initializeitlc(tfmdata,value) d.italic = it end end - tfmdata.properties.italic_correction = true + tfmdata.properties.hasitalics = true end end end @@ -54,7 +54,7 @@ local function initializeslant(tfmdata,value) elseif value < -1 then value = -1 end - tfmdata.parameters.slant_factor = value + tfmdata.parameters.slantfactor = value end otffeatures.register { @@ -75,7 +75,7 @@ local function initializeextend(tfmdata,value) elseif value < -10 then value = -10 end - tfmdata.parameters.extend_factor = value + tfmdata.parameters.extendfactor = value end otffeatures.register { |