Commit aadd2dc0 authored by mercury233's avatar mercury233

load font from file

parent f137400f
...@@ -39,10 +39,9 @@ namespace ImgGen ...@@ -39,10 +39,9 @@ namespace ImgGen
private static StringFormat rightAlignFormat; private static StringFormat rightAlignFormat;
private static string xyzString = "超量"; private static string xyzString = "超量";
private static string fontName = "文泉驿微米黑";
private static string fontLiShuName = "方正隶变_GBK";
private static string numfontName = "MatrixBoldSmallCaps";
private static string spfontName = "黑体"; private static string spfontName = "黑体";
private static FontFamily fontName;
private static FontFamily numfontName;
private static List<int> zeroStarCards = new List<int>(); private static List<int> zeroStarCards = new List<int>();
...@@ -63,11 +62,16 @@ namespace ImgGen ...@@ -63,11 +62,16 @@ namespace ImgGen
} }
} }
numfontName = Program.GetFontFamily("MatrixBoldSmallCaps");
string _style = System.Configuration.ConfigurationManager.AppSettings["Style"]; string _style = System.Configuration.ConfigurationManager.AppSettings["Style"];
if (_style == "隶书") if (_style == "隶书")
{ {
LiShu = true; LiShu = true;
fontName = fontLiShuName; fontName = Program.GetFontFamily("方正隶变_GBK");
}
else
{
fontName = Program.GetFontFamily("文泉驿微米黑");
} }
string _namestyle = System.Configuration.ConfigurationManager.AppSettings["NameStyle"]; string _namestyle = System.Configuration.ConfigurationManager.AppSettings["NameStyle"];
......
...@@ -4,6 +4,7 @@ namespace ImgGen ...@@ -4,6 +4,7 @@ namespace ImgGen
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO; using System.IO;
internal class Program internal class Program
...@@ -21,8 +22,35 @@ namespace ImgGen ...@@ -21,8 +22,35 @@ namespace ImgGen
return null; return null;
} }
private static PrivateFontCollection fontCollection;
public static FontFamily GetFontFamily(string fontName)
{
try
{
return new FontFamily(fontName, fontCollection);
}
catch
{
try
{
return new FontFamily(fontName);
}
catch
{
Console.WriteLine($"Font {fontName} not found!");
return new FontFamily("Arial");
}
}
}
private static void Main(string[] args) private static void Main(string[] args)
{ {
fontCollection = new PrivateFontCollection();
foreach (string font in Directory.GetFiles("./fonts"))
{
fontCollection.AddFontFile(font);
}
if (args.Length > 0) if (args.Length > 0)
{ {
DataManager.InitialDatas(args[0]); DataManager.InitialDatas(args[0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment