BidiReshapeSharp 1.2.0

dotnet add package BidiReshapeSharp --version 1.2.0
                    
NuGet\Install-Package BidiReshapeSharp -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BidiReshapeSharp" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BidiReshapeSharp" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="BidiReshapeSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BidiReshapeSharp --version 1.2.0
                    
#r "nuget: BidiReshapeSharp, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BidiReshapeSharp@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BidiReshapeSharp&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=BidiReshapeSharp&version=1.2.0
                    
Install as a Cake Tool

BidiReshapeSharp

NuGet Version NuGet Downloads

A library to Bi-Directional and Reshape Arabic or Persian texts

Overview

BidiReshapeSharp is a .NET library for pre-processing Right-to-Left (RTL) scripts, such as Arabic and Persian, for display in rendering environments that do not natively implement the Unicode Bidirectional Algorithm (UBA). There are good Python libraries that do this, but there was no library in C# to do the same. So I decided to do it myself. The library resolves two primary issues that arise in basic LTR rendering pipelines:

  1. Character Reordering: It handles the complex rearrangement of mixed RTL and LTR text segments (text, numbers, punctuation) to ensure correct visual flow.
  2. Contextual Shaping: It replaces generic Unicode characters with their correct contextual glyph forms (initial, medial, final, or isolated) required for connecting scripts.

By using the shaping method, the input string is converted into a sequence of display characters that can be rendered correctly by any simple LTR text engine.

Features

  • Applies the necessary initial, medial, final, and isolated forms for all standard Arabic and Persian characters.
  • Correctly substitutes common character pairs, such as Lām + Alif, with their typographic ligature forms (e.g., 'لا' becomes 'ﻻ').
  • Implements full reordering logic to correctly position LTR elements (like numbers) within RTL sentences.
  • Simple, static API for straightforward integration.

Installation

The library is available as a NuGet package.

NuGet Package Manager

Install-Package BidiReshapeSharp

.NET CLI

dotnet add package BidiReshapeSharp

Usage

The primary functionality is exposed through the static BidiShaper class and its Reshape method.

Simple String Processing (Default Configuration)

The ProcessString method accepts a single string and returns the fully reshaped and reordered result using the default configuration settings.

using BidiReshapeSharp;
using System;

public class Program
{
    public static void Main()
    {
        // Example 1: Basic Arabic phrase requiring character connection and ligatures (e.g., in لأمر).
        string inputArabic = "الْكِتَابُ الْجَدِيدُ لأمر";
        string outputArabic = BidiReshape.ProcessString(inputArabic);

        Console.WriteLine($"Original (raw Unicode): {inputArabic}");
        Console.WriteLine($"Reshaped (display-ready): {outputArabic}");
        
        // The output string contains correctly connected glyphs and reordered segments.

        // Example 2: Mixing RTL text, LTR numbers, and punctuation.
        string inputMixed = "النص المختلط 123 مع ترقيم.";
        string outputMixed = BidiReshape.ProcessString(inputMixed);

        Console.WriteLine($"\nOriginal (mixed data): {inputMixed}");
        Console.WriteLine($"Reshaped (correctly ordered): {outputMixed}");
    }
}

Advanced String Processing with Configuration

Use the overloaded ProcessString method along with a ReshaperConfig object to apply custom shaping rules.

using BidiReshapeSharp;
using System;
using BidiReshapeSharp.Reshaper;

public class Program
{
    public static void Main()
    {
        // Create a custom configuration object.
        var customConfig = new ReshaperConfig
        {
            DeleteHarakat = true,
            UseUnshapedInsteadOfIsolated = true
        };

        // We support persian texts with پچگژ too!
        string input = "نمونه متن پارسی";
        string output = BidiReshape.ProcessString(input, customConfig);

        Console.WriteLine($"Configured Output: {output}");
    }
}

Based on

Python Arabic Reshaper by mpcabd

BidiSharp by fsufyan

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 239 10/30/2025
1.1.0 188 9/29/2025
1.0.0 175 9/28/2025