Skip to content

Commit

Permalink
Add Local Font Import Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussacana committed Dec 27, 2020
1 parent 4266c18 commit 809040e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
3 changes: 3 additions & 0 deletions StringReloads/Engine/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public string[] IniLines {

bool? _LogFile = null;
public bool LogFile => ((bool?)(_LogFile ??= GetValue("LogFile").ToBoolean())).Value;

bool? _LoadLocalFont = null;
public bool LoadLocalFont => ((bool?)(_LoadLocalFont ??= GetValue("LoadLocalFont").ToBoolean())).Value;

Log.LogLevel? _LogLevel = null;
public Log.LogLevel LogLevel => ((Log.LogLevel?)(_LogLevel ??= GetValue("LogLevel").ToLogLevel())).Value;
Expand Down
7 changes: 6 additions & 1 deletion StringReloads/Engine/Initializer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using StringReloads.Engine.Unmanaged;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -37,6 +39,9 @@ internal void Initialize(SRL Engine)

PluginsInitializer(Engine);

if (Engine.Settings.LoadLocalFont)
FontUtility.LoadLocalFonts();

ModifiersInitializer(Engine);
HooksInitializer(Engine);
ModsInitializer(Engine);
Expand Down
39 changes: 39 additions & 0 deletions StringReloads/Engine/Unmanaged/Font.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

namespace StringReloads.Engine.Unmanaged
{
internal unsafe static class FontUtility
{
internal static void LoadLocalFonts()
{
var RootDir = Path.Combine(EntryPoint.CurrentDll).TrimEnd(' ', '\\', '/');
var RootDirB = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(' ', '\\', '/');
var RootBEquals = RootDir.ToLowerInvariant().StartsWith(RootDirB.ToLowerInvariant());

if (RootDirB.Length < RootDir.Length && RootBEquals)
RootDir = RootDirB;

var Exts = new string[] { "*.fon", "*.fnt", "*.ttf", "*.ttc", "*.fot", "*.otf", "*.mmm", "*.pfb", "*.pfm" };
var Fonts = (from Ext in Exts
from Font in Directory.GetFiles(RootDir, Ext)
select Font);

foreach (var Font in Fonts)
{
int Loaded = AddFontResourceExW(Font, FR_PRIVATE, null);

if (Loaded > 0)
Log.Information("{0} Fonts Loaded From {1}", Loaded.ToString(), Path.GetFileName(Font));
}
}

[DllImport("gdi32.dll")]
static extern int AddFontResourceExW(string lpszFilename, uint fl, void* reserved);

const uint FR_PRIVATE = 0x10;
const uint FR_NOT_ENUM = 0x20;
}
}
1 change: 1 addition & 0 deletions StringReloads/SRL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ReloadRegexCaptures=true
SanityCheck=true
TrimMatch=false
Workspace=StringReloads
LoadLocalFonts=false

[Wordwrap]
UseRelativeWidth=false
Expand Down
4 changes: 2 additions & 2 deletions StringReloads/StringReloads.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<None Remove="packages\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CoreCLR-NCalc" Version="2.2.88" />
<PackageReference Include="Iced" Version="1.8.0" />
<PackageReference Include="CoreCLR-NCalc" Version="2.2.92" />
<PackageReference Include="Iced" Version="1.10.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 809040e

Please sign in to comment.