Better Font Code

Changed system fonts to share a reference across all Font library's
This commit is contained in:
JacobTech 2023-01-01 20:38:37 -05:00
parent 4aa46bf095
commit 4d22c3a8d5
2 changed files with 72 additions and 43 deletions

View File

@ -10,7 +10,7 @@
<IncludeSymbols>False</IncludeSymbols>
<RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>1.0.0-alpha2</Version>
<Version>1.0.0-alpha4</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -6,6 +6,7 @@ namespace GraphicsManager.Objects.Core;
public class Font
{
private static List<Face>? System = null;
private List<Face> _Faces = new();
private Library lib;
public IReadOnlyList<Face> Faces => _Faces.AsReadOnly();
@ -33,39 +34,9 @@ public class Font
? Tools.GetResourceBytes(Base + Font)
: Tools.GetResourceBytes(Assembly!, $"{Base}{Font}"));
fontclass._Faces.Add(new Face(lib, f, 0));
//load the fucking system fonts
if (OperatingSystem.IsLinux())
if (System is null)
{
try
{
Process proc = new()
{
};
proc.Start();
proc.WaitForExit();
string[] files = proc.StandardOutput.ReadToEnd().Split($":{Environment.NewLine}");
for (int i = 0; i < files.Length; i++)
{
fontclass._Faces.Add(new Face(lib, files[i], 0));
}
}
catch
{
}
}
return fontclass;
}
public static Font MakeFontFromSystem()
{
Font fontclass = new()
{
Assembly = null,
Embeded = false,
Name = default!,
lib = new()
};
System = new();
if (OperatingSystem.IsLinux())
{
try
@ -84,13 +55,60 @@ public class Font
string[] files = proc.StandardOutput.ReadToEnd().Split($": {Environment.NewLine}");
for (int i = 0; i < files.Length; i++)
{
fontclass._Faces.Add(new Face(fontclass.lib, files[i], 0));
System!.Add(new Face(fontclass.lib, files[i], 0));
}
}
catch
{
}
}
}
for (int i = 0; i < System!.Count; i++) fontclass._Faces.Add(System![i]);
return fontclass;
}
public static Font MakeFontFromSystem()
{
Font fontclass = new()
{
Assembly = null,
Embeded = false,
Name = default!,
lib = new()
};
if (Font.System is null)
{
Font.System = new();
if (OperatingSystem.IsLinux())
{
try
{
Process proc = new()
{
StartInfo = new()
{
FileName = "/bin/bash",
Arguments = "-c \"fc-list ':' file\"",
RedirectStandardOutput = true,
}
};
proc.Start();
proc.WaitForExit();
string[] files = proc.StandardOutput.ReadToEnd().Split($": {Environment.NewLine}");
for (int i = 0; i < files.Length; i++)
{
Font.System!.Add(new Face(fontclass.lib, files[i], 0));
}
}
catch
{
}
}
}
for (int i = 0; i < Font.System!.Count; i++) fontclass._Faces.Add(Font.System![i]);
return fontclass;
}
@ -105,26 +123,37 @@ public class Font
};
fontclass.lib = new();
fontclass._Faces.Add(new Face(fontclass.lib, File.ReadAllBytes(Font), 0));
//load the fucking system fonts
if (System is null)
{
System = new();
if (OperatingSystem.IsLinux())
{
try
{
Process proc = new()
{
StartInfo = new()
{
FileName = "/bin/bash",
Arguments = "-c \"fc-list ':' file\"",
RedirectStandardOutput = true,
}
};
proc.Start();
proc.WaitForExit();
string[] files = proc.StandardOutput.ReadToEnd().Split($":{Environment.NewLine}");
string[] files = proc.StandardOutput.ReadToEnd().Split($": {Environment.NewLine}");
for (int i = 0; i < files.Length; i++)
{
fontclass._Faces.Add(new Face(fontclass.lib, files[i], 0));
System!.Add(new Face(fontclass.lib, files[i], 0));
}
}
catch
{
}
}
}
for (int i = 0; i < System!.Count; i++) fontclass._Faces.Add(System![i]);
return fontclass;
}