-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from Sandip124/fix/appfreezing
Fix/appfreezing
- Loading branch information
Showing
11 changed files
with
57 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,43 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Drawing.Text; | ||
|
||
namespace BatteryNotifier.Providers | ||
{ | ||
internal class FontProvider | ||
{ | ||
private const string FontDirectory = "Assets/fonts"; | ||
[System.Runtime.InteropServices.DllImport("gdi32.dll")] | ||
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [System.Runtime.InteropServices.In] ref uint pcFonts); | ||
|
||
private const string RegularFont = "Inter-Regular.ttf"; | ||
private const string BoldFont = "Inter-Bold.ttf"; | ||
|
||
|
||
public PrivateFontCollection FontCollection = new(); | ||
public PrivateFontCollection FontsCollection = new(); | ||
|
||
public static FontProvider Default = new(); | ||
|
||
private FontProvider() | ||
{ | ||
FontCollection.AddFontFile($"{FontDirectory}/{RegularFont}"); | ||
FontCollection.AddFontFile($"{FontDirectory}/{BoldFont}"); | ||
LoadFont(Properties.Resources.Inter_Regular); | ||
LoadFont(Properties.Resources.Inter_Bold); | ||
} | ||
|
||
private void LoadFont(byte[] fontResource) | ||
{ | ||
IntPtr fontPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontResource.Length); | ||
System.Runtime.InteropServices.Marshal.Copy(fontResource, 0, fontPtr, fontResource.Length); | ||
uint dummy = 0; | ||
FontsCollection.AddMemoryFont(fontPtr, fontResource.Length); | ||
AddFontMemResourceEx(fontPtr, (uint)fontResource.Length, IntPtr.Zero, ref dummy); | ||
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr); | ||
} | ||
|
||
public static Font GetRegularFont(float size = 8) | ||
{ | ||
return new Font(Default.FontCollection.Families[0], size, FontStyle.Regular, GraphicsUnit.Point); | ||
return new Font(Default.FontsCollection.Families[0], size, FontStyle.Regular, GraphicsUnit.Point); | ||
} | ||
|
||
public static Font GetBoldFont(float size = 8) | ||
{ | ||
return new Font(Default.FontCollection.Families[0], size, FontStyle.Bold, GraphicsUnit.Point); | ||
return new Font(Default.FontsCollection.Families[0], size, FontStyle.Bold, GraphicsUnit.Point); | ||
} | ||
} | ||
|
||
} |