A comprehensive utility library providing tools for Persian .NET application development, starting with advanced font management capabilities. Currently focuses on FontInstaller functionality with additional developer tools and utilities planned for future releases. Provides per-user font installation without requiring administrator privileges, supporting TTF, OTF, WOFF, and other font formats.
$ dotnet add package Barnamenevis.Net.ToolsA comprehensive utility library for .NET applications providing tools for Persian application development, starting with advanced font management capabilities.
Barnamenevis.Net.Tools is designed to be a comprehensive toolkit for Persian .NET application development. Currently, the library focuses on FontInstaller functionality, with additional developer tools and utilities planned for future releases.
The library currently provides the FontInstaller class, which allows .NET applications to automatically install fonts for the current user, making it easy to distribute applications with custom Persian, or other specialized fonts. The installation is per-user only, requires no admin privileges, and fonts persist after the application closes.
Barnamenevis.Net.Tools will be expanded with additional utility classes and tools for Persian application development, including:
Stay tuned for upcoming releases with these additional features!
Fonts subdirectoryusing Barnamenevis.Net.Tools;
// Install fonts from application's "Fonts" subdirectory
int installedCount = FontInstaller.InstallApplicationFonts();
Console.WriteLine($"نصب شد {installedCount} فونت جدید");
// Install fonts from a custom directory
int count = FontInstaller.InstallFontsFromDirectory(@"C:\MyFonts");
// Install from relative path
int count = FontInstaller.InstallFontsFromDirectory("./Resources/Fonts");
// In Program.cs (Console/WinForms) or App.xaml.cs (WPF)
static void Main() // or protected override void OnStartup(StartupEventArgs e)
{
try
{
// Install fonts at application startup
int installedCount = FontInstaller.InstallApplicationFonts();
if (installedCount > 0)
{
Console.WriteLine($"✅ با موفقیت {installedCount} فونت جدید نصب شد");
// Configure your UI libraries to use the installed fonts
// Example for RtlMessageBox:
RtlMessageBox.PreferredFontName = "Vazirmatn FD";
RtlMessageBox.ApplyCustomFont = true;
}
else
{
Console.WriteLine("ℹ️ فونت جدیدی برای نصب وجود ندارد (احتمالاً قبلاً نصب شده)");
}
}
catch (Exception ex)
{
Console.WriteLine($"⚠️ نصب فونت با خطا مواجه شد: {ex.Message}");
// Application continues with system fonts
}
// Continue with normal application startup
Application.Run(new MainForm()); // WinForms
// or base.OnStartup(e); // WPF
}
InstallApplicationFonts()Installs fonts from the application's default "Fonts" subdirectory.
public static int InstallApplicationFonts()
Returns: Number of fonts that were newly installed (0 if none or already installed)
Example:
int count = FontInstaller.InstallApplicationFonts();
// Looks for fonts in: [AppDirectory]/Fonts/
InstallFontsFromDirectory(string)Installs fonts from a specified directory path.
public static int InstallFontsFromDirectory(string fontsDirectoryPath)
Parameters:
fontsDirectoryPath: Path to directory containing font filesReturns: Number of fonts that were newly installed
Throws: ArgumentException if path is null/empty
Example:
// Absolute path
int count = FontInstaller.InstallFontsFromDirectory(@"C:\MyProject\Assets\Fonts");
// Relative path
int count = FontInstaller.InstallFontsFromDirectory("./Resources/Fonts");
// Network path
int count = FontInstaller.InstallFontsFromDirectory(@"\\server\share\Fonts");
UninstallFont(string)Removes a previously installed font for the current user.
public static bool UninstallFont(string fontFileName)
Parameters:
fontFileName: Name of the font file (e.g., "Vazirmatn-FD-Regular.ttf")Returns: true if successfully uninstalled, false otherwise
Example:
bool success = FontInstaller.UninstallFont("Vazirmatn-FD-Regular.ttf");
This library works seamlessly with the RTL MessageBox libraries in this solution:
// Install fonts and configure RTL MessageBox in one step
public static void SetupPersianUI()
{
var installedCount = FontInstaller.InstallApplicationFonts();
// Configure WPF RTL MessageBox
Barnamenevis.Net.RtlMessageBox.Wpf.RtlMessageBox.PreferredFontName = "Vazirmatn FD";
Barnamenevis.Net.RtlMessageBox.Wpf.RtlMessageBox.ApplyCustomFont = true;
// Configure Windows Forms RTL MessageBox
Barnamenevis.Net.RtlMessageBox.WindowsForms.RtlMessageBox.PreferredFontName = "Vazirmatn FD";
Barnamenevis.Net.RtlMessageBox.WindowsForms.RtlMessageBox.ApplyCustomFont = true;
Console.WriteLine($"رابط کاربری فارسی با {installedCount} فونت جدید پیکربندی شد");
}
We welcome contributions! If you have ideas for additional tools and utilities that would benefit Persian .NET developers, please:
Together, we can build a comprehensive toolkit for Persian .NET application development!