From 05c1a1f336a3148f9f8e3b02e3944deaebb0357f Mon Sep 17 00:00:00 2001
From: Philipp Gesang <phg@phi-gamma.net>
Date: Wed, 27 Apr 2016 19:09:28 +0200
Subject: [fontloader] sync with Context as of 2016-04-27

---
 src/fontloader/misc/fontloader-font-dsp.lua |  2 +-
 src/fontloader/misc/fontloader-font-ots.lua | 30 ++++++++++++++++++-----------
 2 files changed, 20 insertions(+), 12 deletions(-)

(limited to 'src/fontloader/misc')

diff --git a/src/fontloader/misc/fontloader-font-dsp.lua b/src/fontloader/misc/fontloader-font-dsp.lua
index 14e816d..85a80bd 100644
--- a/src/fontloader/misc/fontloader-font-dsp.lua
+++ b/src/fontloader/misc/fontloader-font-dsp.lua
@@ -525,7 +525,7 @@ local function chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nof
                             end
                         end
                         local noflookups = readushort(f)
-                        local lookups = { }
+                        local lookups    = { }
                         for i=1,noflookups do
                             lookups[readushort(f)+1] = readushort(f) + 1
                         end
diff --git a/src/fontloader/misc/fontloader-font-ots.lua b/src/fontloader/misc/fontloader-font-ots.lua
index ac81989..90fcde2 100644
--- a/src/fontloader/misc/fontloader-font-ots.lua
+++ b/src/fontloader/misc/fontloader-font-ots.lua
@@ -2144,7 +2144,7 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode)
                 else
                     local discfound = nil
                     local n = f + 1
-                    last = getnext(last)
+                    last = getnext(last) -- the second in current (first already matched)
                     while n <= l do
                         if not last and (sweeptype == "post" or sweeptype == "replace") then
                             last      = getnext(sweepnode)
@@ -2185,7 +2185,6 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode)
                                     end
                                     break
                                 end
-                                last = getnext(last)
                             elseif char == false then
                                 if discfound then
                                     notmatchreplace[discfound] = true
@@ -2238,6 +2237,7 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode)
                                     end
                                     match = not notmatchpre[last]
                                 end
+                                -- maybe only if match
                                 last = getnext(last)
                             else
                                 match = false
@@ -2273,8 +2273,12 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode)
                                             if trace_skips then
                                                 show_skip(dataset,sequence,char,ck,class)
                                             end
+                                            prev = getprev(prev) -- moved here
                                         elseif seq[n][char] then
-                                            n = n -1
+                                            if n > 1 then -- new test
+                                                prev = getprev(prev) -- moved here
+                                            end
+                                            n = n - 1
                                         else
                                             if discfound then
                                                 notmatchreplace[discfound] = true
@@ -2293,7 +2297,7 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode)
                                         end
                                         break
                                     end
-                                    prev = getprev(prev)
+                                 -- prev = getprev(prev) -- moved up
                                 elseif char == false then
                                     if discfound then
                                         notmatchreplace[discfound] = true
@@ -2357,21 +2361,20 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode)
                                             if not match then
                                                 break
                                             end
-                                        else
-                                            -- skip 'm
                                         end
-                                    else
-                                        -- skip 'm
                                     end
+                                    -- maybe only if match
+                                    prev = getprev(prev)
                                 elseif seq[n][32] then
                                     n = n - 1
+                                    prev = getprev(prev)
                                 else
                                     match = false
                                     break
                                 end
-                                prev = getprev(prev)
                             elseif seq[n][32] then -- somewhat special, as zapfino can have many preceding spaces
                                 n = n - 1
+                                prev = getprev(prev) -- was absent
                             else
                                 match = false
                                 break
@@ -2409,7 +2412,11 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode)
                                         if trace_skips then
                                             show_skip(dataset,sequence,char,ck,class)
                                         end
+                                        current = getnext(current) -- was absent
                                     elseif seq[n][char] then
+                                        if n < s then -- new test
+                                            current = getnext(current) -- was absent
+                                        end
                                         n = n + 1
                                     else
                                         if discfound then
@@ -2485,16 +2492,17 @@ local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode)
                                 else
                                     -- skip 'm
                                 end
+                                -- maybe only if match
+                                current = getnext(current)
                             elseif seq[n][32] then -- brrr
                                 n = n + 1
                             else
                                 match = false
                                 break
                             end
-                            current = getnext(current)
                         elseif seq[n][32] then
                             n = n + 1
-current = getnext(current)
+                            current = getnext(current)
                         else
                             match = false
                             break
-- 
cgit v1.2.3