An open API service indexing awesome lists of open source software.

https://github.com/giosali/diacriticalmarks

A small, basic library for creating and getting diacritical letters in WPF.
https://github.com/giosali/diacriticalmarks

csharp diacritical-marks diacritics wpf

Last synced: about 1 month ago
JSON representation

A small, basic library for creating and getting diacritical letters in WPF.

Awesome Lists containing this project

README

          

DiacriticalMarks




A small, basic library for creating and getting diacritical letters in WPF



NuGet Version


Target Framework



CI Workflow


License

## Requirements

**DiacriticalMarks** is compatible with **.NET 5.0** (*net5.0-windows*) and **.NET 6.0** (*net6.0-windows*).

## Installation

You can find the package on [NuGet](https://www.nuget.org/packages/DiacriticalMarks) or install it through PackageManagement:

```ps
Install-Package DiacriticalMarks
```

## Usage

The purpose of this library is to do basic things like:

```
a + ´ = á
```

or even:

```
a + ^ + ` = ầ
```

### Using Basic Accents

You're most likely interested in using some of the following basic accents:

| Accent | Mark |
|------------|:----:|
| Circumflex | ^ |
| Grave | ` |
| Tilde | ~ |
| Diaeresis | ¨ |
| Macron | ¯ |
| Acute | ´ |
| Cedilla | ¸ |

If that's the case, you can simply use the `AttachAccent` method to *attach* an accent to a provided base character:

```csharp
using DiacriticalMarks;

public static void Main()
{
string result = DiacriticalMarks.AttachAccent('a', Accent.Acute);
char diacriticalLetter = char.Parse(result);
Console.WriteLine(diacriticalLetter); // Prints á
}
```

The `DiacriticalMarks` namespace contains an [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum) called `Accent` that contains:

* the circumflex accent (^)
* the grave accent (`)
* the tilde (~)
* the diaeresis (¨)
* the macron (¯)
* the acute accent (´)
* and the cedilla (¸)

### Using Combining Diacritical Marks

If you need access to more, you can also use the `CombiningDiacriticalMark` enum which is also found in the `DiacriticalMarks` namespace. To use [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks), you have access to two methods:

* `AttachDiacritic`
* `AttachDiacritics`

The `CombiningDiacriticalMark` enum contains 112 values, per the [official document on combining diacritical marks by the Unicode Consortium](https://www.unicode.org/charts/PDF/U0300.pdf).

#### AttachDiacritic method

The `AttachDiacritic` method is similar to the `AttachAccent` method except instead of providing an `Accent`, you need to provide a `CombiningDiacriticalMark`:

```csharp
using DiacriticalMarks;

public static void Main()
{
string result = DiacriticalMarks.AttachDiacritic('a', CombiningDiacriticalMark.CombiningGraveAccent);
char diacriticalCharacter = char.Parse(result);
Console.WriteLine(diacriticalCharacter); // Prints 'à'
}
```

#### AttachDiacritics method

If you need to attach multiple diacritical marks to a base character, you can use the `AttachDiacritics` method. This method accepts a an array of `CombiningDiacriticalMark`:

```csharp
using DiacriticalMarks;

public static void Main()
{
CombiningDiacriticalMark[] marks = new CombiningDiacriticalMark[] { CombiningDiacriticalMark.CombiningBreve, CombiningDiacriticalMark.CombiningDotBelow };
string result = DiacriticalMarks.AttachDiacritic('A', marks);
char diacriticalCharacter = char.Parse(result);
Console.WriteLine(diacriticalCharacter); // Prints 'Ặ'
}
```

```
📝 NOTE: The order of `CombiningDiacriticalMark`s matters! For example, if the order of the `marks` variable was instead:

{ CombiningDiacriticalMark.CombiningDotBelow, CombiningDiacriticalMark.CombiningBreve }

Then you may end up with a string consisting of a 'Ạ' that has a breve ('˘') accent attached to it, which means the string will have a length of 2 instead of 1.

In other words:

'A' + new CombiningDiacriticalMark[] { CombiningDiacriticalMark.CombiningBreve, CombiningDiacriticalMark.CombiningDotBelow } = 'Ặ'

Length = 1
Official Unicode name = Latin Capital Letter a with Breve and Dot Below

'A' + new CombiningDiacriticalMark[] { CombiningDiacriticalMark.CombiningDotBelow, CombiningDiacriticalMark.CombiningBreve } = 'Ặ'

Length = 2
Official Unicode name = ?
```

If you need to find the correct order for certain characters, follow the order listed in their official Unicode names. A site that I recommend for viewing names is [Unicode-Table](https://unicode-table.com/).