From 40c16033d164a969e06aacc991371592731baf2a Mon Sep 17 00:00:00 2001
From: Hans Hagen <pragma@wxs.nl>
Date: Thu, 6 Jan 2022 20:05:31 +0100
Subject: 2022-01-06 19:50:00

---
 tex/generic/context/luatex/luatex-fonts-merged.lua | 378 +++++++++++++++------
 1 file changed, 277 insertions(+), 101 deletions(-)

(limited to 'tex/generic')

diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua
index f4d50e351..fdfde314f 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 : c:/data/develop/context/sources/luatex-fonts-merged.lua
 -- parent file : c:/data/develop/context/sources/luatex-fonts.lua
--- merge date  : 2021-12-30 19:00
+-- merge date  : 2022-01-06 19:47
 
 do -- begin closure to overcome local limits and interference
 
@@ -31585,8 +31585,10 @@ if not modules then modules={} end modules ['font-osd']={
  copyright="TAT Zetwerk / PRAGMA ADE / ConTeXt Development Team",
  license="see context related readme files"
 }
-local insert,imerge,copy,tohash=table.insert,table.imerge,table.copy,table.tohash
-local next,type=next,type
+local insert,remove,imerge,copy,tohash=table.insert,table.remove,table.imerge,table.copy,table.tohash
+local next,type,rawget=next,type,rawget
+local formatters=string.formatters
+local settings_to_hash=utilities.parsers.settings_to_hash
 local report=logs.reporter("otf","devanagari")
 fonts=fonts       or {}
 fonts.analyzers=fonts.analyzers   or {}
@@ -31596,6 +31598,7 @@ local handlers=otf.handlers
 local methods=fonts.analyzers.methods
 local otffeatures=fonts.constructors.features.otf
 local registerotffeature=otffeatures.register
+local trace_steps=false
 local nuts=nodes.nuts
 local getnext=nuts.getnext
 local getprev=nuts.getprev
@@ -31642,6 +31645,7 @@ replace_all_nbsp=function(head)
  return replace_all_nbsp(head)
 end
 local processcharacters=nil
+local logprocess=nil
 if context then
 
 --removed
@@ -31654,6 +31658,8 @@ else
   end
   return head
  end
+ logprocess=function(str)
+ end
 end
 local indicgroups=characters and characters.indicgroups
 if not indicgroups and characters then
@@ -31763,7 +31769,7 @@ local before_subscript=indicgroups.before_subscript
 local after_subscript=indicgroups.after_subscript
 local before_main=indicgroups.before_main
 local after_main=indicgroups.after_main
-local mark_four=table.merged (
+local mark_pre_above_below_post=table.merged (
  pre_mark,
  above_mark,
  below_mark,
@@ -31774,6 +31780,11 @@ local mark_above_below_post=table.merged (
  below_mark,
  post_mark
 )
+local devanagarihash=table.setmetatableindex(function(t,k)
+ local v=fontdata[k].resources.devanagari or false
+ t[k]=v
+ return v
+end)
 local zw_char={ 
  [c_zwnj]=true,
  [c_zwj ]=true,
@@ -31894,7 +31905,7 @@ local function initializedevanagi(tfmdata)
   local resources=tfmdata.resources
   local devanagari=resources.devanagari
   if not devanagari then
-   report("adding devanagari features to font")
+   report("adding features to font")
    local gsubfeatures=resources.features.gsub
    local sequences=resources.sequences
    local sharedfeatures=tfmdata.shared.features
@@ -31921,7 +31932,7 @@ local function initializedevanagi(tfmdata)
          for k,v in next,pre_mark do
           local locl=coverage[k]
           if locl then
-           if #locl>0 then	
+           if #locl>0 then
             for j=1,#locl do
              local ck=locl[j]
              local f=ck[4]
@@ -31942,6 +31953,7 @@ local function initializedevanagi(tfmdata)
               end
              end
             end
+           else
            end
            if locl then
             reorder_matras.steps[1].coverage[locl]=true
@@ -31954,7 +31966,7 @@ local function initializedevanagi(tfmdata)
       if basic_shaping_forms[k] then
        lastmatch=lastmatch+1
        if s~=lastmatch then
-        table.insert(sequences,lastmatch,table.remove(sequences,s))
+        insert(sequences,lastmatch,remove(sequences,s))
        end
       end
      end
@@ -31972,9 +31984,7 @@ local function initializedevanagi(tfmdata)
    local vatucache={}
    local pstfcache={}
    local seqsubset={}
-   local rephstep={
-    coverage={} 
-   }
+   local rephstep={ coverage={} } 
    local devanagari={
     reph=false,
     vattu=false,
@@ -31999,7 +32009,7 @@ local function initializedevanagi(tfmdata)
     local has_pstf=features.pstf
     if has_rphf and has_rphf[script] then
      devanagari.reph=true
-    elseif (has_blwf and has_blwf[script] ) or (has_vatu and has_vatu[script] ) then
+    elseif (has_blwf and has_blwf[script]) or (has_vatu and has_vatu[script]) then
      devanagari.vattu=true
      for i=1,nofsteps do
       local step=steps[i]
@@ -32007,10 +32017,8 @@ local function initializedevanagi(tfmdata)
       if coverage then
        for k,v in next,coverage do
         for h,w in next,halant do
-         if v[h] then
-          if not blwfcache[k] then
-           blwfcache[k]=v
-          end
+         if v[h] and not blwfcache[k] then
+          blwfcache[k]=v
          end
          if has_vatu and has_vatu[script] and not vatucache[k] then
           vatucache[k]=v
@@ -32033,33 +32041,37 @@ local function initializedevanagi(tfmdata)
         local r=coverage[k]
         if r then
          local found=false
-         if #r>0 then  
+         if #r>0 then
           for j=1,#r do
            local ck=r[j]
            local f=ck[4]
            local chainlookups=ck[6]
-           if chainlookups and chainlookups[f] then	
+           if chainlookups then
             local chainlookup=chainlookups[f]
-            for j=1,#chainlookup do
-             local chainstep=chainlookup[j]
-             local steps=chainstep.steps
-             local nofsteps=chainstep.nofsteps
-             for i=1,nofsteps do
-              local step=steps[i]
-              local coverage=step.coverage
-              if coverage then
-               local h=coverage[k]
-               if h then
-                for k,v in next,h do
-                 found=v and (tonumber(v) or v.ligature)
+            if chainlookup then
+             for j=1,#chainlookup do
+              local chainstep=chainlookup[j]
+              local steps=chainstep.steps
+              local nofsteps=chainstep.nofsteps
+              for i=1,nofsteps do
+               local step=steps[i]
+               local coverage=step.coverage
+               if coverage then
+                local h=coverage[k]
+                if h then
+                 for k,v in next,h do
+                  if v then
+                   found=tonumber(v) or v.ligature
+                   if found then
+                    pre_base_reordering_consonants[found]=true
+                    break
+                   end
+                  end
+                 end
                  if found then
-                  pre_base_reordering_consonants[found]=true
                   break
                  end
                 end
-                if found then
-                 break
-                end
                end
               end
              end
@@ -32068,10 +32080,12 @@ local function initializedevanagi(tfmdata)
           end
          else
           for k,v in next,r do
-           found=v and (tonumber(v) or v.ligature)
-           if found then
-            pre_base_reordering_consonants[found]=true
-            break
+           if v then
+            found=tonumber(v) or v.ligature
+            if found then
+             pre_base_reordering_consonants[found]=true
+             break
+            end
            end
           end
          end
@@ -32089,14 +32103,15 @@ local function initializedevanagi(tfmdata)
        local step=steps[i]
        local coverage=step.coverage
        if coverage then
-        local reph,rephbase=false,false
+        local reph=false
+        local base=false
         if kind=="rphf" then
          for k,v in next,ra do
           local r=coverage[k]
           if r then
-           rephbase=k
+           base=k
            local h=false
-           if #r>0 then	
+           if #r>0 then
             for j=1,#r do
              local ck=r[j]
              local f=ck[4]
@@ -32144,7 +32159,7 @@ local function initializedevanagi(tfmdata)
           end
          end
         end
-        seqsubset[#seqsubset+1]={ kind,coverage,reph,rephbase }
+         seqsubset[#seqsubset+1]={ kind,coverage,reph,base }
        end
       end
      end
@@ -32159,7 +32174,7 @@ local function initializedevanagi(tfmdata)
          local h=coverage[k]
          if h then
           local found=false
-          if #h>0 then 
+          if #h>0 then
            for j=1,#h do
             local ck=h[j]
             local f=ck[4]
@@ -32177,10 +32192,12 @@ local function initializedevanagi(tfmdata)
                 local h=coverage[k]
                 if h then
                  for k,v in next,h do
-                  found=v and (tonumber(v) or v.ligature)
-                  if found then
-                   pre_base_reordering_consonants[found]=true
-                   break
+                  if v then
+                   found=tonumber(v) or v.ligature
+                   if found then
+                    pre_base_reordering_consonants[found]=true
+                    break
+                   end
                   end
                  end
                  if found then
@@ -32220,9 +32237,6 @@ local function initializedevanagi(tfmdata)
     sharedfeatures["dv03"]=true 
     sharedfeatures["dv04"]=true 
    end
-   if script=="mlym" or script=="taml" then
-    devanagari.left_matra_before_base=true
-   end
   end
  end
 end
@@ -32234,6 +32248,43 @@ registerotffeature {
   node=initializedevanagi,
  },
 }
+local function initializeconjuncts(tfmdata,value)
+ if value then
+  local resources=tfmdata.resources
+  local devanagari=resources.devanagari
+  if devanagari then
+   local conjuncts="auto"
+   local conjuncts="continue"
+   local movematra="auto"
+   if type(value)=="string" and value~="auto" then
+    value=settings_to_hash(value)
+    conjuncts=rawget(value,"conjuncts") or conjuncts
+    movematra=rawget(value,"movematra") or movematra
+   end
+   if conjuncts=="auto" then
+    conjuncts="continue"
+   end
+   if movematra=="auto" and
+      script=="mlym" or
+      script=="taml" then
+    movematra="leftbeforebase"
+   else
+    movematra="default"
+   end
+   devanagari.conjuncts=conjuncts
+   devanagari.movematra=movematra
+    report("conjuncts %a, movematra %a",conjuncts,movematra)
+  end
+ end
+end
+registerotffeature {
+ name="indic",
+ description="control indic",
+ default="auto",
+ initializers={
+  node=initializeconjuncts,
+ },
+}
 local show_syntax_errors=false
 local function inject_syntax_error(head,current,char)
  local signal=copy_node(current)
@@ -32341,9 +32392,9 @@ local function order_matras(c)
   char=getchar(cn)
  end
 end
+local swapped=table.swapped(states)
 local function reorder_one(head,start,stop,font,attr,nbspaces)
- local reph,vattu,blwfcache,vatucache,pstfcache=initialize_one(font,attr) 
- local devanagari=fontdata[font].resources.devanagari
+ local reph,vattu,blwfcache,vatucache,pstfcache=initialize_one(font,attr)
  local current=start
  local n=getnext(start)
  local base=nil
@@ -32366,6 +32417,9 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
    stop=getprev(stop)
    head=remove_node(head,current)
    flushnode(current)
+   if trace_steps then
+    logprocess("reorder one, remove nbsp")
+   end
    return head,stop,nbspaces
   else
    nbspaces=nbspaces+1
@@ -32409,6 +32463,9 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
         stop=current
        end
       end
+      if trace_steps then
+       logprocess("reorder one, handle nbsp")
+      end
      end
     end
    end
@@ -32463,6 +32520,9 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
    if lastcons==stop then
     stop=n
    end
+   if trace_steps then
+    logprocess("reorder one, handle halant")
+   end
   end
  end
  n=getnext(start)
@@ -32487,6 +32547,9 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
   if matra==stop then
    stop=n
   end
+  if trace_steps then
+   logprocess("reorder one, handle matra")
+  end
  end
  local current=start
  while current~=stop do
@@ -32525,14 +32588,19 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
      ch=getchar(n)
     end
     local tpm=twopart_mark[ch]
-    while tpm do
-     local extra=copy_node(n)
-     copyinjection(extra,n)
-     ch=tpm[1]
-     setchar(n,ch)
-     setchar(extra,tpm[2])
-     head=insertnodeafter(head,current,extra)
-     tpm=twopart_mark[ch]
+    if tpm then
+     while tpm do
+      local extra=copy_node(n)
+      copyinjection(extra,n)
+      ch=tpm[1]
+      setchar(n,ch)
+      setchar(extra,tpm[2])
+      head=insertnodeafter(head,current,extra)
+      tpm=twopart_mark[ch]
+     end
+     if trace_steps then
+      logprocess("reorder one, handle mark")
+     end
     end
     while c~=stop and dependent_vowel[ch] do
      c=n
@@ -32555,9 +32623,10 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
   local bp=getprev(firstcons)
   local cn=getnext(current)
   local last=getnext(c)
+  local done=false
   while cn~=last do
    if pre_mark[getchar(cn)] then
-    if devanagari.left_matra_before_base then
+    if devanagarihash[font].movematra=="leftbeforebase" then
      local prev,next=getboth(cn)
      setlink(prev,next)
      if cn==stop then
@@ -32594,6 +32663,7 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
      end
      cn=next
     end
+    done=true
    elseif current~=base and dependent_vowel[getchar(cn)] then
     local prev,next=getboth(cn)
     if next then
@@ -32606,6 +32676,7 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
     setlink(b,cn,getnext(b))
     order_matras(cn)
     cn=next
+    done=true
    elseif current==base and dependent_vowel[getchar(cn)] then
     local cnn=getnext(cn)
     order_matras(cn)
@@ -32619,9 +32690,14 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
   end
   allreordered=c==stop
   current=getnext(c)
+  if done and trace_steps then
+   logprocess("reorder one, matra")
+  end
  end
  if reph or vattu then
-  local current,cns=start,nil
+  local current=start
+  local cns=nil
+  local done=false
   while current~=stop do
    local c=current
    local n=getnext(current)
@@ -32652,6 +32728,7 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
       local next=getnext(b)
       setlink(c,next)
       setlink(b,current)
+      done=true
      end
     elseif cns and getnext(cns)~=current then
      local cp=getprev(current)
@@ -32659,6 +32736,7 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
      setlink(cp,n)
      setlink(cns,current) 
      setlink(c,cnsn)
+     done=true
      if c==stop then
       stop=cp
       break
@@ -32698,6 +32776,9 @@ local function reorder_one(head,start,stop,font,attr,nbspaces)
    end
    current=getnext(current)
   end
+  if done and trace_steps then
+   logprocess("reorder one, handle reph and vata") 
+  end
  end
  if getchar(base)==c_nbsp then
   nbspaces=nbspaces-1
@@ -32730,6 +32811,9 @@ function handlers.devanagari_reorder_matras(head,start)
     setlink(start,next)
     setlink(current,start)
     start=startnext
+    if trace_steps then
+     logprocess("reorder matra")
+    end
     break
    end
   else
@@ -32758,6 +32842,9 @@ function handlers.devanagari_reorder_reph(head,start)
    local char=ischar(current,startfont)
    if char and getprop(current,a_syllabe)==startattr then
     if halant[char] then
+     if trace_steps then
+      logprocess("reorder reph, handling halant")
+     end
      local next=getnext(current)
      if next then
       local nextchar=ischar(next,startfont)
@@ -32788,6 +32875,9 @@ function handlers.devanagari_reorder_reph(head,start)
     local char=ischar(current,startfont)
     if char and getprop(current,a_syllabe)==startattr then
      if consonant[char] and not getstate(current,s_pref) then
+      if trace_steps then
+       logprocess("reorder reph, handling consonant")
+      end
       startnext=getnext(start)
       head=remove_node(head,start)
       setlink(current,start)
@@ -32812,6 +32902,9 @@ function handlers.devanagari_reorder_reph(head,start)
     local char=ischar(current,startfont)
     if char and getprop(current,a_syllabe)==startattr then
      if getstate(current,s_pstf) then 
+      if trace_steps then
+       logprocess("reorder reph, before postscript, post base")
+      end
       startnext=getnext(start)
       head=remove_node(head,start)
       setlink(getprev(current),start)
@@ -32825,6 +32918,9 @@ function handlers.devanagari_reorder_reph(head,start)
      current=getnext(current)
     else
      if c then
+      if trace_steps then
+       logprocess("reorder reph, before postscript")
+      end
       startnext=getnext(start)
       head=remove_node(head,start)
       setlink(getprev(c),start)
@@ -32847,7 +32943,13 @@ function handlers.devanagari_reorder_reph(head,start)
     local state=getstate(current)
     if before_subscript[rephbase] and (state==s_blwf or state==s_pstf) then
      c=current
+     if trace_steps then
+      logprocess("reorder reph, before subscript")
+     end
     elseif after_subscript[rephbase] and (state==s_pstf) then
+     if trace_steps then
+      logprocess("reorder reph, after subscript")
+     end
      c=current
     end
     current=getnext(current)
@@ -32878,6 +32980,9 @@ function handlers.devanagari_reorder_reph(head,start)
    end
   end
   if start~=current then
+   if trace_steps then
+    logprocess("reorder reph, to end")
+   end
    startnext=getnext(start)
    head=remove_node(head,start)
    setlink(start,getnext(current))
@@ -32899,6 +33004,9 @@ function handlers.devanagari_reorder_pre_base_reordering_consonants(head,start)
   local next=getnext(current)
   if char and getprop(current,a_syllabe)==startattr then
    if halant[char] then 
+    if trace_steps then
+     logprocess("reorder pre base consonants, handle halant")
+    end
     if next then
      local char=ischar(next,startfont)
      if char and zw_char[char] and getprop(next,a_syllabe)==startattr then
@@ -32924,6 +33032,9 @@ function handlers.devanagari_reorder_pre_base_reordering_consonants(head,start)
  while current and getprop(current,a_syllabe)==startattr do
   local char=ischar(current)
   if (not dependent_vowel[char] and (not getstate(current) or getstate(current,s_init))) then
+   if trace_steps then
+    logprocess("reorder pre base consonants, handle vowel or initial")
+   end
    startnext=getnext(start)
    head=remove_node(head,start)
    if current==head then
@@ -32965,6 +33076,9 @@ function handlers.devanagari_remove_joiners(head,start,kind,lookupname,replaceme
   head=stop
  end
  flushlist(start)
+ if trace_steps then
+  logprocess("remove joiners")
+ end
  return head,stop,true
 end
 local function initialize_two(font,attr)
@@ -32981,15 +33095,17 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
  local basepos=nil
  local subpos=nil
  local postpos=nil
- reorderreph.coverage={}
- rephbase[font]={}
+ reorderreph.coverage={} 
+ rephbase[font]={} 
  for i=1,#seqsubset do
   local subset=seqsubset[i]
   local kind=subset[1]
   local lookupcache=subset[2]
   if kind=="rphf" then
-   reorderreph.coverage[subset[3]]=true 
-   rephbase[font][subset[3]]=subset[4]
+   local reph=subset[3]
+   local base=subset[4]
+   reorderreph.coverage[reph]=true 
+   rephbase[font][reph]=base
    local current=start
    local last=getnext(stop)
    while current~=last do
@@ -33004,9 +33120,9 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
         current=afternext 
        elseif current==start then
         setstate(current,s_rphf)
-        current=next
+        current=next 
        else
-        current=next
+        current=next 
        end
       end
      end
@@ -33023,7 +33139,7 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
      if found then 
       local next=getnext(current)
       if contextchain(found,next) then
-       if (not getstate(current) and not getstate(next)) then	
+       if not getstate(current) and not getstate(next) then 
         setstate(current,s_pref)
         setstate(next,s_pref)
         current=next
@@ -33045,7 +33161,7 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
       if contextchain(found,next) then
        if next~=stop and getchar(getnext(next))==c_zwnj then 
         current=next
-       elseif (not getstate(current)) then	
+       elseif not getstate(current) then 
         setstate(current,s_half)
         if not halfpos then
          halfpos=current
@@ -33067,7 +33183,7 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
      if found then
       local next=getnext(current)
       if contextchain(found,next) then
-       if (not getstate(current) and not getstate(next)) then 
+       if not getstate(current) and not getstate(next) then 
         setstate(current,s_blwf)
         setstate(next,s_blwf)
         current=next
@@ -33088,7 +33204,7 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
      if found then
       local next=getnext(current)
       if contextchain(found,next) then
-       if (not getstate(current) and not getstate(next)) then 
+       if not getstate(current) and not getstate(next) then 
         setstate(current,s_pstf)
         setstate(next,s_pstf)
         current=next
@@ -33110,6 +33226,9 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
    stop=getprev(stop)
    head=remove_node(head,current)
    flushnode(current)
+   if trace_steps then
+    logprocess("reorder two, remove nbsp")
+   end
    return head,stop,nbspaces
   else
    nbspaces=nbspaces+1
@@ -33150,6 +33269,9 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
      end
     end
    end
+   if trace_steps then
+    logprocess("reorder two, handle nbsp")
+   end
   end
  else 
   local last=getnext(stop)
@@ -33200,14 +33322,19 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
   local target=nil
   local cn=getnext(current)
   local tpm=twopart_mark[char]
-  while tpm do
-   local extra=copy_node(current)
-   copyinjection(extra,current)
-   char=tpm[1]
-   setchar(current,char)
-   setchar(extra,tpm[2])
-   head=insertnodeafter(head,current,extra)
-   tpm=twopart_mark[char]
+  if tpm then
+   while tpm do
+    local extra=copy_node(current)
+    copyinjection(extra,current)
+    char=tpm[1]
+    setchar(current,char)
+    setchar(extra,tpm[2])
+    head=insertnodeafter(head,current,extra)
+    tpm=twopart_mark[char]
+   end
+   if tpm and trace_steps then
+    logprocess("reorder two, handle matra")
+   end
   end
   if not moved[current] and dependent_vowel[char] then
    if pre_mark[char] then 
@@ -33248,6 +33375,9 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
     end
     setlink(getprev(pos),current)
     setlink(current,pos)
+    if trace_steps then
+     logprocess("reorder two, handle pre mark")
+    end
    elseif above_mark[char] then
     target=basepos
     if subpos==basepos then
@@ -33287,6 +33417,9 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
      end
      setlink(current,getnext(target))
      setlink(target,current)
+     if trace_steps then
+      logprocess("reorder two, handle mark")
+     end
     end
    end
   end
@@ -33314,6 +33447,9 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
       stop=prev
      end
      cn=next
+     if trace_steps then
+      logprocess("reorder two, handle halant and ra")
+     end
     end
    end
   end
@@ -33346,6 +33482,9 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
     setprev(nextnextnext,current)
    end
    setlink(nextnext,c)
+   if trace_steps then
+    logprocess("reorder two, handle nukta")
+   end
   end
   if stop==current then break end
   current=getnext(current)
@@ -33357,6 +33496,9 @@ local function reorder_two(head,start,stop,font,attr,nbspaces)
   nbspaces=nbspaces-1
   head=remove_node(head,base)
   flushnode(base)
+  if trace_steps then
+   logprocess("reorder two, handle nbsp")
+  end
  end
  return head,stop,nbspaces
 end
@@ -33444,21 +33586,38 @@ local function analyze_next_chars_one(c,font,variant)
  local already_below_mark 
  local already_post_mark  
  while dependent_vowel[v] do
-  local vowels=twopart_mark[v] or { v }
-  for k,v in next,vowels do
-   if pre_mark[v] and not already_pre_mark then
+  local vowels=twopart_mark[v]
+  if vowels then
+   for k=1,#vowels do
+    local v=vowels[k]
+    if pre_mark[v] and not already_pre_mark then
+     already_pre_mark=true
+    elseif above_mark[v] and not already_above_mark then
+     already_above_mark=true
+    elseif below_mark[v] and not already_below_mark then
+     already_below_mark=true
+    elseif post_mark[v] and not already_post_mark then
+     already_post_mark=true
+    elseif devanagarihash[font].conjuncts=="quit" then
+     return c
+    end
+   end
+  else
+   if devanagarihash[font].conjuncts=="quit" then
+    return c
+   elseif pre_mark[v] and not already_pre_mark then
     already_pre_mark=true
-   elseif above_mark[v] and not already_above_mark then
-    already_above_mark=true
-   elseif below_mark[v] and not already_below_mark then
-    already_below_mark=true
    elseif post_mark[v] and not already_post_mark then
     already_post_mark=true
+   elseif below_mark[v] and not already_below_mark then
+    already_below_mark=true
+   elseif above_mark[v] and not already_above_mark then
+    already_above_mark=true
    else
     return c
    end
   end
-  c=getnext(c)
+  c=n
   n=getnext(c)
   if not n then
    return c
@@ -33469,7 +33628,7 @@ local function analyze_next_chars_one(c,font,variant)
   end
  end
  if nukta[v] then
-  c=getnext(c)
+  c=n
   n=getnext(c)
   if not n then
    return c
@@ -33480,7 +33639,7 @@ local function analyze_next_chars_one(c,font,variant)
   end
  end
  if halant[v] then
-  c=getnext(c)
+  c=n
   n=getnext(c)
   if not n then
    return c
@@ -33491,7 +33650,7 @@ local function analyze_next_chars_one(c,font,variant)
   end
  end
  if vowel_modifier[v] then
-  c=getnext(c)
+  c=n
   n=getnext(c)
   if not n then
    return c
@@ -33502,7 +33661,7 @@ local function analyze_next_chars_one(c,font,variant)
   end
  end
  if stress_tone_mark[v] then
-  c=getnext(c)
+  c=n
   n=getnext(c)
   if not n then
    return c
@@ -33626,18 +33785,35 @@ local function analyze_next_chars_two(c,font)
   local already_pre_mark   
   local already_above_mark 
   local already_below_mark 
-  local already_post_mark  
+  local already_post_mark
   while dependent_vowel[v] do
-   local vowels=twopart_mark[v] or { v }
-   for k,v in next,vowels do
-    if pre_mark[v] and not already_pre_mark then
+   local vowels=twopart_mark[v]
+   if vowels then
+    for k=1,#vowels do
+     local v=vowels[k]
+     if pre_mark[v] and not already_pre_mark then
+      already_pre_mark=true
+     elseif above_mark[v] and not already_above_mark then
+      already_above_mark=true
+     elseif below_mark[v] and not already_below_mark then
+      already_below_mark=true
+     elseif post_mark[v] and not already_post_mark then
+      already_post_mark=true
+     elseif devanagarihash[font].conjuncts=="quit" then
+      return c
+     end
+    end
+   else
+    if devanagarihash[font].conjuncts=="quit" then
+     return c
+    elseif pre_mark[v] and not already_pre_mark then
      already_pre_mark=true
-    elseif above_mark[v] and not already_above_mark then
-     already_above_mark=true
-    elseif below_mark[v] and not already_below_mark then
-     already_below_mark=true
     elseif post_mark[v] and not already_post_mark then
      already_post_mark=true
+    elseif below_mark[v] and not already_below_mark then
+     already_below_mark=true
+    elseif above_mark[v] and not already_above_mark then
+     already_above_mark=true
     else
      return c
     end
@@ -33876,7 +34052,7 @@ local function method_one(head,font,attr)
      end
     else
      if show_syntax_errors then
-      local mark=mark_four[char]
+      local mark=mark_pre_above_below_post[char]
       if mark then
        head,current=inject_syntax_error(head,current,char)
       end
@@ -33975,7 +34151,7 @@ local function method_two(head,font,attr)
   if not syllableend and show_syntax_errors then
    local char=ischar(current,font)
    if char and not getstate(current) then 
-    local mark=mark_four[char]
+    local mark=mark_pre_above_below_post[char]
     if mark then
      head,current=inject_syntax_error(head,current,char)
     end
-- 
cgit v1.2.3