---
title: "Set an OpenType script when shaping text in C#"
url: https://recursiveai.org/onefont/cookbook/override-opentype-shaping-script/
description: "Force an OpenType script tag for a run in C# with ShapingOptions.Script, and compare Arabic and Latin shaping on the same input."
version: "1.5.1"
---

# Set an OpenType script when shaping text in C#

**onefont** is a free, open-source font and text-shaping library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneFont) · [GitHub](https://github.com/recursive-ai-oss/onefont-csharp) · [Docs](https://recursiveai.org/onefont/docs/) · [Download example (.zip)](https://recursiveai.org/onefont/cookbook/override-opentype-shaping-script/override-opentype-shaping-script.zip)

Set `ShapingOptions.Script` to override script detection. The zip’s `arabic.ttf` is a Noto Sans Arabic subset.

```shell
dotnet add package RecursiveAI.OneFont
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
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](https://recursiveai.org/onefont/cookbook/override-opentype-shaping-script/override-opentype-shaping-script.zip) 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:

```text
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:

```csharp
var options = new ShapingOptions
    { Script = 0x6C61746E }; // latn
```

```text
69
69
```

## Related recipes

- [Shape Arabic and other right-to-left text](https://recursiveai.org/onefont/cookbook/right-to-left-text/)
- [Select localized glyphs by language](https://recursiveai.org/onefont/cookbook/shape-text-with-locale-specific-glyphs/)
- [Use OpenType features](https://recursiveai.org/onefont/cookbook/opentype-features/)

---

## 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](https://learn.microsoft.com/en-us/typography/opentype/spec/scripttags), `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](https://simoncozens.github.io/fonts-and-layout/features.html#scripts-and-languages). 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](https://recursiveai.org/onefont/docs/shaping/) 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.
