Files
29WxOrder/WxOrder.Framework/Resources/Fonts/FontGeometry.tt
T
chfei 4f606c3561 新增 WxOrder.Framework 项目
新增公共类 WPFCommon 包
2026-08-17 14:25:05 +08:00

66 lines
2.8 KiB
Plaintext

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ output extension=".xaml" encoding="utf-8" #>
<#
StringBuilder FontString = new StringBuilder();
FontString.AppendLine("<ResourceDictionary");
FontString.AppendLine("\txmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"");
FontString.AppendLine("\txmlns:PresentationOptions=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation/options\"");
FontString.AppendLine("\txmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"");
FontString.AppendLine("\txmlns:sys=\"clr-namespace:System;assembly=mscorlib\"");
FontString.AppendLine("\t>");
FontString.AppendLine("");
FontString.AppendLine("");
string cssPath = this.Host.ResolvePath("iconfont.css");
string svgPath = this.Host.ResolvePath("iconfont.js");
if (File.Exists(cssPath))
{
string cssContent = File.ReadAllText(cssPath, Encoding.UTF8);
MatchCollection matchs = Regex.Matches(cssContent, "\\.icon-(?<name>.+?):before.+?\\{.+?content:.+?\"\\\\(?<value>e.+?)\";.+?\\}", RegexOptions.Singleline);
foreach (Match match in matchs)
{
string name = match.Groups["name"].Value;
//name = Regex.Replace(name,"(a-(\\d{4,}(.*)?_fluent_|SegoeFluentIconsRegular-))|(_regular_icon|$)","",RegexOptions.Singleline);
string value = match.Groups["value"].Value;
FontString.AppendLine(string.Format("\t<sys:String x:Key=\"txt-{0}\">&#x{1};</sys:String>", name, value));
}
}
if (File.Exists(svgPath))
{
FontString.AppendLine("");
FontString.AppendLine("");
string svgContent = File.ReadAllText(svgPath, Encoding.UTF8);
MatchCollection matchs = Regex.Matches(svgContent, "<symbol.+?id=\"(?<name>.+?)\".+?>(?<value>.+?)</symbol>");
foreach (Match match in matchs)
{
string name = match.Groups["name"].Value;
string symbol = match.Groups["value"].Value;
StringBuilder value =new StringBuilder();
MatchCollection pathMatchs = Regex.Matches(symbol,"<path.+?d=\"(?<value>.+?)\"");
foreach(Match pathMatch in pathMatchs)
{
value.AppendLine("\t\t"+pathMatch.Groups["value"].Value);
}
FontString.AppendLine(string.Format("\t<Geometry x:Key=\"{0}\" PresentationOptions:Freeze=\"True\">\n{1}\t</Geometry>", name, value));
}
}
FontString.AppendLine("");
FontString.AppendLine("");
FontString.AppendLine("</ResourceDictionary>");
string content = FontString.ToString();
string savePath =Path.Combine(this.Host.ResolvePath(""),@"..\Themes\FontGeometry.xaml");
//File.WriteAllText(savePath,content,Encoding.UTF8);
#>
<#=content#>