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> <IncludeSymbols>False</IncludeSymbols>
<RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl> <RepositoryUrl>https://git.jacobtech.com/JacobTech.com/GraphicsManager</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<Version>1.0.0-alpha2</Version> <Version>1.0.0-alpha4</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

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