diff options
Diffstat (limited to 'tex/context/base/mkiv/typo-itc.lua')
| -rw-r--r-- | tex/context/base/mkiv/typo-itc.lua | 64 | 
1 files changed, 47 insertions, 17 deletions
diff --git a/tex/context/base/mkiv/typo-itc.lua b/tex/context/base/mkiv/typo-itc.lua index ea8103aad..312832d5b 100644 --- a/tex/context/base/mkiv/typo-itc.lua +++ b/tex/context/base/mkiv/typo-itc.lua @@ -6,9 +6,9 @@ if not modules then modules = { } end modules ['typo-itc'] = {      license   = "see context related readme files"  } -local utfchar = utf.char  local trace_italics       = false  trackers.register("typesetters.italics", function(v) trace_italics = v end) +  local report_italics      = logs.reporter("nodes","italics")  local threshold           = 0.5   trackers.register("typesetters.threshold", function(v) threshold = v == true and 0.5 or tonumber(v) end) @@ -23,7 +23,7 @@ local glue_code           = nodecodes.glue  local disc_code           = nodecodes.disc  local math_code           = nodecodes.math -local tasks               = nodes.tasks +local enableaction        = nodes.tasks.enableaction  local nuts                = nodes.nuts  local nodepool            = nuts.pool @@ -40,14 +40,18 @@ local getchar             = nuts.getchar  local getdisc             = nuts.getdisc  local getattr             = nuts.getattr  local setattr             = nuts.setattr +local getattrlist         = nuts.getattrlist +local setattrlist         = nuts.setattrlist  local setfield            = nuts.setfield  local setdisc             = nuts.setdisc  local isglyph             = nuts.isglyph +local setkern             = nuts.setkern +local getkern             = nuts.getkern +local getheight           = nuts.getheight  local insert_node_after   = nuts.insert_after  local delete_node         = nuts.delete  local end_of_math         = nuts.end_of_math -local find_tail           = nuts.tail  local texgetattribute     = tex.getattribute  local texsetattribute     = tex.setattribute @@ -63,6 +67,7 @@ local fonthashes          = fonts.hashes  local fontdata            = fonthashes.identifiers  local italicsdata         = fonthashes.italics  local exheights           = fonthashes.exheights +local chardata            = fonthashes.characters  local is_punctuation      = characters.is_punctuation @@ -117,14 +122,14 @@ end  -- todo: clear attribute  local function okay(data,current,font,prevchar,previtalic,char,what) -    if not data then +    if data then          if trace_italics then              report_italics("ignoring %p between %s italic %C and italic %C",previtalic,what,prevchar,char)          end          return false      end      if threshold then -        local ht = getfield(current,"height") +        local ht = getheight(current)          local ex = exheights[font]          local th = threshold * ex          if ht <= th then @@ -149,9 +154,9 @@ end  local function correction_kern(kern,n)      local k = new_correction_kern(kern)      if n then -        local a = getfield(n,"attr") +        local a = getattrlist(n)          if a then -- maybe not -            setfield(k,"attr",a) -- can be a marked content (border case) +            setattrlist(k,a) -- can be a marked content (border case)          end      end      return k @@ -160,9 +165,9 @@ end  local function correction_glue(glue,n)      local g = new_correction_glue(glue)      if n then -        local a = getfield(n,"attr") +        local a = getattrlist(n)          if a then -- maybe not -            setfield(g,"attr",a) -- can be a marked content (border case) +            setattrlist(g,a) -- can be a marked content (border case)          end      end      return g @@ -195,12 +200,37 @@ local function domath(head,current, done)                              else                                  a = a + 100                              end -                            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) +                            local i = getkern(kern) +                            local f = getfont(glyph) +                            local c = getchar(glyph) +                            if getheight(next) < 1.25*exheights[f] then +                                if i == 0 then +                                    if trace_italics then +                                        report_italics("%s italic %p between math %C and punctuation %C","ignoring",i,c,char) +                                    end +                                else +                                    if trace_italics then +                                        report_italics("%s italic between math %C and punctuation %C","removing",i,c,char) +                                    end +                                    setkern(kern,0) -- or maybe a small value or half the ic +                                    done = true +                                end +                            elseif i == 0 then +                                local d = chardata[f][c] +                                local i = d.italic +                                if i == 0 then +                                    if trace_italics then +                                        report_italics("%s italic %p between math %C and punctuation %C","ignoring",i,c,char) +                                    end +                                else +                                    setkern(kern,i) +                                    if trace_italics then +                                        report_italics("%s italic %p between math %C and punctuation %C","setting",i,c,char) +                                    end +                                    done = true                                  end -                                setfield(kern,"kern",0) -- or maybe a small value or half the ic -                                done = true +                            elseif trace_italics then +                                report_italics("%s italic %p between math %C and punctuation %C","keeping",k,c,char)                              end                          end                      end @@ -253,7 +283,7 @@ local function texthandler(head)      local previnserted    = nil      local pre             = nil -    local pretail          = nil +    local pretail         = nil      local post            = nil      local posttail        = nil @@ -568,7 +598,7 @@ function italics.handler(head)  end  enabletext = function() -    tasks.enableaction("processors","typesetters.italics.handler") +    enableaction("processors","typesetters.italics.handler")      if trace_italics then          report_italics("enabling text/text italics")      end @@ -577,7 +607,7 @@ enabletext = function()  end  enablemath = function() -    tasks.enableaction("processors","typesetters.italics.handler") +    enableaction("processors","typesetters.italics.handler")      if trace_italics then          report_italics("enabling math/text italics")      end  | 
