diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2015-07-27 20:15:05 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2015-07-27 20:15:05 +0200 |
commit | 840fb4a9d8351042ac6a73a3bb1ae1146fc9cbc1 (patch) | |
tree | 18f3acde560cfe4594753af86dfa39bfde1d21ba | |
parent | 619d3b4f6f8f86d8ed2f67b6eadce948ba951aec (diff) | |
download | context-840fb4a9d8351042ac6a73a3bb1ae1146fc9cbc1.tar.gz |
2015-07-27 19:38:00
35 files changed, 863 insertions, 587 deletions
diff --git a/tex/context/base/attr-ini.mkiv b/tex/context/base/attr-ini.mkiv index 614c30da0..ffed65bd7 100644 --- a/tex/context/base/attr-ini.mkiv +++ b/tex/context/base/attr-ini.mkiv @@ -52,15 +52,17 @@ \def\attr_basics_define_system{\attr_basics_define_indeed\s!private} \def\attr_basics_define_indeed#1[#2][#3]% - {\scratchcounter\clf_defineattribute{#2}{#1}\relax - %\writestatus\m!system{defining #1 attribute #2 with number \number\scratchcounter}% - \expandafter\attributedef\csname\??attributecount#2\endcsname\scratchcounter - \expandafter\newconstant \csname\??attributeid#2\endcsname - \csname\??attributeid#2\endcsname\scratchcounter - % some attributes are always global - \doifnotinset\s!global{#3}{\appendetoks\csname\??attributecount#2\endcsname\attributeunsetvalue\to\attributesresetlist}% - % here public means 'visible' so it's not to be confused with 'public' at the lua end - \doifinset \s!public{#3}{\expandafter\let\csname#2\s!attribute\expandafter\endcsname\csname\??attributeid#2\endcsname}} + {\ifcsname\??attributecount#2\endcsname\else + \scratchcounter\clf_defineattribute{#2}{#1}\relax + %\writestatus\m!system{defining #1 attribute #2 with number \number\scratchcounter}% + \expandafter\attributedef\csname\??attributecount#2\endcsname\scratchcounter + \expandafter\newconstant \csname\??attributeid#2\endcsname + \csname\??attributeid#2\endcsname\scratchcounter + % some attributes are always global + \doifnotinset\s!global{#3}{\appendetoks\csname\??attributecount#2\endcsname\attributeunsetvalue\to\attributesresetlist}% + % here public means 'visible' so it's not to be confused with 'public' at the lua end + \doifinset \s!public{#3}{\expandafter\let\csname#2\s!attribute\expandafter\endcsname\csname\??attributeid#2\endcsname}% + \fi} \unexpanded\def\newattribute#1% {\attr_basics_define_indeed\s!public[\strippedcsname#1][]% diff --git a/tex/context/base/char-def.lua b/tex/context/base/char-def.lua index 132d007d5..9bd181fd7 100644 --- a/tex/context/base/char-def.lua +++ b/tex/context/base/char-def.lua @@ -620,11 +620,12 @@ characters.data={ adobename="colon", category="po", cjkwd="na", - comment="mathclass=punctuation,mathname=colon", + comment="mathclass=punctuation,mathname=colon,mathsymbol=0x2236", description="COLON", direction="cs", linebreak="is", mathclass="relation", +--mathsymbol=0x2236, unicodeslot=0x3A, }, { diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 27fe636b0..fcfbd2a0d 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2015.07.24 13:58} +\newcontextversion{2015.07.27 19:36} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex bfa83a42e..9e52fef87 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 73f331f2c..96484b5aa 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -39,7 +39,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2015.07.24 13:58} +\edef\contextversion{2015.07.27 19:36} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/font-con.lua b/tex/context/base/font-con.lua index 137c21e48..383a403c4 100644 --- a/tex/context/base/font-con.lua +++ b/tex/context/base/font-con.lua @@ -191,10 +191,9 @@ in the process; numbers are of course copies. Here 65536 equals 1pt. (Due to excessive memory usage in CJK fonts, we no longer pass the boundingbox.)</p> --ldx]]-- --- The scaler is only used for otf and afm and virtual fonts. If --- a virtual font has italic correction make sure to set the --- hasitalics flag. Some more flags will be added in --- the future. +-- The scaler is only used for otf and afm and virtual fonts. If a virtual font has italic +-- correction make sure to set the hasitalics flag. Some more flags will be added in the +-- future. --[[ldx-- <p>The reason why the scaler was originally split, is that for a while we experimented @@ -563,26 +562,27 @@ function constructors.scale(tfmdata,specification) target.mathparameters = nil -- nop end -- - local italickey = "italic" - local useitalics = true -- something context - -- - -- some context specific trickery (this will move to a plugin) + -- Here we support some context specific trickery (this might move to a plugin). During the + -- transition to opentype the engine had troubles with italics so we had some additional code + -- for fixing that. In node mode (text) we don't care much if italics gets passed because + -- the engine does nothign with them then. -- if hasmath then - -- the latest luatex can deal with it itself so we now disable this - -- mechanism here - -- - -- if properties.mathitalics then - -- italickey = "italic_correction" - -- if trace_defining then - -- report_defining("math italics disabled for font %a, fullname %a, filename %a",name,fullname,filename) - -- end - -- end - autoitalicamount = false -- new - elseif properties.textitalics then - italickey = "italic_correction" - useitalics = false - if properties.delaytextitalics then + local mathitalics = properties.mathitalics + if mathitalics == false then + if trace_defining then + report_defining("%s italics %s for font %a, fullname %a, filename %a","math",hasitalics and "ignored" or "disabled",name,fullname,filename) + end + hasitalics = false + autoitalicamount = false + end + else + local textitalics = properties.textitalics + if textitalics == false then + if trace_defining then + report_defining("%s italics %s for font %a, fullname %a, filename %a","text",hasitalics and "ignored" or "disabled",name,fullname,filename) + end + hasitalics = false autoitalicamount = false end end @@ -591,8 +591,7 @@ function constructors.scale(tfmdata,specification) -- if trace_defining then report_defining("defining tfm, name %a, fullname %a, filename %a, hscale %a, vscale %a, math %a, italics %a", - name,fullname,filename,hdelta,vdelta, - hasmath and "enabled" or "disabled",useitalics and "enabled" or "disabled") + name,fullname,filename,hdelta,vdelta,hasmath and "enabled" or "disabled",hasitalics and "enabled" or "disabled") end -- constructors.beforecopyingcharacters(target,tfmdata) @@ -607,15 +606,15 @@ function constructors.scale(tfmdata,specification) local c = changed[unicode] if c then description = descriptions[c] or descriptions[unicode] or character - character = characters[c] or character - index = description.index or c + character = characters[c] or character + index = description.index or c else description = descriptions[unicode] or character - index = description.index or unicode + index = description.index or unicode end else description = descriptions[unicode] or character - index = description.index or unicode + index = description.index or unicode end local width = description.width local height = description.height @@ -700,23 +699,6 @@ function constructors.scale(tfmdata,specification) end end -- - 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 hasitalics then - local vi = description.italic - if vi and vi ~= 0 then - chr[italickey] = vi*hdelta - end - end - -- to be tested if hasmath then -- todo, just operate on descriptions.math local vn = character.next @@ -755,7 +737,7 @@ function constructors.scale(tfmdata,specification) end end end - local va = character.top_accent + local va = character.accent if va then chr.top_accent = vdelta*va end @@ -778,6 +760,27 @@ function constructors.scale(tfmdata,specification) chr.mathkern = kerns -- singular -> should be patched in luatex ! end end + if hasitalics then + local vi = character.italic + if vi and vi ~= 0 then + chr.italic = vi*hdelta + end + end + elseif autoitalicamount then -- itlc feature + 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.italic = vi*hdelta + end + elseif vi ~= 0 then + chr.italic = vi*hdelta + end + elseif hasitalics then -- unlikely + local vi = character.italic + if vi and vi ~= 0 then + chr.italic = vi*hdelta + end end if haskerns then local vk = character.kerns @@ -844,6 +847,8 @@ function constructors.scale(tfmdata,specification) targetcharacters[unicode] = chr end -- + properties.setitalics = hasitalics -- for postprocessing + -- constructors.aftercopyingcharacters(target,tfmdata) -- constructors.trytosharefont(target,tfmdata) diff --git a/tex/context/base/font-dsp.lua b/tex/context/base/font-dsp.lua index 768ea92b3..a1a89dd3b 100644 --- a/tex/context/base/font-dsp.lua +++ b/tex/context/base/font-dsp.lua @@ -1938,8 +1938,9 @@ local function readmathglyphinfo(f,fontdata,offset) local coverage = readushort(f) local nofglyphs = readushort(f) coverage = readcoverage(f,offset+italics+coverage,true) + setposition(f,offset+italics+4) for i=1,nofglyphs do - local italic = readshort(f) + local italic = readmathvalue(f) if italic ~= 0 then local glyph = glyphs[coverage[i]] local math = glyph.math @@ -1957,8 +1958,9 @@ local function readmathglyphinfo(f,fontdata,offset) local coverage = readushort(f) local nofglyphs = readushort(f) coverage = readcoverage(f,offset+accents+coverage,true) + setposition(f,offset+accents+4) for i=1,nofglyphs do - local accent = readshort(f) + local accent = readmathvalue(f) if accent ~= 0 then local glyph = glyphs[coverage[i]] local math = glyph.math @@ -2062,7 +2064,7 @@ local function readmathvariants(f,fontdata,offset) -- advance = readushort(f), -- } - local function get(offset,coverage,nofglyphs,construction,kvariants,kparts) + local function get(offset,coverage,nofglyphs,construction,kvariants,kparts,kitalic) if coverage ~= 0 and nofglyphs > 0 then local coverage = readcoverage(f,offset+coverage,true) for i=1,nofglyphs do @@ -2100,7 +2102,7 @@ local function readmathvariants(f,fontdata,offset) end if assembly ~= 0 then setposition(f,offset + c + assembly) - local italics = readmathvalue(f) + local italic = readmathvalue(f) local nofparts = readushort(f) local parts = { } for i=1,nofparts do @@ -2117,19 +2119,24 @@ local function readmathvariants(f,fontdata,offset) parts[i] = p end if not math then - math = { [kparts] = parts } + math = { + [kparts] = parts + } glyph.math = math else math[kparts] = parts end + if italic and italic ~= 0 then + math[kitalic] = italic + end end end end end end - get(offset,vcoverage,vnofglyphs,vconstruction,"vvariants","vparts") - get(offset,hcoverage,hnofglyphs,hconstruction,"hvariants","hparts") + get(offset,vcoverage,vnofglyphs,vconstruction,"vvariants","vparts","vitalic") + get(offset,hcoverage,hnofglyphs,hconstruction,"hvariants","hparts","hitalic") end function readers.math(f,fontdata,specification) diff --git a/tex/context/base/font-ext.lua b/tex/context/base/font-ext.lua index b7817c140..f153d5624 100644 --- a/tex/context/base/font-ext.lua +++ b/tex/context/base/font-ext.lua @@ -534,8 +534,8 @@ local function initializeitlc(tfmdata,value) -- hm, always value end registerotffeature { - name = "itlc", - description = "italic correction", + name = "itlc", + description = "italic correction", initializers = { base = initializeitlc, node = initializeitlc, @@ -543,8 +543,8 @@ registerotffeature { } registerafmfeature { - name = "itlc", - description = "italic correction", + name = "itlc", + description = "italic correction", initializers = { base = initializeitlc, node = initializeitlc, @@ -552,14 +552,12 @@ registerafmfeature { } local function initializetextitalics(tfmdata,value) -- yes no delay - local delay = value == "delay" - tfmdata.properties.textitalics = delay and true or value - tfmdata.properties.delaytextitalics = delay + tfmdata.properties.textitalics = toboolean(value) end registerotffeature { - name = "textitalics", - description = "use alternative text italic correction", + name = "textitalics", + description = "use alternative text italic correction", initializers = { base = initializetextitalics, node = initializetextitalics, @@ -567,14 +565,36 @@ registerotffeature { } registerafmfeature { - name = "textitalics", - description = "use alternative text italic correction", + name = "textitalics", + description = "use alternative text italic correction", initializers = { base = initializetextitalics, node = initializetextitalics, } } +local function initializemathitalics(tfmdata,value) -- yes no delay + tfmdata.properties.mathitalics = toboolean(value) +end + +registerotffeature { + name = "mathitalics", + description = "use alternative math italic correction", + initializers = { + base = initializemathitalics, + node = initializemathitalics, + } +} + +registerafmfeature { + name = "mathitalics", + description = "use alternative math italic correction", + initializers = { + base = initializemathitalics, + node = initializemathitalics, + } +} + -- slanting local function initializeslant(tfmdata,value) diff --git a/tex/context/base/font-gds.lua b/tex/context/base/font-gds.lua index 4daafd154..7e53ef049 100644 --- a/tex/context/base/font-gds.lua +++ b/tex/context/base/font-gds.lua @@ -566,8 +566,8 @@ fontgoodies.register("mathematics", initialize) -- }, -- } --- math italics - +-- math italics (not rteally needed) +-- -- it would be nice to have a \noitalics\font option local function initialize(tfmdata) @@ -579,60 +579,44 @@ local function initialize(tfmdata) local mathitalics = mathgoodies and mathgoodies.italics if mathitalics then local properties = tfmdata.properties - mathitalics = mathitalics[file.nameonly(properties.name)] or mathitalics - if mathitalics then - if trace_goodies then - report_goodies("loading mathitalics for font %a",properties.name) - end - local corrections = mathitalics.corrections - local defaultfactor = mathitalics.defaultfactor - local disableengine = mathitalics.disableengine - properties.hasitalics = true - properties.mathitalic_defaultfactor = defaultfactor -- we inherit outer one anyway (name will change) - if properties.mathitalics == nil then - properties.mathitalics = disableengine - end - if corrections then - -- As we want to set italic_correction (the context one) we need a - -- postprocessor instead of messing with the (unscaled) descriptions. - fontgoodies.registerpostprocessor(tfmdata, function(tfmdata) -- this is another tfmdata (a copy) - -- better make a helper so that we have less code being defined - local properties = tfmdata.properties - local parameters = tfmdata.parameters - local characters = tfmdata.characters - properties.hasitalics = true - properties.mathitalic_defaultfactor = defaultfactor - properties.mathitalic_defaultvalue = defaultfactor * parameters.quad - if properties.mathitalics == nil then - properties.mathitalics = disableengine - end - if trace_goodies then - report_goodies("assigning mathitalics for font %a",properties.name) - end - local mathitalics = properties.mathitalics - local quad = parameters.quad - local hfactor = parameters.hfactor - for k, v in next, corrections do - local c = characters[k] - if c then - if v > -1 and v < 1 then - v = v * quad - else - v = v * hfactor - end - c.italic_correction = v -- for context - if mathitalics then - c.italic = v -- for tex + if properties.setitalics then + mathitalics = mathitalics[file.nameonly(properties.name)] or mathitalics + if mathitalics then + if trace_goodies then + report_goodies("loading mathitalics for font %a",properties.name) + end + local corrections = mathitalics.corrections + local defaultfactor = mathitalics.defaultfactor + -- properties.mathitalic_defaultfactor = defaultfactor -- we inherit outer one anyway (name will change) + if corrections then + fontgoodies.registerpostprocessor(tfmdata, function(tfmdata) -- this is another tfmdata (a copy) + -- better make a helper so that we have less code being defined + local properties = tfmdata.properties + local parameters = tfmdata.parameters + local characters = tfmdata.characters + properties.mathitalic_defaultfactor = defaultfactor + properties.mathitalic_defaultvalue = defaultfactor * parameters.quad + if trace_goodies then + report_goodies("assigning mathitalics for font %a",properties.name) + end + local quad = parameters.quad + local hfactor = parameters.hfactor + for k, v in next, corrections do + local c = characters[k] + if c then + if v > -1 and v < 1 then + c.italic = v * quad + else + c.italic = v * hfactor + end else - c.italic = nil + report_goodies("invalid mathitalics entry %U for font %a",k,properties.name) end - else - report_goodies("invalid mathitalics entry %U for font %a",k,properties.name) end - end - end) + end) + end + return -- maybe not as these can accumulate end - return -- maybe not as these can accumulate end end end diff --git a/tex/context/base/font-mis.lua b/tex/context/base/font-mis.lua index 931c755fd..8219cd234 100644 --- a/tex/context/base/font-mis.lua +++ b/tex/context/base/font-mis.lua @@ -22,7 +22,7 @@ local handlers = fonts.handlers handlers.otf = handlers.otf or { } local otf = handlers.otf -otf.version = otf.version or 2.817 +otf.version = otf.version or 2.818 otf.cache = otf.cache or containers.define("fonts", "otf", otf.version, true) local fontloader = fontloader diff --git a/tex/context/base/font-mps.lua b/tex/context/base/font-mps.lua index 5095c4f79..591f5d323 100644 --- a/tex/context/base/font-mps.lua +++ b/tex/context/base/font-mps.lua @@ -276,15 +276,15 @@ local fc = number.dimenfactors.bp * sc / 10 function metapost.output(kind,font,char,advance,shift,ex) local character = characters[font][char] - if char then + if character then local index = character.index if index then local shapedata = shapes[font] local glyphs = shapedata.glyphs -- todo: subfonts fonts.shapes.indexed(font,sub) if glyphs then - local glyf = data.glyphs[index] + local glyf = glyphs[index] if glyf then - local units = data.fontheader and data.fontheader.units or data.units or 1000 + local units = shapedata.units or 1000 local yfactor = sc/units local xfactor = yfactor local shift = shift or 0 diff --git a/tex/context/base/font-otf.lua b/tex/context/base/font-otf.lua index 204357ab5..79d3ac60d 100644 --- a/tex/context/base/font-otf.lua +++ b/tex/context/base/font-otf.lua @@ -58,7 +58,7 @@ local otf = fonts.handlers.otf otf.glists = { "gsub", "gpos" } -otf.version = 2.817 -- beware: also sync font-mis.lua and in mtx-fonts +otf.version = 2.818 -- beware: also sync font-mis.lua and in mtx-fonts otf.cache = containers.define("fonts", "otf", otf.version, true) local hashes = fonts.hashes @@ -1119,16 +1119,16 @@ end -- boundingbox: split into ht/dp takes more memory (larger tables and less sharing) actions["analyze glyphs"] = function(data,filename,raw) -- maybe integrate this in the previous - local descriptions = data.descriptions - local resources = data.resources - local metadata = data.metadata - local properties = data.properties - local hasitalics = false - local widths = { } - local marks = { } -- always present (saves checking) + local descriptions = data.descriptions + local resources = data.resources + local metadata = data.metadata + local properties = data.properties + local hasitalics = false + local widths = { } + local marks = { } -- always present (saves checking) for unicode, description in next, descriptions do - local glyph = description.glyph - local italic = glyph.italic_correction -- only in a math font + local glyph = description.glyph + local italic = glyph.italic_correction -- only in a math font (we also have vert/horiz) if not italic then -- skip elseif italic == 0 then @@ -1883,11 +1883,11 @@ local function check_variants(unicode,the_variants,splitter,unicodes) parts = nil end end - local italic_correction = the_variants.italic_correction - if italic_correction and italic_correction == 0 then - italic_correction = nil + local italic = the_variants.italic + if italic and italic == 0 then + italic = nil end - return variants, parts, italic_correction + return variants, parts, italic end actions["analyze math"] = function(data,filename,raw) @@ -1896,15 +1896,16 @@ actions["analyze math"] = function(data,filename,raw) local unicodes = data.resources.unicodes local splitter = data.helpers.tounicodetable for unicode, description in next, data.descriptions do - local glyph = description.glyph - local mathkerns = glyph.mathkern -- singular - local horiz_variants = glyph.horiz_variants - local vert_variants = glyph.vert_variants - local top_accent = glyph.top_accent - if mathkerns or horiz_variants or vert_variants or top_accent then + local glyph = description.glyph + local mathkerns = glyph.mathkern -- singular + local hvariants = glyph.horiz_variants + local vvariants = glyph.vert_variants + local accent = glyph.top_accent + local italic = glyph.italic_correction + if mathkerns or hvariants or vvariants or accent or italic then local math = { } - if top_accent then - math.top_accent = top_accent + if accent then + math.accent = accent end if mathkerns then for k, v in next, mathkerns do @@ -1920,15 +1921,14 @@ actions["analyze math"] = function(data,filename,raw) end math.kerns = mathkerns end - if horiz_variants then - math.horiz_variants, math.horiz_parts, math.horiz_italic_correction = check_variants(unicode,horiz_variants,splitter,unicodes) + if hvariants then + math.hvariants, math.hparts, math.hitalic = check_variants(unicode,hvariants,splitter,unicodes) end - if vert_variants then - math.vert_variants, math.vert_parts, math.vert_italic_correction = check_variants(unicode,vert_variants,splitter,unicodes) + if vvariants then + math.vvariants, math.vparts, math.vitalic = check_variants(unicode,vvariants,splitter,unicodes) end - local italic_correction = description.italic - if italic_correction and italic_correction ~= 0 then - math.italic_correction = italic_correction + if italic and italic ~= 0 then + math.italic = italic end description.math = math end @@ -2503,7 +2503,7 @@ end -- we cannot share descriptions as virtual fonts might extend them (ok, -- we could use a cache with a hash -- --- we already assing an empty tabel to characters as we can add for +-- we already assign an empty tabel to characters as we can add for -- instance protruding info and loop over characters; one is not supposed -- to change descriptions and if one does so one should make a copy! @@ -2551,8 +2551,11 @@ local function copytotfm(data,cache_id) local m = d.math if m then -- watch out: luatex uses horiz_variants for the parts - local variants = m.horiz_variants - local parts = m.horiz_parts + -- + local italic = m.italic + -- + local variants = m.hvariants + local parts = m.hparts -- local done = { [unicode] = true } if variants then local c = character @@ -2569,9 +2572,11 @@ local function copytotfm(data,cache_id) c.horiz_variants = parts elseif parts then character.horiz_variants = parts + italic = m.hitalic end - local variants = m.vert_variants - local parts = m.vert_parts + -- + local variants = m.vvariants + local parts = m.vparts -- local done = { [unicode] = true } if variants then local c = character @@ -2588,15 +2593,18 @@ local function copytotfm(data,cache_id) c.vert_variants = parts elseif parts then character.vert_variants = parts + italic = m.vitalic end - local italic_correction = m.vert_italic_correction - if italic_correction then - character.vert_italic_correction = italic_correction -- was c. + -- + if italic and italic ~= 0 then + character.italic = italic -- overload end - local top_accent = m.top_accent - if top_accent then - character.top_accent = top_accent + -- + local accent = m.accent + if accent then + character.accent = accent end + -- local kerns = m.kerns if kerns then character.mathkerns = kerns diff --git a/tex/context/base/font-otl.lua b/tex/context/base/font-otl.lua index f86850bf4..96775d0f0 100644 --- a/tex/context/base/font-otl.lua +++ b/tex/context/base/font-otl.lua @@ -53,7 +53,7 @@ local report_otf = logs.reporter("fonts","otf loading") local fonts = fonts local otf = fonts.handlers.otf -otf.version = 3.002 -- beware: also sync font-mis.lua and in mtx-fonts +otf.version = 3.003 -- beware: also sync font-mis.lua and in mtx-fonts otf.cache = containers.define("fonts", "otl", otf.version, true) local otfreaders = otf.readers @@ -375,6 +375,9 @@ local function copytotfm(data,cache_id) local m = d.math if m then -- watch out: luatex uses horiz_variants for the parts + -- + local italic = m.italic + -- local variants = m.hvariants local parts = m.hparts if variants then @@ -388,7 +391,9 @@ local function copytotfm(data,cache_id) c.horiz_variants = parts elseif parts then character.horiz_variants = parts + italic = m.hitalic end + -- local variants = m.vvariants local parts = m.vparts if variants then @@ -402,15 +407,18 @@ local function copytotfm(data,cache_id) c.vert_variants = parts elseif parts then character.vert_variants = parts + italic = m.vitalic end - local italic_correction = m.italic -- vitalic ? - if italic_correction then - character.vert_italic_correction = italic_correction -- was c. + -- + if italic and italic ~= 0 then + character.italic = italic end - local top_accent = m.accent -- taccent? - if top_accent then - character.top_accent = top_accent + -- + local accent = m.accent -- taccent? + if accent then + character.top_accent = accent end + -- local kerns = m.kerns if kerns then character.mathkerns = kerns @@ -436,7 +444,9 @@ local function copytotfm(data,cache_id) local charwidth = metadata.averagewidth -- or unset local charxheight = metadata.xheight -- or unset local italicangle = metadata.italicangle + local hasitalics = metadata.hasitalics properties.monospaced = monospaced + properties.hasitalics = hasitalics parameters.italicangle = italicangle parameters.charwidth = charwidth parameters.charxheight = charxheight diff --git a/tex/context/base/font-otr.lua b/tex/context/base/font-otr.lua index eb012f1d5..210aba67a 100644 --- a/tex/context/base/font-otr.lua +++ b/tex/context/base/font-otr.lua @@ -34,15 +34,6 @@ if not modules then modules = { } end modules ['font-otr'] = { -- todo: more messages (only if really needed) -- --- todo (in old loader and new one) math: --- --- italic_correction -> italic --- top_accent -> top accent --- vert_parts -> vparts --- horiz_parts -> hparts --- vert_variants -> vvariants -> next in tex, so better 'sizes' --- horiz_variants -> hvariants -> next in tex, so better 'sizes' --- -- considered, in math: -- -- start -> first (so we can skip the first same-size one) diff --git a/tex/context/base/font-pre.mkiv b/tex/context/base/font-pre.mkiv index 98498b6aa..afc427183 100644 --- a/tex/context/base/font-pre.mkiv +++ b/tex/context/base/font-pre.mkiv @@ -241,9 +241,8 @@ tlig=yes, trep=yes, mathalternates=yes, - mathitalics=yes, + mathitalics=yes, % we pass them % mathgaps=yes, - % nomathitalics=yes, % don't pass to tex, might become default language=dflt, script=math] diff --git a/tex/context/base/lpdf-ano.lua b/tex/context/base/lpdf-ano.lua index f5e320a00..9994be2df 100644 --- a/tex/context/base/lpdf-ano.lua +++ b/tex/context/base/lpdf-ano.lua @@ -1051,9 +1051,10 @@ end local function build(levels,start,parent,method,nested) local startlevel = levels[start].level + local noflevels = #levels local i, n = start, 0 local child, entry, m, prev, first, last, f, l - while i and i <= #levels do + while i and i <= noflevels do local current = levels[i] if current.usedpage == false then -- safeguard @@ -1086,19 +1087,20 @@ local function build(levels,start,parent,method,nested) if variant == "unknown" then -- error, ignore i = i + 1 - elseif level <= startlevel then - if level < startlevel then - if nested then -- could be an option but otherwise we quit too soon - if entry then - pdfflushobject(child,entry) - else - report_bookmark("error 1") - end - return i, n, first, last + elseif level < startlevel then + if nested then -- could be an option but otherwise we quit too soon + if entry then + pdfflushobject(child,entry) else - report_bookmark("confusing level change at level %a around %a",level,title) + report_bookmark("error 1") end + return i, n, first, last + else + report_bookmark("confusing level change at level %a around %a",level,title) + startlevel = level end + end + if level == startlevel then if trace_bookmarks then report_bookmark("%3i %w%s %s",reference.realpage,(level-1)*2,(opened and "+") or "-",title) end @@ -1121,12 +1123,14 @@ local function build(levels,start,parent,method,nested) A = action, } -- entry.Dest = somedestination(reference.internal,reference.internal,reference.realpage) - if not first then first, last = child, child end + if not first then + first, last = child, child + end prev = child last = prev n = n + 1 i = i + 1 - elseif i < #levels and level > startlevel then + elseif i < noflevels and level > startlevel then i, m, f, l = build(levels,i,pdfreference(child),method,true) if entry then entry.Count = (opened and m) or -m @@ -1160,6 +1164,7 @@ end function codeinjections.addbookmarks(levels,method) if levels and #levels > 0 then +-- inspect(levels) local parent = pdfreserveobject() local _, m, first, last = build(levels,1,pdfreference(parent),method or "internal",false) local dict = pdfdictionary { diff --git a/tex/context/base/math-ini.mkiv b/tex/context/base/math-ini.mkiv index 83065c6aa..d0fb0405c 100644 --- a/tex/context/base/math-ini.mkiv +++ b/tex/context/base/math-ini.mkiv @@ -261,7 +261,6 @@ \newcount \defaultrelpenalty \defaultrelpenalty 500 \newcount \defaultbinoppenalty \defaultbinoppenalty 700 - \startsetups math:spacing:default \thickmuskip \defaultthickmuskip \medmuskip \defaultmedmuskip @@ -670,8 +669,8 @@ \let\math_tags_mo\firstofoneunexpanded \let\math_tags_mi\firstofoneunexpanded -\unexpanded\def\math_tags_mn#1{\begingroup\mathupright#1\endgroup} -\unexpanded\def\math_tags_ms#1{\begingroup\mathupright#1\endgroup} +\unexpanded\def\math_tags_mn#1{\begingroup\mathupright\math_set_o_both#1\endgroup} +\unexpanded\def\math_tags_ms#1{\begingroup\mathupright\math_set_p_both#1\endgroup} % Once this is stable we can store the number at the tex end which is % faster. Functions getnumbers >= 1000. @@ -732,10 +731,10 @@ \let\math_tags_mfunctiontxt\gobbletwoarguments \let\math_tags_mfunctionlab\gobbletwoarguments -\unexpanded\def\math_tags_mo_indeed#1{\begingroup \attribute\mathcategoryattribute\plusone #1\endgroup} -\unexpanded\def\math_tags_mi_indeed#1{\begingroup \attribute\mathcategoryattribute\plustwo #1\endgroup} -\unexpanded\def\math_tags_mn_indeed#1{\begingroup\mathupright\attribute\mathcategoryattribute\plusthree#1\endgroup} -\unexpanded\def\math_tags_ms_indeed#1{\begingroup\mathupright\attribute\mathcategoryattribute\plusfour #1\endgroup} % todo: mathoptext +\unexpanded\def\math_tags_mo_indeed#1{\begingroup \attribute\mathcategoryattribute\plusone #1\endgroup} +\unexpanded\def\math_tags_mi_indeed#1{\begingroup \attribute\mathcategoryattribute\plustwo #1\endgroup} +\unexpanded\def\math_tags_mn_indeed#1{\begingroup\mathupright\attribute\mathcategoryattribute\plusthree\math_set_o_both#1\endgroup} +\unexpanded\def\math_tags_ms_indeed#1{\begingroup\mathupright\attribute\mathcategoryattribute\plusfour \math_set_p_both#1\endgroup} % todo: mathoptext \newconditional\c_apply_function @@ -1223,21 +1222,23 @@ %D Math italics (experiment) -% we need keys +%D We need keys but what names to use and because we have hardcoded solution +%D we can stick to numbers. \installcorenamespace{mathitalics} \setnewconstant\c_math_italics_attribute\attributeunsetvalue -\letvalue{\??mathitalics 1}\plusone % fontitalics -\letvalue{\??mathitalics 2}\plustwo % fontdata -\letvalue{\??mathitalics 3}\plusthree % quad based -\letvalue{\??mathitalics 4}\plusfour % combination of 1 and 3 -\letvalue{\??mathitalics\v!none}\attributeunsetvalue +\letvalue{\??mathitalics 1}\plusone % fontitalics +\letvalue{\??mathitalics 2}\plustwo % fontdata +\letvalue{\??mathitalics 3}\plusthree % quad based +\letvalue{\??mathitalics 4}\plusfour % combination of 1 and 3 +\letvalue{\??mathitalics\v!none }\attributeunsetvalue +\letvalue{\??mathitalics\v!reset}\attributeunsetvalue \def\math_italics_initialize {\ifnum\c_math_italics_attribute=\attributeunsetvalue \else - \clf_setmathitalics % one time + \clf_initializemathitalics % one time \global\let\math_italics_initialize\relax \fi} @@ -1255,7 +1256,7 @@ \to \everymathematics \setupmathematics - [\s!italics=3] % for the moment only this one makes sense .. still experimental + [\s!italics=3] % 4 is probably better % looks nicer but can generate bogus csnames % @@ -1334,17 +1335,44 @@ % to delegate to \LUA\ when we have more variants and need analysis (experimental % trickery removed for a while). -\def\math_punctuation_comma_next {\ifx\nexttoken\blankspace \mathpunct{\textcomma }\else\mathord{\textcomma }\fi} -\def\math_punctuation_period_next{\ifx\nexttoken\blankspace \mathpunct{\textperiod}\else\mathord{\textperiod}\fi} +% \def\math_punctuation_comma_next {\ifx\nexttoken\blankspace\mathpunct\else\mathord\fi{\textcomma }} +% \def\math_punctuation_period_next{\ifx\nexttoken\blankspace\mathpunct\else\mathord\fi{\textperiod}} +% +% \unexpanded\def\math_punctuation_nop_comma {\mathpunct{\textcomma}} +% \unexpanded\def\math_punctuation_nop_period{\mathord{\textperiod}} +% +% \unexpanded\def\math_punctuation_all_comma {\futurelet\nexttoken\math_punctuation_comma_next} +% \unexpanded\def\math_punctuation_all_period{\futurelet\nexttoken\math_punctuation_period_next} +% +% \let\math_punctuation_yes_comma \math_punctuation_all_comma +% \let\math_punctuation_yes_period\math_punctuation_nop_period +% +% The next one is more efficient as it produces more flat noad lists for numbers. -\unexpanded\def\math_punctuation_nop_comma {\mathpunct{\textcomma}} -\unexpanded\def\math_punctuation_all_comma {\futurelet\nexttoken\math_punctuation_comma_next} - \let\math_punctuation_yes_comma \math_punctuation_all_comma +\setnewconstant\c_math_comma "002C +\setnewconstant\c_math_period "002E +\setnewconstant\c_math_special"8000 + +\def\math_set_o_period{\Umathcode\c_math_period\mathordcode \zerocount\c_math_period} +\def\math_set_p_period{\Umathcode\c_math_period\mathpunctcode\zerocount\c_math_period} +\def\math_set_o_comma {\Umathcode\c_math_comma \mathordcode \zerocount\c_math_comma } +\def\math_set_p_comma {\Umathcode\c_math_comma \mathpunctcode\zerocount\c_math_comma } -\unexpanded\def\math_punctuation_nop_period{\mathord{\textperiod}} +\edef\math_set_o_both {\math_set_o_period\math_set_o_comma} +\edef\math_set_p_both {\math_set_p_period\math_set_p_comma} + +\unexpanded\def\math_punctuation_nop_comma {\begingroup\math_set_p_comma ,\endgroup} +\unexpanded\def\math_punctuation_nop_period{\begingroup\math_set_o_period.\endgroup} + +\unexpanded\def\math_punctuation_all_comma {\futurelet\nexttoken\math_punctuation_comma_next} \unexpanded\def\math_punctuation_all_period{\futurelet\nexttoken\math_punctuation_period_next} + + \let\math_punctuation_yes_comma \math_punctuation_all_comma \let\math_punctuation_yes_period\math_punctuation_nop_period +\def\math_punctuation_comma_next {\begingroup\Umathcode\c_math_comma \ifx\nexttoken\blankspace\mathordcode\else\mathordcode\fi\zerocount\c_math_comma ,\endgroup} +\def\math_punctuation_period_next{\begingroup\Umathcode\c_math_period\ifx\nexttoken\blankspace\mathordcode\else\mathordcode\fi\zerocount\c_math_period.\endgroup} + \setnewconstant\c_math_comma "002C \setnewconstant\c_math_period "002E \setnewconstant\c_math_special"8000 @@ -1360,6 +1388,12 @@ {\let,\math_punctuation_nop_comma \let.\math_punctuation_nop_period} + % more efficient list: + % + % \setgvalue{\??mathautopunctuation\v!no}% + % {\Umathcode\c_math_period\mathordcode \zerocount\c_math_period + % \Umathcode\c_math_comma \mathpunctcode\zerocount\c_math_comma } + \setgvalue{\??mathautopunctuation\v!yes}% {\let,\math_punctuation_yes_comma \let.\math_punctuation_yes_period} @@ -2298,22 +2332,33 @@ \fi\fi \relax} -%D Experiment: +%D Experiment: (todo: same switch as italic, using \type {\everyswitchmathematics}). + +\newcount\c_math_domain_attribute -\unexpanded\def\setmathdomain[#1]% - {\clf_setmathdomain{#1}} +\def\math_domain_initialize + {\ifnum\c_math_domain_attribute=\attributeunsetvalue \else + \clf_initializemathdomain % one time + \global\let\math_domain_initialize\relax + \fi} \appendtoks \edef\p_domain{\mathematicsparameter\c!domain}% - \ifx\currentmathdomain\p_domain \else - \ifx\p_domain\empty - \attribute\mathdomainattribute\attributeunsetvalue - \else - \clf_setmathdomain\p_domain - \fi - \let\currentmathdomain\p_domain + \ifx\p_domain\empty + \c_math_domain_attribute\attributeunsetvalue + \else + \c_math_domain_attribute\clf_getmathdomain\p_domain\relax + \math_domain_initialize \fi -\to \everysetupmathematics +\to \everyswitchmathematics % only in mathematics + +\appendtoks + \attribute\mathdomainattribute\c_math_domain_attribute +\to \everymathematics + +\setupmathematics + [\s!italics=3] % for the moment only this one makes sense .. still experimental + \protect \endinput diff --git a/tex/context/base/math-int.mkiv b/tex/context/base/math-int.mkiv index 6b65738ff..5876eb7bb 100644 --- a/tex/context/base/math-int.mkiv +++ b/tex/context/base/math-int.mkiv @@ -48,13 +48,11 @@ \or \limits \or - % auto - \ifcase\normalmathstyle\displaylimits\or\displaylimits\else\limits\fi - % \ifnum\attribute\mathmodeattribute=\plusone % we need a proper flag - % \displaylimits - % \else - % \limits - % \fi + \ifnum\attribute\mathmodeattribute=\plusone + \limits + \else + \nolimits + \fi \else % none \fi} diff --git a/tex/context/base/math-noa.lua b/tex/context/base/math-noa.lua index 973e44a77..3b11fff77 100644 --- a/tex/context/base/math-noa.lua +++ b/tex/context/base/math-noa.lua @@ -25,143 +25,149 @@ local sortedhash = table.sortedhash local insert, remove = table.insert, table.remove local div = math.div -local fonts, nodes, node, mathematics = fonts, nodes, node, mathematics - -local otf = fonts.handlers.otf -local otffeatures = fonts.constructors.newfeatures("otf") -local registerotffeature = otffeatures.register - -local privateattribute = attributes.private -local registertracker = trackers.register -local registerdirective = directives.register -local logreporter = logs.reporter - -local trace_remapping = false registertracker("math.remapping", function(v) trace_remapping = v end) -local trace_processing = false registertracker("math.processing", function(v) trace_processing = v end) -local trace_analyzing = false registertracker("math.analyzing", function(v) trace_analyzing = v end) -local trace_normalizing = false registertracker("math.normalizing", function(v) trace_normalizing = v end) -local trace_collapsing = false registertracker("math.collapsing", function(v) trace_collapsing = v end) -local trace_patching = false registertracker("math.patching", function(v) trace_patching = v end) -local trace_goodies = false registertracker("math.goodies", function(v) trace_goodies = v end) -local trace_variants = false registertracker("math.variants", function(v) trace_variants = v end) -local trace_alternates = false registertracker("math.alternates", function(v) trace_alternates = v end) -local trace_italics = false registertracker("math.italics", function(v) trace_italics = v end) -local trace_domains = false registertracker("math.domains", function(v) trace_domains = v end) -local trace_families = false registertracker("math.families", function(v) trace_families = v end) -local trace_fences = false registertracker("math.fences", function(v) trace_fences = v end) - -local check_coverage = true registerdirective("math.checkcoverage", function(v) check_coverage = v end) - -local report_processing = logreporter("mathematics","processing") -local report_remapping = logreporter("mathematics","remapping") -local report_normalizing = logreporter("mathematics","normalizing") -local report_collapsing = logreporter("mathematics","collapsing") -local report_patching = logreporter("mathematics","patching") -local report_goodies = logreporter("mathematics","goodies") -local report_variants = logreporter("mathematics","variants") -local report_alternates = logreporter("mathematics","alternates") -local report_italics = logreporter("mathematics","italics") -local report_domains = logreporter("mathematics","domains") -local report_families = logreporter("mathematics","families") -local report_fences = logreporter("mathematics","fences") - -local a_mathrendering = privateattribute("mathrendering") -local a_exportstatus = privateattribute("exportstatus") - -local nuts = nodes.nuts -local nodepool = nuts.pool -local tonut = nuts.tonut -local tonode = nuts.tonode -local nutstring = nuts.tostring - -local getfield = nuts.getfield -local setfield = nuts.setfield -local getnext = nuts.getnext -local getprev = nuts.getprev -local getid = nuts.getid -local getfont = nuts.getfont -local getsubtype = nuts.getsubtype -local getchar = nuts.getchar -local getattr = nuts.getattr -local setattr = nuts.setattr - -local insert_node_after = nuts.insert_after -local insert_node_before = nuts.insert_before -local free_node = nuts.free -local new_node = nuts.new -- todo: pool: math_noad math_sub -local copy_node = nuts.copy -local slide_nodes = nuts.slide - -local mlist_to_hlist = nodes.mlist_to_hlist - -local font_of_family = node.family_font - -local new_kern = nodepool.kern -local new_rule = nodepool.rule - -local fonthashes = fonts.hashes -local fontdata = fonthashes.identifiers -local fontcharacters = fonthashes.characters -local fontproperties = fonthashes.properties -local fontitalics = fonthashes.italics -local fontemwidths = fonthashes.emwidths -local fontexheights = fonthashes.exheights - -local variables = interfaces.variables -local texsetattribute = tex.setattribute -local texgetattribute = tex.getattribute -local unsetvalue = attributes.unsetvalue -local implement = interfaces.implement - -local v_reset = variables.reset - -local chardata = characters.data - -noads = noads or { } -- todo: only here -local noads = noads - -noads.processors = noads.processors or { } -local processors = noads.processors - -noads.handlers = noads.handlers or { } -local handlers = noads.handlers - -local tasks = nodes.tasks - -local nodecodes = nodes.nodecodes -local noadcodes = nodes.noadcodes -local fencecodes = nodes.fencecodes - -local noad_ord = noadcodes.ord -local noad_rel = noadcodes.rel -local noad_bin = noadcodes.bin -local noad_open = noadcodes.open -local noad_close = noadcodes.close -local noad_punct = noadcodes.punct -local noad_opdisplaylimits= noadcodes.opdisplaylimits -local noad_oplimits = noadcodes.oplimits -local noad_opnolimits = noadcodes.opnolimits -local noad_inner = noadcodes.inner - -local math_noad = nodecodes.noad -- attr nucleus sub sup -local math_accent = nodecodes.accent -- attr nucleus sub sup accent -local math_radical = nodecodes.radical -- attr nucleus sub sup left degree -local math_fraction = nodecodes.fraction -- attr nucleus sub sup left right -local math_box = nodecodes.subbox -- attr list -local math_sub = nodecodes.submlist -- attr list -local math_char = nodecodes.mathchar -- attr fam char -local math_textchar = nodecodes.mathtextchar -- attr fam char -local math_delim = nodecodes.delim -- attr small_fam small_char large_fam large_char -local math_style = nodecodes.style -- attr style -local math_choice = nodecodes.choice -- attr display text script scriptscript -local math_fence = nodecodes.fence -- attr subtype - -local hlist_code = nodecodes.hlist -local glyph_code = nodecodes.glyph - -local left_fence_code = fencecodes.left -local middle_fence_code = fencecodes.middle -local right_fence_code = fencecodes.right +local fonts = fonts +local nodes = nodes +local node = node +local mathematics = mathematics +local context = context + +local otf = fonts.handlers.otf +local otffeatures = fonts.constructors.newfeatures("otf") +local registerotffeature = otffeatures.register + +local privateattribute = attributes.private +local registertracker = trackers.register +local registerdirective = directives.register +local logreporter = logs.reporter + +local trace_remapping = false registertracker("math.remapping", function(v) trace_remapping = v end) +local trace_processing = false registertracker("math.processing", function(v) trace_processing = v end) +local trace_analyzing = false registertracker("math.analyzing", function(v) trace_analyzing = v end) +local trace_normalizing = false registertracker("math.normalizing", function(v) trace_normalizing = v end) +local trace_collapsing = false registertracker("math.collapsing", function(v) trace_collapsing = v end) +local trace_patching = false registertracker("math.patching", function(v) trace_patching = v end) +local trace_goodies = false registertracker("math.goodies", function(v) trace_goodies = v end) +local trace_variants = false registertracker("math.variants", function(v) trace_variants = v end) +local trace_alternates = false registertracker("math.alternates", function(v) trace_alternates = v end) +local trace_italics = false registertracker("math.italics", function(v) trace_italics = v end) +local trace_domains = false registertracker("math.domains", function(v) trace_domains = v end) +local trace_families = false registertracker("math.families", function(v) trace_families = v end) +local trace_fences = false registertracker("math.fences", function(v) trace_fences = v end) + +local check_coverage = true registerdirective("math.checkcoverage", function(v) check_coverage = v end) + +local report_processing = logreporter("mathematics","processing") +local report_remapping = logreporter("mathematics","remapping") +local report_normalizing = logreporter("mathematics","normalizing") +local report_collapsing = logreporter("mathematics","collapsing") +local report_patching = logreporter("mathematics","patching") +local report_goodies = logreporter("mathematics","goodies") +local report_variants = logreporter("mathematics","variants") +local report_alternates = logreporter("mathematics","alternates") +local report_italics = logreporter("mathematics","italics") +local report_domains = logreporter("mathematics","domains") +local report_families = logreporter("mathematics","families") +local report_fences = logreporter("mathematics","fences") + +local a_mathrendering = privateattribute("mathrendering") +local a_exportstatus = privateattribute("exportstatus") + +local nuts = nodes.nuts +local nodepool = nuts.pool +local tonut = nuts.tonut +local tonode = nuts.tonode +local nutstring = nuts.tostring + +local getfield = nuts.getfield +local setfield = nuts.setfield +local getnext = nuts.getnext +local getprev = nuts.getprev +local getid = nuts.getid +local getfont = nuts.getfont +local getsubtype = nuts.getsubtype +local getchar = nuts.getchar +local getattr = nuts.getattr +local setattr = nuts.setattr + +local insert_node_after = nuts.insert_after +local insert_node_before = nuts.insert_before +local free_node = nuts.free +local new_node = nuts.new -- todo: pool: math_noad math_sub +local copy_node = nuts.copy +local slide_nodes = nuts.slide +local linked_nodes = nuts.linked +local set_visual = nuts.setvisual + +local mlist_to_hlist = nodes.mlist_to_hlist + +local font_of_family = node.family_font + +local new_kern = nodepool.kern +local new_rule = nodepool.rule + +local fonthashes = fonts.hashes +local fontdata = fonthashes.identifiers +local fontcharacters = fonthashes.characters +local fontproperties = fonthashes.properties +local fontitalics = fonthashes.italics +local fontemwidths = fonthashes.emwidths +local fontexheights = fonthashes.exheights + +local variables = interfaces.variables +local texsetattribute = tex.setattribute +local texgetattribute = tex.getattribute +local unsetvalue = attributes.unsetvalue +local implement = interfaces.implement + +local v_reset = variables.reset + +local chardata = characters.data + +noads = noads or { } -- todo: only here +local noads = noads + +noads.processors = noads.processors or { } +local processors = noads.processors + +noads.handlers = noads.handlers or { } +local handlers = noads.handlers + +local tasks = nodes.tasks + +local nodecodes = nodes.nodecodes +local noadcodes = nodes.noadcodes +local fencecodes = nodes.fencecodes + +local noad_ord = noadcodes.ord +local noad_rel = noadcodes.rel +local noad_bin = noadcodes.bin +local noad_open = noadcodes.open +local noad_close = noadcodes.close +local noad_punct = noadcodes.punct +local noad_opdisplaylimits = noadcodes.opdisplaylimits +local noad_oplimits = noadcodes.oplimits +local noad_opnolimits = noadcodes.opnolimits +local noad_inner = noadcodes.inner + +local math_noad = nodecodes.noad -- attr nucleus sub sup +local math_accent = nodecodes.accent -- attr nucleus sub sup accent +local math_radical = nodecodes.radical -- attr nucleus sub sup left degree +local math_fraction = nodecodes.fraction -- attr nucleus sub sup left right +local math_box = nodecodes.subbox -- attr list +local math_sub = nodecodes.submlist -- attr list +local math_char = nodecodes.mathchar -- attr fam char +local math_textchar = nodecodes.mathtextchar -- attr fam char +local math_delim = nodecodes.delim -- attr small_fam small_char large_fam large_char +local math_style = nodecodes.style -- attr style +local math_choice = nodecodes.choice -- attr display text script scriptscript +local math_fence = nodecodes.fence -- attr subtype + +local hlist_code = nodecodes.hlist +local glyph_code = nodecodes.glyph + +local left_fence_code = fencecodes.left +local middle_fence_code = fencecodes.middle +local right_fence_code = fencecodes.right -- this initial stuff is tricky as we can have removed and new nodes with the same address -- the only way out is a free-per-page list of nodes (not bad anyway) @@ -1077,72 +1083,93 @@ end -- = we check for correction first because accessing nodes is slower -- = the actual glyph is not that important (we can control it with numbers) --- Italic correction in luatex math is a mess. There are all kind of assumptions based on --- old fonts and new font. Eventually there should be a flag that can signal to ignore all --- those heuristics. We want to deal with it ourselves also in the perspective of mxed math --- and text. +-- Italic correction in luatex math is (was) a mess. There are all kind of assumptions based on +-- old fonts and new fonts. Eventually there should be a flag that can signal to ignore all +-- those heuristics. We want to deal with it ourselves also in the perspective of mixed math +-- and text. Also, for a while in context we had to deal with a mix of virtual math fonts and +-- real ones. + +-- in opentype the italic correction of a limop is added to the width and luatex does some juggling +-- that we want to avoid but we need to do something here (in fact, we could better fix the width of +-- the character local a_mathitalics = privateattribute("mathitalics") local italics = { } local default_factor = 1/20 +local setcolor = nodes.tracers.colors.set +local resetcolor = nodes.tracers.colors.reset +local italic_kern = new_kern +local c_positive_d = "trace:dg" +local c_negative_d = "trace:dr" + +local function insert_kern(current,kern) + local sub = new_node(math_sub) -- todo: pool + local noad = new_node(math_noad) -- todo: pool + setfield(sub,"list",kern) + setfield(kern,"next",noad) + setfield(noad,"nucleus",current) + return sub +end + +registertracker("math.italics.visualize", function(v) + if v then + italic_kern = function(k) + local n = new_kern(k) + set_visual(n,"italic") + return n + end + else + italic_kern = new_kern + end +end) + local function getcorrection(method,font,char) -- -- or character.italic -- (this one is for tex) - local correction, fromvisual + local visual = chardata[char].visual if method == 1 then - -- only font data triggered by fontitalics + -- check on state local italics = fontitalics[font] if italics then local character = fontcharacters[font][char] if character then - correction = character.italic_correction + local correction = character.italic if correction and correction ~= 0 then - return correction, false + return correction, visual end end end elseif method == 2 then - -- only font data triggered by fontdata + -- no check local character = fontcharacters[font][char] if character then - correction = character.italic_correction + local correction = character.italic if correction and correction ~= 0 then - return correction, false + return correction, visual end end elseif method == 3 then - -- only quad based by selective - local visual = chardata[char].visual - if not visual then - -- skip - elseif visual == "it" or visual == "bi" then - correction = fontproperties[font].mathitalic_defaultvalue or default_factor*fontemwidths[font] - if correction and correction ~= 0 then - return correction, true + -- check on visual + if visual == "it" or visual == "bi" then + local character = fontcharacters[font][char] + if character then + local correction = character.italic + if correction and correction ~= 0 then + return correction, visual + end end end elseif method == 4 then -- combination of 1 and 3 local italics = fontitalics[font] - if italics then + if italics and (visual == "it" or visual == "bi") then local character = fontcharacters[font][char] if character then - correction = character.italic_correction - if correction and correction ~= 0 then - return correction, false - end - end - end - if not correction then - local visual = chardata[char].visual - if not visual then - -- skip - elseif visual == "it" or visual == "bi" then - correction = fontproperties[font].mathitalic_defaultvalue or default_factor*fontemwidths[font] + local correction = character.italic if correction and correction ~= 0 then - return correction, true + return correction, visual end end end @@ -1150,115 +1177,21 @@ local function getcorrection(method,font,char) -- -- or character.italic -- (thi end -local setcolor = nodes.tracers.colors.set -local resetcolor = nodes.tracers.colors.reset -local italic_kern = new_kern -local c_positive_d = "trace:db" -local c_negative_d = "trace:dr" - -local function insert_kern(current,kern) - local sub = new_node(math_sub) -- todo: pool - local noad = new_node(math_noad) -- todo: pool - setfield(sub,"list",kern) - setfield(kern,"next",noad) - setfield(noad,"nucleus",current) - return sub -end - -registertracker("math.italics.visualize", function(v) - if v then - italic_kern = function(k,font) - local ex = 1.5 * fontexheights[font] - if k > 0 then - return setcolor(new_rule(k,ex,ex),c_positive_d) - else - -- influences un* - return old_kern(k) .. setcolor(new_rule(-k,ex,ex),c_negative_d) .. old_kern(k) - end - end - else - italic_kern = new_kern - end -end) - italics[math_char] = function(pointer,what,n,parent) local method = getattr(pointer,a_mathitalics) - if method and method > 0 then + if method and method > 0 and method < 100 then local char = getchar(pointer) local font = font_of_family(getfield(pointer,"fam")) -- todo: table local correction, visual = getcorrection(method,font,char) - if correction then - local pid = getid(parent) - local sub, sup - if pid == math_noad then - sup = getfield(parent,"sup") - sub = getfield(parent,"sub") - end - if sup or sub then - local subtype = getsubtype(parent) - if subtype == noad_oplimits then - if sup then - setfield(parent,"sup",insert_kern(sup,italic_kern(correction,font))) - if trace_italics then - report_italics("method %a, adding %p italic correction for upper limit of %C",method,correction,char) - end - end - if sub then - local correction = - correction - setfield(parent,"sub",insert_kern(sub,italic_kern(correction,font))) - if trace_italics then - report_italics("method %a, adding %p italic correction for lower limit of %C",method,correction,char) - end - end - elseif sup then - if pointer ~= sub then - setfield(parent,"sup",insert_kern(sup,italic_kern(correction,font))) - if trace_italics then - report_italics("method %a, adding %p italic correction before superscript after %C",method,correction,char) - end - else - -- otherwise we inject twice - end - end - else - local next_noad = getnext(parent) - if not next_noad then - if n== 1 then -- only at the outer level .. will become an option (always,endonly,none) - if trace_italics then - report_italics("method %a, adding %p italic correction between %C and end math",method,correctio,char) - end - insert_node_after(parent,parent,italic_kern(correction,font)) - end - elseif getid(next_noad) == math_noad then - local next_subtype = getsubtype(next_noad) - if next_subtype == noad_punct or next_subtype == noad_ord then - local next_nucleus = getfield(next_noad,"nucleus") - if getid(next_nucleus) == math_char then - local next_char = getchar(next_nucleus) - local next_data = chardata[next_char] - local visual = next_data.visual - if visual == "it" or visual == "bi" then - -- if trace_italics then - -- report_italics("method %a, skipping %p italic correction between italic %C and italic %C",method,correction,char,next_char) - -- end - else - local category = next_data.category - if category == "nd" or category == "ll" or category == "lu" then - if trace_italics then - report_italics("method %a, adding %p italic correction between italic %C and non italic %C",method,correction,char,next_char) - end - insert_node_after(parent,parent,italic_kern(correction,font)) - -- elseif next_data.height > (fontexheights[font]/2) then - -- if trace_italics then - -- report_italics("method %a, adding %p italic correction between %C and ascending %C",method,correction,char,next_char) - -- end - -- insert_node_after(parent,parent,italic_kern(correction,font)) - -- elseif trace_italics then - -- -- report_italics("method %a, skipping %p italic correction between %C and %C",method,correction,char,next_char) - end - end - end + if correction and correction ~= 0 then + local next_noad = getnext(parent) + if not next_noad then + if n == 1 then -- only at the outer level .. will become an option (always,endonly,none) + if trace_italics then + report_italics("method %a, flagging italic correction between %C and end math",method,correction,char) end + setattr(pointer,a_mathitalics,101) + setattr(parent,a_mathitalics,101) end end end @@ -1286,7 +1219,14 @@ function mathematics.setitalics(name) if enable then enable() end - texsetattribute(a_mathitalics,name and name ~= v_reset and tonumber(name) or unsetvalue) + texsetattribute(a_mathitalics,name and name ~= v_reset and tonumber(name) or unsetvalue) -- maybe also v_none +end + +function mathematics.getitalics(name) + if enable then + enable() + end + context(name and name ~= v_reset and tonumber(name) or unsetvalue) end function mathematics.resetitalics() @@ -1294,8 +1234,21 @@ function mathematics.resetitalics() end implement { + name = "initializemathitalics", + actions = enable, + onlyonce = true, +} + +implement { name = "setmathitalics", - actions = mathematics.setitalics + actions = mathematics.setitalics, + arguments = "string", +} + +implement { + name = "getmathitalics", + actions = mathematics.getitalics, + arguments = "string", } implement { @@ -1602,12 +1555,32 @@ do texsetattribute(a_mathdomain,data and data.attribute or unsetvalue) end + function mathematics.getdomain(name) + if enable then + enable() + end + local data = name and name ~= v_reset and categories[name] + context(data and data.attribute or unsetvalue) + end + + implement { + name = "initializemathdomain", + actions = enable, + onlyonce = true, + } + implement { name = "setmathdomain", arguments = "string", actions = mathematics.setdomain, } + implement { + name = "getmathdomain", + arguments = "string", + actions = mathematics.getdomain, + } + local function makehash(data) local hash = { } local parents = data.parents diff --git a/tex/context/base/pack-rul.lua b/tex/context/base/pack-rul.lua index 151642c3a..dc4e48655 100644 --- a/tex/context/base/pack-rul.lua +++ b/tex/context/base/pack-rul.lua @@ -108,6 +108,7 @@ local function doreshapeframedbox(n) local subtype = getsubtype(h) if subtype == box_code or subtype == line_code then l = hpack(l,maxwidth,'exactly',getfield(h,"dir")) -- multiple return values +-- setfield(l,"attr",getfield(h,"attr")) setfield(h,"list",l) setfield(h,"shift",0) -- needed for display math, so no width check possible end diff --git a/tex/context/base/pack-rul.mkiv b/tex/context/base/pack-rul.mkiv index 0fecf792c..911076f60 100644 --- a/tex/context/base/pack-rul.mkiv +++ b/tex/context/base/pack-rul.mkiv @@ -1526,6 +1526,7 @@ \pack_framed_finish_c \fi\fi\fi \ifconditional\page_postprocessors_needed_box + % quite late \page_postprocessors_linenumbers_box\b_framed_normal \fi \else diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex 3fee23fc6..69a42bdc6 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex 178090ac0..408a0546d 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/strc-bkm.lua b/tex/context/base/strc-bkm.lua index 96b68b236..a055a97a1 100644 --- a/tex/context/base/strc-bkm.lua +++ b/tex/context/base/strc-bkm.lua @@ -214,6 +214,7 @@ function bookmarks.place() end end end +-- inspect(levels) bookmarks.finalize(levels) function bookmarks.place() end -- prevent second run end diff --git a/tex/context/base/strc-def.mkiv b/tex/context/base/strc-def.mkiv index b4d2a5fea..015e02d67 100644 --- a/tex/context/base/strc-def.mkiv +++ b/tex/context/base/strc-def.mkiv @@ -66,7 +66,7 @@ \setsectionblock [\v!bodypart] % default \appendtoks - \setsectionblock [\v!bodypart]% default + \clf_setinitialsectionblock{\v!bodypart}% \to \everyjob % \definesection (could become \definehead with one parameter) diff --git a/tex/context/base/strc-doc.lua b/tex/context/base/strc-doc.lua index 3019c7a66..66b30fe3a 100644 --- a/tex/context/base/strc-doc.lua +++ b/tex/context/base/strc-doc.lua @@ -240,9 +240,22 @@ function sections.setblock(name,settings) return block end +local pushed_order = { } +local pushed_done = { } + +function sections.order() + return job.variables.collected.sectionblockorder or pushed_order -- so we have a first pass list too +end + function sections.pushblock(name,settings) counters.check(0) -- we assume sane usage of \page between blocks local block = name or data.block + if not pushed_done[name] then + pushed_done[name] = true + local nofpushed = #pushed_order + 1 + pushed_order[nofpushed] = name + job.variables.tobesaved.sectionblockorder = pushed_order + end insert(data.blocks,block) data.block = block sectionblockdata[block] = settings @@ -1103,3 +1116,16 @@ implement { name = "popsectionblock", actions = sections.popblock, } + +-- bah, i'll probably forget about this hack but it's needed for +-- preamble list mess as used by some users for booksmarks + +implement { + name = "setinitialsectionblock", + onlyonce = true, + arguments = "string", + actions = function(default) + local name = sections.order()[1] + context.setsectionblock { name ~= "" and name or default } + end +} diff --git a/tex/context/base/strc-lst.lua b/tex/context/base/strc-lst.lua index fd79bbd7a..050655e64 100644 --- a/tex/context/base/strc-lst.lua +++ b/tex/context/base/strc-lst.lua @@ -122,6 +122,7 @@ local function initializer() local ordered = lists.ordered local usedinternals = references.usedinternals local blockdone = { } + local lastblock = nil for i=1,#collected do local c = collected[i] local m = c.metadata @@ -135,9 +136,22 @@ local function initializer() usedinternals[internal] = r.used end local block = r.block - if block and not blockdone[block] then + if not block then + -- shouldn't happen + elseif lastblock == block then + -- we're okay + elseif lastblock then + if blockdone[block] then + report_lists("out of order sectionsblocks, maybe use \\setsectionblock") + else + blockdone[block] = true + sectionblocks[#sectionblocks+1] = block + end + lastblock = block + elseif not blockdone[block] then blockdone[block] = true sectionblocks[#sectionblocks+1] = block + lastblock = block end end -- access by order in list diff --git a/tex/context/base/trac-vis.lua b/tex/context/base/trac-vis.lua index 1b93ebb2d..40ba1e8c3 100644 --- a/tex/context/base/trac-vis.lua +++ b/tex/context/base/trac-vis.lua @@ -144,6 +144,7 @@ local trace_strut local trace_whatsit local trace_user local trace_math +local trace_italic local report_visualize = logs.reporter("visualize") @@ -164,6 +165,7 @@ local modes = { simplevtop = 1024 + 4, user = 2048, math = 4096, + italic = 8192, } local modes_makeup = { "hbox", "vbox", "kern", "glue", "penalty" } @@ -171,7 +173,7 @@ local modes_boxes = { "hbox", "vbox" } local modes_all = { "hbox", "vbox", "kern", "glue", "penalty", "fontkern", "whatsit", "glyph", "user", "math" } local usedfont, exheight, emwidth -local l_penalty, l_glue, l_kern, l_fontkern, l_hbox, l_vbox, l_vtop, l_strut, l_whatsit, l_glyph, l_user, l_math +local l_penalty, l_glue, l_kern, l_fontkern, l_hbox, l_vbox, l_vtop, l_strut, l_whatsit, l_glyph, l_user, l_math, l_italic local enabled = false local layers = { } @@ -216,6 +218,7 @@ local function enable() l_glyph = layers.glyph l_user = layers.user l_math = layers.math + l_italic = layers.italic nodes.tasks.enableaction("shipouts","nodes.visualizers.handler") report_visualize("enabled") enabled = true @@ -272,6 +275,10 @@ local function setvisual(n,a,what) -- this will become more efficient when we ha return a end +function nuts.setvisual(n,mode) + setattr(n,a_visual,setvisual(mode,getattr(n,a_visual),true)) +end + function visualizers.setvisual(n) texsetattribute(a_visual,setvisual(n,texgetattribute(a_visual))) end @@ -748,6 +755,29 @@ local function ruledkern(head,current,vertical) return head, getnext(current) end +local i_cache = { } + +local function ruleditalic(head,current) + local kern = getfield(current,"kern") + local info = i_cache[kern] + if info then + -- print("kern hit") + else + local amount = formatters["%s:%0.3f"]("IC",kern*pt_factor) + if kern > 0 then + info = sometext(amount,l_kern,c_positive) + elseif kern < 0 then + info = sometext(amount,l_kern,c_negative) + else + info = sometext(amount,l_kern,c_zero) + end + i_cache[kern] = info + end + info = copy_list(info) + head, current = insert_node_before(head,current,info) + return head, getnext(current) +end + local p_cache_v = { } local p_cache_h = { } @@ -789,6 +819,7 @@ local function visualize(head,vertical,forced) local trace_simple = false local trace_user = false local trace_math = false + local trace_italic = false local current = head local previous = nil local attr = unsetvalue @@ -812,6 +843,7 @@ local function visualize(head,vertical,forced) trace_simple = false trace_user = false trace_math = false + trace_italic = false else -- dead slow: trace_hbox = hasbit(a, 1) trace_vbox = hasbit(a, 2) @@ -826,6 +858,7 @@ local function visualize(head,vertical,forced) trace_simple = hasbit(a,1024) trace_user = hasbit(a,2048) trace_math = hasbit(a,4096) + trace_italic = hasbit(a,8192) end attr = a end @@ -856,7 +889,9 @@ local function visualize(head,vertical,forced) head, current = fontkern(head,current) end else -- if subtype == user_kern_code then - if trace_kern then + if trace_italic then + head, current = ruleditalic(head,current) + elseif trace_kern then head, current = ruledkern(head,current,vertical) end end diff --git a/tex/context/base/typo-itc.lua b/tex/context/base/typo-itc.lua index d3a31fad1..47783be49 100644 --- a/tex/context/base/typo-itc.lua +++ b/tex/context/base/typo-itc.lua @@ -49,6 +49,8 @@ local find_tail = nuts.tail local texgetattribute = tex.getattribute local texsetattribute = tex.setattribute local a_italics = attributes.private("italics") +local a_mathitalics = attributes.private("mathitalics") + local unsetvalue = attributes.unsetvalue local new_correction_kern = nodepool.fontkern @@ -59,6 +61,8 @@ local fontdata = fonthashes.identifiers local italicsdata = fonthashes.italics local exheights = fonthashes.exheights +local is_punctuation = characters.is_punctuation + local implement = interfaces.implement local forcedvariant = false @@ -67,11 +71,14 @@ function typesetters.italics.forcevariant(variant) forcedvariant = variant end +-- We use the same key as the tex font handler. So, if a valua has already be set, we +-- use that one. + local function setitalicinfont(font,char) local tfmdata = fontdata[font] local character = tfmdata.characters[char] if character then - local italic = character.italic_correction + local italic = character.italic if not italic then local autoitalicamount = tfmdata.properties.autoitalicamount or 0 if autoitalicamount ~= 0 then @@ -93,7 +100,10 @@ local function setitalicinfont(font,char) if trace_italics then report_italics("setting italic correction of %C of font %a to %p",char,font,italic) end - character.italic_correction = italic or 0 + if not italic then + italic = 0 + end + character.italic = italic end return italic else @@ -236,7 +246,7 @@ function italics.handler(head) -- this really can happen previtalic = 0 else - previtalic = cd.italic or cd.italic_correction + previtalic = cd.italic if not previtalic then previtalic = setitalicinfont(font,char) -- calculated once -- previtalic = 0 @@ -283,7 +293,7 @@ function italics.handler(head) -- this really can happen replaceitalic = 0 else - replaceitalic = cd.italic or cd.italic_correction + replaceitalic = cd.italic if not replaceitalic then replaceitalic = setitalicinfont(font,char) -- calculated once -- replaceitalic = 0 @@ -328,7 +338,7 @@ function italics.handler(head) -- this really can happen -- postitalic = 0 else - postitalic = cd.italic or cd.italic_correction + postitalic = cd.italic if not postitalic then postitalic = setitalicinfont(font,char) -- calculated once -- postitalic = 0 @@ -399,6 +409,30 @@ function italics.handler(head) replaceitalic = 0 postinserted = nil postitalic = 0 + local next = getnext(current) + if next and getid(next) == glyph_code then + local char = getchar(next) + if is_punctuation[char] then + local kern = getprev(current) + if kern and getid(kern) == kern_code then + local glyph = getprev(kern) + if glyph and getid(glyph) == glyph_code then + local a = getattr(glyph,a_mathitalics) + if a == 101 then + local font = getfont(next) + local ex = exheights[font] + -- we need an extrat punctuation checker: . ; etc + if getfield(next,"height") < 1.25*ex then + if trace_italics then + report_italics("removing italic between math %C and punctuation %C",getchar(glyph),char) + end + setfield(kern,"kern",0) -- or maybe a small value or half the ic + end + end + end + end + end + end else if previtalic ~= 0 then if trace_italics then @@ -529,7 +563,7 @@ local function setupitaliccorrection(option) -- no grouping ! texsetattribute(a_italics,variant) end if trace_italics then - report_italics("forcing %a, variant %a",forcedvariant,variant ~= unsetvalue and variant) + report_italics("forcing %a, variant %a",forcedvariant or "-",variant ~= unsetvalue and variant) end end diff --git a/tex/context/base/typo-itc.mkvi b/tex/context/base/typo-itc.mkvi index c0aa8e2f6..b0d2673cd 100644 --- a/tex/context/base/typo-itc.mkvi +++ b/tex/context/base/typo-itc.mkvi @@ -24,7 +24,8 @@ \registerctxluafile{typo-itc}{1.001} -\definesystemattribute[italics][public] +\definesystemattribute[italics] [public] +\definesystemattribute[mathitalics][public] % \let\/=/ % \let\emphasiscorrection\donothing diff --git a/tex/context/fonts/xits-math.lfg b/tex/context/fonts/xits-math.lfg index 24ed2b0aa..8e1274365 100644 --- a/tex/context/fonts/xits-math.lfg +++ b/tex/context/fonts/xits-math.lfg @@ -24,9 +24,9 @@ return { author = "Hans Hagen", copyright = "ConTeXt development team", mathematics = { - italics = { - ["xits-math"] = italics, - }, + -- italics = { + -- ["xits-math"] = italics, + -- }, alternates = { cal = { feature = 'ss01', value = 1, comment = "Mathematical Calligraphic Alphabet" }, greekssup = { feature = 'ss02', value = 1, comment = "Mathematical Greek Sans Serif Alphabet" }, diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index beff7cf61..5de00c5d4 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 07/24/15 13:58:54 +-- merge date : 07/27/15 19:36:10 do -- begin closure to overcome local limits and interference @@ -4492,21 +4492,28 @@ function constructors.scale(tfmdata,specification) target.nomath=true target.mathparameters=nil end - local italickey="italic" - local useitalics=true if hasmath then - autoitalicamount=false - elseif properties.textitalics then - italickey="italic_correction" - useitalics=false - if properties.delaytextitalics then + local mathitalics=properties.mathitalics + if mathitalics==false then + if trace_defining then + report_defining("%s italics %s for font %a, fullname %a, filename %a","math",hasitalics and "ignored" or "disabled",name,fullname,filename) + end + hasitalics=false + autoitalicamount=false + end + else + local textitalics=properties.textitalics + if textitalics==false then + if trace_defining then + report_defining("%s italics %s for font %a, fullname %a, filename %a","text",hasitalics and "ignored" or "disabled",name,fullname,filename) + end + hasitalics=false autoitalicamount=false end end if trace_defining then report_defining("defining tfm, name %a, fullname %a, filename %a, hscale %a, vscale %a, math %a, italics %a", - name,fullname,filename,hdelta,vdelta, - hasmath and "enabled" or "disabled",useitalics and "enabled" or "disabled") + name,fullname,filename,hdelta,vdelta,hasmath and "enabled" or "disabled",hasitalics and "enabled" or "disabled") end constructors.beforecopyingcharacters(target,tfmdata) local sharedkerns={} @@ -4604,22 +4611,6 @@ function constructors.scale(tfmdata,specification) chr.right_protruding=protrusionfactor*width*vr end end - if autoitalicamount then - local vi=description.italic - if not vi then - local vi=description.boundingbox[3]-description.width+autoitalicamount - if vi>0 then - chr[italickey]=vi*hdelta - end - elseif vi~=0 then - chr[italickey]=vi*hdelta - end - elseif hasitalics then - local vi=description.italic - if vi and vi~=0 then - chr[italickey]=vi*hdelta - end - end if hasmath then local vn=character.next if vn then @@ -4657,7 +4648,7 @@ function constructors.scale(tfmdata,specification) end end end - local va=character.top_accent + local va=character.accent if va then chr.top_accent=vdelta*va end @@ -4680,6 +4671,27 @@ function constructors.scale(tfmdata,specification) chr.mathkern=kerns end end + if hasitalics then + local vi=character.italic + if vi and vi~=0 then + chr.italic=vi*hdelta + end + end + elseif autoitalicamount then + local vi=description.italic + if not vi then + local vi=description.boundingbox[3]-description.width+autoitalicamount + if vi>0 then + chr.italic=vi*hdelta + end + elseif vi~=0 then + chr.italic=vi*hdelta + end + elseif hasitalics then + local vi=character.italic + if vi and vi~=0 then + chr.italic=vi*hdelta + end end if haskerns then local vk=character.kerns @@ -4742,6 +4754,7 @@ function constructors.scale(tfmdata,specification) end targetcharacters[unicode]=chr end + properties.setitalics=hasitalics constructors.aftercopyingcharacters(target,tfmdata) constructors.trytosharefont(target,tfmdata) return target @@ -7110,7 +7123,7 @@ local report_otf=logs.reporter("fonts","otf loading") local fonts=fonts local otf=fonts.handlers.otf otf.glists={ "gsub","gpos" } -otf.version=2.817 +otf.version=2.818 otf.cache=containers.define("fonts","otf",otf.version,true) local hashes=fonts.hashes local definers=fonts.definers @@ -8524,11 +8537,11 @@ local function check_variants(unicode,the_variants,splitter,unicodes) parts=nil end end - local italic_correction=the_variants.italic_correction - if italic_correction and italic_correction==0 then - italic_correction=nil + local italic=the_variants.italic + if italic and italic==0 then + italic=nil end - return variants,parts,italic_correction + return variants,parts,italic end actions["analyze math"]=function(data,filename,raw) if raw.math then @@ -8538,13 +8551,14 @@ actions["analyze math"]=function(data,filename,raw) for unicode,description in next,data.descriptions do local glyph=description.glyph local mathkerns=glyph.mathkern - local horiz_variants=glyph.horiz_variants - local vert_variants=glyph.vert_variants - local top_accent=glyph.top_accent - if mathkerns or horiz_variants or vert_variants or top_accent then + local hvariants=glyph.horiz_variants + local vvariants=glyph.vert_variants + local accent=glyph.top_accent + local italic=glyph.italic_correction + if mathkerns or hvariants or vvariants or accent or italic then local math={} - if top_accent then - math.top_accent=top_accent + if accent then + math.accent=accent end if mathkerns then for k,v in next,mathkerns do @@ -8560,15 +8574,14 @@ actions["analyze math"]=function(data,filename,raw) end math.kerns=mathkerns end - if horiz_variants then - math.horiz_variants,math.horiz_parts,math.horiz_italic_correction=check_variants(unicode,horiz_variants,splitter,unicodes) + if hvariants then + math.hvariants,math.hparts,math.hitalic=check_variants(unicode,hvariants,splitter,unicodes) end - if vert_variants then - math.vert_variants,math.vert_parts,math.vert_italic_correction=check_variants(unicode,vert_variants,splitter,unicodes) + if vvariants then + math.vvariants,math.vparts,math.vitalic=check_variants(unicode,vvariants,splitter,unicodes) end - local italic_correction=description.italic - if italic_correction and italic_correction~=0 then - math.italic_correction=italic_correction + if italic and italic~=0 then + math.italic=italic end description.math=math end @@ -9104,8 +9117,9 @@ local function copytotfm(data,cache_id) local d=descriptions[unicode] local m=d.math if m then - local variants=m.horiz_variants - local parts=m.horiz_parts + local italic=m.italic + local variants=m.hvariants + local parts=m.hparts if variants then local c=character for i=1,#variants do @@ -9116,9 +9130,10 @@ local function copytotfm(data,cache_id) c.horiz_variants=parts elseif parts then character.horiz_variants=parts + italic=m.hitalic end - local variants=m.vert_variants - local parts=m.vert_parts + local variants=m.vvariants + local parts=m.vparts if variants then local c=character for i=1,#variants do @@ -9129,14 +9144,14 @@ local function copytotfm(data,cache_id) c.vert_variants=parts elseif parts then character.vert_variants=parts + italic=m.vitalic end - local italic_correction=m.vert_italic_correction - if italic_correction then - character.vert_italic_correction=italic_correction + if italic and italic~=0 then + character.italic=italic end - local top_accent=m.top_accent - if top_accent then - character.top_accent=top_accent + local accent=m.accent + if accent then + character.accent=accent end local kerns=m.kerns if kerns then diff --git a/tex/generic/context/luatex/luatex-gadgets.lua b/tex/generic/context/luatex/luatex-gadgets.lua new file mode 100644 index 000000000..9bf423fda --- /dev/null +++ b/tex/generic/context/luatex/luatex-gadgets.lua @@ -0,0 +1,75 @@ +if not modules then modules = { } end modules ['luatex-gadgets'] = { + version = 1.001, + comment = "companion to luatex-gadgets.tex", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +if context then return end + +-- This module contains some maybe useful gadgets. More might show up here +-- as side effect of tutorials or articles. Don't use this file in ConTeXt +-- because we often have similar mechanisms already. + +gadgets = gadgets or { } -- global namespace + +-- marking content for optional removal + +local marking = { } +gadgets.marking = marking + +local marksignal = 5001 -- will be set in the tex module +local lastmarked = 0 +local marked = { } +local local_par = 6 +local whatsit_node = 8 + +function marking.setsignal(n) + marksignal = tonumber(n) or marksignal +end + +function marking.mark(str) + local currentmarked = marked[str] + if not currentmarked then + lastmarked = lastmarked + 1 + currentmarked = lastmarked + marked[str] = currentmarked + end + tex.setattribute(marksignal,currentmarked) +end + +function marking.remove(str) + local attr = marked[str] + if not attr then + return + end + local list = tex.nest[tex.nest.ptr] + if list then + local head = list.head + local tail = list.tail + local last = tail + if last[marksignal] == attr then + local first = last + while true do + local prev = first.prev + if not prev + or prev[marksignal] ~= attr + or (prev.id == whatsit_node and prev.subtype == local_par) then + break + else + first = prev + end + end + if first == head then + list.head = nil + list.tail = nil + else + local prev = first.prev + list.tail = prev + prev.next = nil + end + node.flush_list(first) + end + end +end diff --git a/tex/generic/context/luatex/luatex-gadgets.tex b/tex/generic/context/luatex/luatex-gadgets.tex new file mode 100644 index 000000000..0faba7f97 --- /dev/null +++ b/tex/generic/context/luatex/luatex-gadgets.tex @@ -0,0 +1,25 @@ +%D \module +%D [ file=luatex-gadgets, +%D version=2015.05.12, +%D title=\LUATEX\ Support Macros, +%D subtitle=Useful stuff from articles, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] + +\directlua{dofile(resolvers.findfile('luatex-gadgets.lua'))} + +% optional removal of marked content +% +% before\marksomething{gone}{\em HERE}\unsomething{gone}after +% before\marksomething{kept}{\em HERE}\unsomething{gone}after +% \marksomething{gone}{\em HERE}\unsomething{gone}last +% \marksomething{kept}{\em HERE}\unsomething{gone}last + +\def\setmarksignal #1{\directlua{gadgets.marking.setsignal(\number#1)}} +\def\marksomething#1#2{{\directlua{gadgets.marking.mark("#1")}{#2}}} +\def\unsomething #1{\directlua{gadgets.marking.remove("#1")}} + +\newattribute\gadgetmarkattribute \setmarksignal\gadgetmarkattribute + +\endinput diff --git a/tex/generic/context/luatex/luatex-plain.tex b/tex/generic/context/luatex/luatex-plain.tex index f209f4792..2c04a27c0 100644 --- a/tex/generic/context/luatex/luatex-plain.tex +++ b/tex/generic/context/luatex/luatex-plain.tex @@ -39,7 +39,7 @@ \input {luatex-math}% \input {luatex-languages}% \input {luatex-mplib}% - % \input {luatex-gadgets}% + \input {luatex-gadgets}% } % We also patch the version number: |