Support UTF8 to UTF16 LE.
Support Unicode helper Fix ANSFR to show 2 same faces in 1 image
This commit is contained in:
125
dotnet/ANSUnicodeHelper/ANSUnicodeHelper.cs
Normal file
125
dotnet/ANSUnicodeHelper/ANSUnicodeHelper.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ANSCENTER
|
||||
{
|
||||
/// <summary>
|
||||
/// Unicode helper for LabVIEW .NET interop.
|
||||
/// All methods are static — no instance creation needed.
|
||||
/// In LabVIEW: use Invoke Node with class type ANSCENTER.ANSUnicodeHelper.
|
||||
/// Thread-safe: no shared mutable state.
|
||||
/// </summary>
|
||||
public class ANSUnicodeHelper
|
||||
{
|
||||
// Pre-compiled regex — compiled once at class load, zero per-call cost
|
||||
private static readonly Regex UnicodeEscapeRegex =
|
||||
new Regex(@"\\u([0-9a-fA-F]{4})", RegexOptions.Compiled);
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for LabVIEW (if needed). Lightweight, no state.
|
||||
/// </summary>
|
||||
public ANSUnicodeHelper() { }
|
||||
|
||||
/// <summary>
|
||||
/// Decodes \uXXXX escape sequences to Unicode characters.
|
||||
/// ASCII strings pass through unchanged (zero allocation).
|
||||
/// </summary>
|
||||
public static string Decode(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input)) return input ?? string.Empty;
|
||||
if (input.IndexOf("\\u", StringComparison.Ordinal) < 0) return input;
|
||||
return UnicodeEscapeRegex.Replace(input, match =>
|
||||
{
|
||||
int codepoint = Convert.ToInt32(match.Groups[1].Value, 16);
|
||||
return ((char)codepoint).ToString();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws Unicode string at position (x, y).
|
||||
/// </summary>
|
||||
public static void DrawString(Graphics g, string escapedText, Font font, Brush brush, float x, float y)
|
||||
{
|
||||
if (g == null || string.IsNullOrEmpty(escapedText)) return;
|
||||
g.DrawString(Decode(escapedText), font, brush, x, y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws Unicode string at position (x, y) with StringFormat.
|
||||
/// </summary>
|
||||
public static void DrawString(Graphics g, string escapedText, Font font, Brush brush, float x, float y, StringFormat format)
|
||||
{
|
||||
if (g == null || string.IsNullOrEmpty(escapedText)) return;
|
||||
g.DrawString(Decode(escapedText), font, brush, x, y, format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws Unicode string at PointF with StringFormat.
|
||||
/// </summary>
|
||||
public static void DrawString(Graphics g, string escapedText, Font font, Brush brush, PointF point, StringFormat format)
|
||||
{
|
||||
if (g == null || string.IsNullOrEmpty(escapedText)) return;
|
||||
g.DrawString(Decode(escapedText), font, brush, point, format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws Unicode string inside a RectangleF with word wrapping.
|
||||
/// </summary>
|
||||
public static void DrawString(Graphics g, string escapedText, Font font, Brush brush, RectangleF layoutRect)
|
||||
{
|
||||
if (g == null || string.IsNullOrEmpty(escapedText)) return;
|
||||
g.DrawString(Decode(escapedText), font, brush, layoutRect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws Unicode string inside a RectangleF with StringFormat.
|
||||
/// </summary>
|
||||
public static void DrawString(Graphics g, string escapedText, Font font, Brush brush, RectangleF layoutRect, StringFormat format)
|
||||
{
|
||||
if (g == null || string.IsNullOrEmpty(escapedText)) return;
|
||||
g.DrawString(Decode(escapedText), font, brush, layoutRect, format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures Unicode string size after decoding.
|
||||
/// </summary>
|
||||
public static SizeF MeasureString(Graphics g, string escapedText, Font font)
|
||||
{
|
||||
if (g == null || string.IsNullOrEmpty(escapedText)) return SizeF.Empty;
|
||||
return g.MeasureString(Decode(escapedText), font);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures Unicode string size with layout area and StringFormat.
|
||||
/// </summary>
|
||||
public static SizeF MeasureString(Graphics g, string escapedText, Font font, SizeF layoutArea, StringFormat format)
|
||||
{
|
||||
if (g == null || string.IsNullOrEmpty(escapedText)) return SizeF.Empty;
|
||||
return g.MeasureString(Decode(escapedText), font, layoutArea, format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if string contains \uXXXX escapes.
|
||||
/// </summary>
|
||||
public static bool HasUnicodeEscapes(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input)) return false;
|
||||
return input.IndexOf("\\u", StringComparison.Ordinal) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if string is pure ASCII.
|
||||
/// </summary>
|
||||
public static bool IsAsciiOnly(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input)) return true;
|
||||
foreach (char c in input)
|
||||
{
|
||||
if (c > 127) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
dotnet/ANSUnicodeHelper/ANSUnicodeHelper.csproj
Normal file
21
dotnet/ANSUnicodeHelper/ANSUnicodeHelper.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<AssemblyName>ANSUnicodeHelper</AssemblyName>
|
||||
<RootNamespace>ANSCENTER</RootNamespace>
|
||||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<FileVersion>1.0.0.0</FileVersion>
|
||||
<Company>ANSCENTER</Company>
|
||||
<Product>ANSUnicodeHelper</Product>
|
||||
<Description>Unicode helper for LabVIEW .NET interop - decodes \uXXXX escapes to .NET System.String</Description>
|
||||
<OutputPath>..\..\cmake-build-release\bin\</OutputPath>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\ANSUnicodeHelper.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\ANSUnicodeHelper.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\ANSUnicodeHelper.csproj",
|
||||
"projectName": "ANSUnicodeHelper",
|
||||
"projectPath": "C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\ANSUnicodeHelper.csproj",
|
||||
"packagesPath": "C:\\Users\\nghia\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||
],
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\nghia\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net48"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-11/nuget/v3/index.json": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net48": {
|
||||
"targetAlias": "net48",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
},
|
||||
"restoreAuditProperties": {
|
||||
"enableAudit": "true",
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
},
|
||||
"SdkAnalysisLevel": "10.0.200"
|
||||
},
|
||||
"frameworks": {
|
||||
"net48": {
|
||||
"targetAlias": "net48",
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\10.0.200\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\nghia\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">7.0.0</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="C:\Users\nghia\.nuget\packages\" />
|
||||
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
||||
64
dotnet/ANSUnicodeHelper/obj/project.assets.json
Normal file
64
dotnet/ANSUnicodeHelper/obj/project.assets.json
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"version": 3,
|
||||
"targets": {
|
||||
".NETFramework,Version=v4.8": {}
|
||||
},
|
||||
"libraries": {},
|
||||
"projectFileDependencyGroups": {
|
||||
".NETFramework,Version=v4.8": []
|
||||
},
|
||||
"packageFolders": {
|
||||
"C:\\Users\\nghia\\.nuget\\packages\\": {},
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
|
||||
},
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\ANSUnicodeHelper.csproj",
|
||||
"projectName": "ANSUnicodeHelper",
|
||||
"projectPath": "C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\ANSUnicodeHelper.csproj",
|
||||
"packagesPath": "C:\\Users\\nghia\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"fallbackFolders": [
|
||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
||||
],
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\nghia\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net48"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-11/nuget/v3/index.json": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net48": {
|
||||
"targetAlias": "net48",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
},
|
||||
"restoreAuditProperties": {
|
||||
"enableAudit": "true",
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
},
|
||||
"SdkAnalysisLevel": "10.0.200"
|
||||
},
|
||||
"frameworks": {
|
||||
"net48": {
|
||||
"targetAlias": "net48",
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\10.0.200\\RuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
dotnet/ANSUnicodeHelper/obj/project.nuget.cache
Normal file
8
dotnet/ANSUnicodeHelper/obj/project.nuget.cache
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "5VJRzMAJt58=",
|
||||
"success": true,
|
||||
"projectFilePath": "C:\\Projects\\CLionProjects\\ANSCORE\\dotnet\\ANSUnicodeHelper\\ANSUnicodeHelper.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
"logs": []
|
||||
}
|
||||
Reference in New Issue
Block a user