Apostrophe height in small caps with a special font

You can substituate glyphs conditionally. The main problem is to find out the correct name. In EBGaramond I found e.g. a variant called sinf:

\documentclass[12pt]{article}
\usepackage{fontspec}

\directlua{
   fonts.handlers.otf.addfeature{
    name = "apo-sc",
    type = "chainsubstitution",
    lookups = {
      {
        type = "substitution",
        data = {
          ["’"] = "quotesingle.sinf", 
        },
      },
    },
    data = {
      rules = {
        {
          before  = { { "A", "B", "C", "D"} },
          current = { { "’" } },
          lookups = { 1 },
        },
      },
    },
  }
}

\setmainfont{EBGaramond}[SmallCapsFeatures={RawFeature=+apo-sc}]



\begin{document}
D'ono'frio A' B' C' 

\textsc{D'ono'frio A' B' C' E'}
\end{document}

enter image description here


I don't have the font to actually check this approach, so what I did as a surrogate is to print apostrophes in bold red those which should be output as \textup{'}, and those in black will be output as \scshape'.

I use listofitems to redefine \textsc. Here I search for all combinations of capital letters followed by an apostrope. While all the rest of the argument is output in \scshape, including apostrophes that follow lowercase letters, those apostrophe's following uppercase letters I output here as \textcolor{red}{\bfseries'}. This line should merely be replaced with \textup{'} to achieve the desired behavior sought by the OP.

\documentclass{article}
\usepackage{listofitems,xcolor}
\let\svtextsc\textsc
\renewcommand\textsc[1]{%
  \setsepchar{A'||B'||C'||D'||E'||F'||G'||H'||I'||J'||K'||L'||M'||%
    N'||O'||P'||Q'||R'||S'||T'||U'||V'||W'||X'||Y'||Z'}%
  \greadlist\scarg{#1}%
  \bgroup%
  \scshape%
  \foreachitem\z\in\scarg[]{%
    \z%
    \ifnum\zcnt<\listlen\scarg[]\relax
      \expandafter\expandafter\expandafter%
        \processapostrophe\scargsep[\zcnt]%
    \fi%
  }%
  \egroup%
}
\def\processapostrophe#1#2{#1%
  \textcolor{red}{\bfseries'}% replace this line with \textup{'}
}
\begin{document}
\textsc{D'Onofrio Dell'Omo}
\end{document}

enter image description here