Set ShapingOptions.Script to override script detection. The zip’s arabic.ttf is a Noto Sans Arabic subset.
dotnet add package RecursiveAI.OneFontRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneFont; var face = FontFace.Load( File.ReadAllBytes("arabic.ttf")); // Pack the four ASCII bytes of "arab" into a uint. var options = new ShapingOptions { Script = 0x61726162 }; var run = TextShaping.ShapeRun( "بب", face, rightToLeft: true, options: options); foreach (var cluster in run) foreach (var glyph in cluster.Glyphs) Console.WriteLine(glyph.GlyphId);
Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.
If you paste the code, put arabic.ttf from the zip next to Program.cs, or put your own Arabic font there and change the filename in the code.
Prints the two joined glyph IDs for بب in the bundled face:
71 70
If the font lacks the selected script’s feature table, OneFont tries DFLT, dflt, then latn; a tag cannot supply missing glyphs or substitutions.
Variations
Compare with Latin shaping
Replace the options declaration. The input and direction stay the same, but Arabic joining no longer applies:
var options = new ShapingOptions { Script = 0x6C61746E }; // latn
69 69
Related recipes
The short answer
Set ShapingOptions.Script and pass the options to TextShaping.ShapeRun. OneFont takes a uint with the first ASCII byte in the most significant position. The bytes for arab are 61 72 61 62 in hexadecimal, so the value is 0x61726162. Set it to 0 or omit the option to detect the script from the text.
What is an OpenType script tag?
A script tag identifies a writing system in the font’s layout data. In OpenType’s script tag registry, arab is Arabic and latn is Latin. The tag helps select font rules for substitution and positioning. It doesn’t change the Unicode string, and it isn’t a region or locale setting. In the example, the two characters are the same letter both times. The output changes because the Arabic shaper selects contextual glyph forms in the first run.
The font’s language system is a separate choice within the selected script, as described in Fonts and Layout for Global Scripts. In OneFont, use ShapingOptions.Language for a language such as sr when the script is already right but you want the font’s localized forms. rightToLeft is also separate: it sets the run direction, not its script. The Latin comparison keeps the right-to-left option enabled so the difference comes from the tag alone.
How does a shaper choose which OpenType features to use?
By default, OneFont works out the script from the characters. Combining marks follow their base, and spaces, punctuation and digits join the script stretch they’re in. Substitution and kerning don’t cross a change of script. The script selects a language system in the font and the shaper applies the appropriate lookups from the available features.
A nonzero Script applies to the whole run. That’s useful when testing a font or when a layout engine already knows the script from surrounding text. Don’t force a single script over a paragraph containing unrelated writing systems just to correct one segment. Pass the override only for the run that needs it, and shape the rest with automatic detection or with their own settings. If a forced tag has no visible effect, compare glyph IDs on text with a known substitution before concluding the tag isn’t being used.