Ignore CGJ and Mongolian Variation Selectors during GPOS

Fixes https://github.com/harfbuzz/harfbuzz/issues/4869
diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh
index 0dc3bce..0676fbe 100644
--- a/src/hb-ot-layout-gsubgpos.hh
+++ b/src/hb-ot-layout-gsubgpos.hh
@@ -406,6 +406,7 @@
 
     void set_ignore_zwnj (bool ignore_zwnj_) { ignore_zwnj = ignore_zwnj_; }
     void set_ignore_zwj (bool ignore_zwj_) { ignore_zwj = ignore_zwj_; }
+    void set_ignore_hidden (bool ignore_hidden_) { ignore_hidden = ignore_hidden_; }
     void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; }
     void set_mask (hb_mask_t mask_) { mask = mask_; }
     void set_per_syllable (bool per_syllable_) { per_syllable = per_syllable_; }
@@ -451,9 +452,10 @@
       if (!c->check_glyph_property (&info, lookup_props))
 	return SKIP_YES;
 
-      if (unlikely (_hb_glyph_info_is_default_ignorable_and_not_hidden (&info) &&
+      if (unlikely (_hb_glyph_info_is_default_ignorable (&info) &&
 		    (ignore_zwnj || !_hb_glyph_info_is_zwnj (&info)) &&
-		    (ignore_zwj || !_hb_glyph_info_is_zwj (&info))))
+		    (ignore_zwj || !_hb_glyph_info_is_zwj (&info)) &&
+		    (ignore_hidden || !_hb_glyph_info_is_hidden (&info))))
 	return SKIP_MAYBE;
 
       return SKIP_NO;
@@ -464,6 +466,7 @@
     hb_mask_t mask = -1;
     bool ignore_zwnj = false;
     bool ignore_zwj = false;
+    bool ignore_hidden = false;
     bool per_syllable = false;
     uint8_t syllable = 0;
     match_func_t match_func = nullptr;
@@ -486,6 +489,8 @@
       matcher.set_ignore_zwnj (c->table_index == 1 || (context_match && c->auto_zwnj));
       /* Ignore ZWJ if we are matching context, or asked to. */
       matcher.set_ignore_zwj  (context_match || c->auto_zwj);
+      /* Ignore hidden glyphs (like CGJ) during GPOS. */
+      matcher.set_ignore_hidden (c->table_index == 1);
       matcher.set_mask (context_match ? -1 : c->lookup_mask);
       /* Per syllable matching is only for GSUB. */
       matcher.set_per_syllable (c->table_index == 0 && c->per_syllable);
diff --git a/src/hb-ot-layout.hh b/src/hb-ot-layout.hh
index 591f7a2..3a8d36a 100644
--- a/src/hb-ot-layout.hh
+++ b/src/hb-ot-layout.hh
@@ -178,7 +178,7 @@
  *   * Is it Default_Ignorable(); we have a modified Default_Ignorable().
  *   * Whether it's one of the four Mongolian Free Variation Selectors,
  *     CGJ, or other characters that are hidden but should not be ignored
- *     like most other Default_Ignorable()s do during matching.
+ *     like most other Default_Ignorable()s do during GSUB matching.
  *   * Whether it's a grapheme continuation.
  *
  * The high-byte has different meanings, switched by the Gen-Cat:
@@ -317,11 +317,9 @@
   info->unicode_props() &= ~ UPROPS_MASK_IGNORABLE;
 }
 static inline bool
-_hb_glyph_info_is_default_ignorable_and_not_hidden (const hb_glyph_info_t *info)
+_hb_glyph_info_is_hidden (const hb_glyph_info_t *info)
 {
-  return ((info->unicode_props() & (UPROPS_MASK_IGNORABLE|UPROPS_MASK_HIDDEN))
-	  == UPROPS_MASK_IGNORABLE) &&
-	 !_hb_glyph_info_substituted (info);
+  return info->unicode_props() & UPROPS_MASK_HIDDEN;
 }
 static inline void
 _hb_glyph_info_unhide (hb_glyph_info_t *info)
diff --git a/test/shape/data/in-house/fonts/cee442574141a0304e780b27dd872519f7d229db.ttf b/test/shape/data/in-house/fonts/cee442574141a0304e780b27dd872519f7d229db.ttf
new file mode 100644
index 0000000..5842bf7
--- /dev/null
+++ b/test/shape/data/in-house/fonts/cee442574141a0304e780b27dd872519f7d229db.ttf
Binary files differ
diff --git a/test/shape/data/in-house/tests/arabic-mark-order.tests b/test/shape/data/in-house/tests/arabic-mark-order.tests
index c089eb3..d16d7d8 100644
--- a/test/shape/data/in-house/tests/arabic-mark-order.tests
+++ b/test/shape/data/in-house/tests/arabic-mark-order.tests
@@ -3,4 +3,4 @@
 ../fonts/21b7fb9c1eeae260473809fbc1fe330f66a507cd.ttf;;U+0649,U+0655,U+034F,U+0650;[uni0650.small2=0@727,-774+0|space=0+0|uni0655=0@727,-209+0|uni0649=0+1566]
 ../fonts/21b7fb9c1eeae260473809fbc1fe330f66a507cd.ttf;;U+0649,U+0655,U+0650;[uni0650.small2=0@727,-774+0|uni0655=0@727,-209+0|uni0649=0+1566]
 ../fonts/21b7fb9c1eeae260473809fbc1fe330f66a507cd.ttf;;U+0649,U+0650,U+0655;[uni0650.small2=0@727,-774+0|uni0655=0@727,-209+0|uni0649=0+1566]
-../fonts/21b7fb9c1eeae260473809fbc1fe330f66a507cd.ttf;;U+0649,U+0650,U+034F,U+0655;[uni0655=0+0|space=0+0|uni0650=0@166,0+0|uni0649=0+1566]
+../fonts/21b7fb9c1eeae260473809fbc1fe330f66a507cd.ttf;;U+0649,U+0650,U+034F,U+0655;[uni0655=0@727,-209+0|space=0+0|uni0650=0@166,0+0|uni0649=0+1566]
diff --git a/test/shape/data/in-house/tests/default-ignorables.tests b/test/shape/data/in-house/tests/default-ignorables.tests
index 68659b2..62b56e1 100644
--- a/test/shape/data/in-house/tests/default-ignorables.tests
+++ b/test/shape/data/in-house/tests/default-ignorables.tests
@@ -1,5 +1,6 @@
 ../fonts/051d92f8bc6ff724511b296c27623f824de256e9.ttf;;U+0075,U+0361,U+034F,U+0301,U+0069;[gid2=0+1266|gid7=0@-617,442+0|gid5=0@-7,0+0|gid1=4+528]
-../fonts/bf962d3202883a820aed019d9b5c1838c2ff69c6.ttf;;U+0020,U+06CC,U+064E,U+034F,U+0651;[uni0651=1+0|space=1+0|uni064E=1@236,-432+0|uni06CC=1+1266|space=0+452]
+../fonts/bf962d3202883a820aed019d9b5c1838c2ff69c6.ttf;;U+0020,U+06CC,U+064E,U+034F,U+0651;[uni0651=1@252,-150+0|space=1+0|uni064E=1@236,-432+0|uni06CC=1+1266|space=0+452]
 ../fonts/6677074106f94a2644da6aaaacd5bbd48cbdc7de.ttf;;U+0647,U+200D;[terminal=0+0|uni0647.init=0+702]
 ../fonts/fcea341ba6489536390384d8403ce5287ba71a4a.ttf;;U+0647,U+200D;[uni0647200D=0+702]
 ../fonts/08b4b136f418add748dc641eb4a83033476f1170.ttf;;U+0647,U+200D;[terminal=0+0|terminal=0+0|uni0647.init=0+702]
+../fonts/cee442574141a0304e780b27dd872519f7d229db.ttf;;U+0635,U+0650,U+034F,U+0651,U+0627;[uni0627.fina=4+231|uni0651=0@285,-66+0|space=0+0|uni0650=0@318,-114+0|uni0635.init=0+838]
diff --git a/test/shape/data/in-house/tests/hebrew-diacritics.tests b/test/shape/data/in-house/tests/hebrew-diacritics.tests
index 6f6aaf6..4f1aabd 100644
--- a/test/shape/data/in-house/tests/hebrew-diacritics.tests
+++ b/test/shape/data/in-house/tests/hebrew-diacritics.tests
@@ -20,9 +20,9 @@
 ../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05D9,U+05B0,U+05E8,U+05D5,U+05BC,U+05E9,U+05C1,U+05B8,U+05DC,U+05B7,U+05B0,U+05DE,U+05B8,U+05D4;[he=13+1071|qamats=11@573,0+0|mem=11+1094|sheva=8@177,0+0|patah=8@499,0+0|lamed=8+901|qamats=5@665,0+0|shinshindot=5+1292|vavdagesh=3+510|resh=2+883|sheva=0@239,0+0|yod=0+454]
 ../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05D9,U+05B0,U+05E8,U+05D5,U+05BC,U+05E9,U+05C1,U+05B8,U+05DC,U+05B8,U+05B0,U+05DE,U+05B8,U+05D4;[he=13+1071|qamats=11@573,0+0|mem=11+1094|sheva=8@176,0+0|qamats=8@499,0+0|lamed=8+901|qamats=5@665,0+0|shinshindot=5+1292|vavdagesh=3+510|resh=2+883|sheva=0@239,0+0|yod=0+454]
 ../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05E0,U+05B0,U+05D1,U+05BB,U+05BD,U+05DB,U+05B7,U+05D3,U+05B0,U+05E0,U+05B6,U+05D0,U+05E6,U+05BC,U+05B7,U+05A3,U+05E8;[resh=16+883|munah=12@203,0+0|patah=12@588,0+0|tsadidagesh=12+968|alef=11+1048|segol=9@316,0+0|nun=9+614|sheva=7@621,0+0|dalet=7+879|patah=5@469,0+0|kaf=5+942|meteg=2@338,0+0|qubuts=2@673,0+0|bet=2+967|sheva=0@316,0+0|nun=0+614]
-../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05DE,U+05B4,U+05EA,U+05BC,U+05B8,U+0591,U+034F,U+05B7,U+059C,U+05D7,U+05B7,U+05EA;[tav=11+1026|patah=9@594,0+0|het=9+1065|gereshaccent=2+0|patah=2+0|space=2+0|atnah=2@437,0+0|qamats=2@794,0+0|tavdagesh=2+1026|hiriq=0@573,0+0|mem=0+1094]
+../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05DE,U+05B4,U+05EA,U+05BC,U+05B8,U+0591,U+034F,U+05B7,U+059C,U+05D7,U+05B7,U+05EA;[tav=11+1026|patah=9@594,0+0|het=9+1065|gereshaccent=2@728,0+0|patah=2@203,0+0|space=2+0|atnah=2@585,0+0|qamats=2@942,0+0|tavdagesh=2+1026|hiriq=0@573,0+0|mem=0+1094]
 ../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05D0,U+05B2,U+200D,U+05BD,U+05AD,U+05D3,U+05B7,U+05D1,U+05BC,U+05B0,U+05E8,U+05B8,U+05D4;[he=12+1071|qamats=10@719,0+0|resh=10+883|sheva=7@505,0+0|betdagesh=7+967|patah=5@621,0+0|dalet=5+879|dehi=0@1063,0+0|hatafpatah_meteg=0@593,0+0|alef=0+1048]
-../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05D5,U+05BD,U+034F,U+05B7,U+05D9,U+05B0,U+05D4,U+05B4,U+05D9,U+05BE,U+05AF,U+05DB,U+05B5,U+05BD,U+05DF;[finalnun=14+459|meteg=11@311,0+0|tsere=11@617,0+0|kaf=11+942|masoracircle=9@320,0+0|makaf=9+631|yod=8+454|hiriq=6@597,0+0|he=6+1071|sheva=4@239,0+0|yod=4+454|patah=0+0|space=0+0|meteg=0@349,0+0|vav=0+484]
+../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05D5,U+05BD,U+034F,U+05B7,U+05D9,U+05B0,U+05D4,U+05B4,U+05D9,U+05BE,U+05AF,U+05DB,U+05B5,U+05BD,U+05DF;[finalnun=14+459|meteg=11@311,0+0|tsere=11@617,0+0|kaf=11+942|masoracircle=9@320,0+0|makaf=9+631|yod=8+454|hiriq=6@597,0+0|he=6+1071|sheva=4@239,0+0|yod=4+454|patah=0@162,0+0|space=0+0|meteg=0@468,0+0|vav=0+484]
 ../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05DC,U+05C5,U+05C4,U+05D5,U+05BC,U+05DC,U+05B5,U+05C5,U+0597,U+05C4,U+05D0,U+05C5,U+05C4;[upperdot=10@594,0+0|lowerdot=10@594,0+0|alef=10+1048|upperdot=5@519,0+0|revia=5@601,0+0|lowerdot=5@519,0+0|tsere=5@499,0+0|lamed=5+901|vavdagesh=3+510|upperdot=0@519,0+0|lowerdot=0@519,0+0|lamed=0+901]
 ../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05D0,U+05B8,U+05E0,U+05BC,U+05B8,U+05BD,U+05D4;[he=6+1071|meteg=2@205,0+0|qamats=2@469,0+0|nundagesh=2+614|qamats=0@591,0+0|alef=0+1048]
 ../fonts/b895f8ff06493cc893ec44de380690ca0074edfa.ttf;;U+05D0,U+05B8,U+05E0,U+05B8,U+05BC,U+05BD,U+05D4;[he=6+1071|meteg=2@205,0+0|qamats=2@469,0+0|nundagesh=2+614|qamats=0@591,0+0|alef=0+1048]