# Discretionary Ligatures
# https://learn.microsoft.com/en-us/typography/opentype/spec/features_ae#dlig

# Set IgnoreMarks to skip over marks in lookups.
# For example, if we have /f/acutecomb/i, treat lookup as /f/i
# https://learn.microsoft.com/en-us/typography/opentype/spec/chapter2#lookup-table
lookupflag IgnoreMarks;

# fi
sub f' [
  i idotless idotless.double itildebelow ibar igrave iacute iogonek
  ihookabove idotbelow icyrillic ij i.sc

  j jdotless jdotlessbar uni0249 uni0249.ccmp jcrosstail yotgreek jecyrillic
] by f.i;

# ff -> ff'
@DLIG_f_L = [ f fdotaccent feng ];
@DLIG_f_R = [ f.1 fdotaccent.1 feng.1 ];

# tt -> tt'
@DLIG_t_L = [
  t tpalatalhook tcedilla tcaron tcommaaccent tdotaccent tdotbelow
  tlinebelow tcircumflexbelow tdieresis
];

@DLIG_t_R = [
  t.1 tpalatalhook.1 tcedilla.1 tcaron.1 tcommaaccent.1 tdotaccent.1 tdotbelow.1
  tlinebelow.1 tcircumflexbelow.1 tdieresis.1
];

# left side "trigger" glyph for t.1 and f.1 sub
@DLIG_t1_L = [
  @DLIG_f_L @DLIG_f_R

  k khook kcommaaccent kcaron kacute kdotbelow klinebelow k.base

  r rrthook uni024D rfishhook rdescend racute rcommaaccent rcaron
  rdblgrave rinvertedbreve rdotaccent rdotbelow rdotbelowmacron rlinebelow

  @DLIG_t_L @DLIG_t_R

  v vtilde vdotbelow

  w wdieresis wcircumflex wgrave wacute wdotaccent wdotbelow wring

  x xdotaccent xdieresis khacyrillic chi

  y ydieresis uni024F yacute ycircumflex uni0233 ydotaccent yring ygrave ydotbelow
  yhookabove ytilde ucyrillic ushortcyrillic umacroncyrillic udieresiscyrillic
  uhungarumlautcyrillic yogonek y.sc

  # lower case glyphs with long ("beyond x-height") left vertical stroke
  d dcroat drthook dhook dtopbar dcurl ddotaccent ddotbelow dlinebelow dcedilla
  dcircumflexbelow dong

  l lslash lbar lmidtilde lrthook lbelt lcurl ldot lacute
  lcommaaccent lcaron
  ldotbelow ldotbelowmacron llinebelow lcircumflexbelow
  l.ss02 lslash.ss02 lbar.ss02 lmidtilde.ss02 lbelt.ss02 ldot.ss02 lacute.ss02
  lcommaaccent.ss02 lcaron.ss02
  ldotbelow.ss02 ldotbelowmacron.ss02 llinebelow.ss02 lcircumflexbelow.ss02

];


# ffi (note. f.i is sub'd by liga)
sub f [ f f.i ]' i by f.i.1;

# tt, ft, rt, tf, ff, ft ...
sub @DLIG_t1_L @DLIG_t_L' by @DLIG_t_R;
sub @DLIG_t1_L @DLIG_f_L' by @DLIG_f_R;

# interrobang
sub exclam question by interrobang;
sub question exclam by interrobang;
sub exclamdown questiondown by invertedinterrobang;
sub questiondown exclamdown by invertedinterrobang;
