% XeTeX script transitions, implemented by ucharclasses.
% Part of latexbangla, LPPL 1.3c or later; copyright 2026 Adib Hasan.

\RequirePackage[Latin,Bengali,Devanagari]{ucharclasses}

% ucharclasses inserts these groups only around Latin runs. Selecting a font
% family preserves size, weight and shape; normalfont would discard them.
% Devanagari is included in the block setup because danda (।) belongs there.
% Common typographic punctuation follows the companion English font, as ASCII
% punctuation already does. SolaimanLipi lacks these Unicode glyphs. Assign only
% visible punctuation, not the whole General Punctuation block: its joiners and
% format controls must remain available to Bengali shaping.
\clist_map_inline:nn {"2013,"2014,"2018,"2019,"201C,"201D,"2026}
  {\XeTeXcharclass #1 = \BasicLatinClass\scan_stop:}
\setTransitionsForLatin
  {\group_begin:\__latexbangla_select_latin_font:} {\group_end:}

% ucharclasses installs transitions only between its enabled blocks and the
% word boundary. Class 0 also needs transitions: characters outside the enabled
% blocks must close a Latin run before Bengali text resumes. Otherwise
% its font group leaks, causing missing glyphs and unbalanced author groups.
% Adjacent Latin blocks belong to the same run (as in café or Ānand);
% do not open another group when crossing between them.
% Reuse ucharclasses' Latin block inventory rather than duplicating its ranges.
\group_begin:
  \seq_clear_new:N \l__latexbangla_latin_classes_seq
  \cs_set:Npn \do #1
    {\cs_if_exist:cT {#1Class}
      {\seq_put_right:Nn \l__latexbangla_latin_classes_seq {#1Class}}}
  \LatinClasses
  \seq_map_inline:Nn \l__latexbangla_latin_classes_seq
    {
      \tex_global:D \XeTeXinterchartoks 0 \use:c {#1} =
        {\group_begin:\__latexbangla_select_latin_font:}
      \tex_global:D \XeTeXinterchartoks \use:c {#1} 0 = {\group_end:}
      \seq_map_inline:Nn \l__latexbangla_latin_classes_seq
        {\tex_global:D \XeTeXinterchartoks \use:c {#1} \use:c {##1} = {}}
    }
\group_end:

\endinput
