generated from karashiiro/DalamudPluginProjectTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
UINewFontHandler.cs
130 lines (113 loc) · 5.52 KB
/
UINewFontHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// <copyright file="UINewFontHandler.cs" company="lokinmodar">
// Copyright (c) lokinmodar. All rights reserved.
// Licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License license.
// </copyright>
using System;
using System.Text.Unicode;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Plugin.Services;
namespace Echoglossian
{
public class UINewFontHandler : IDisposable
{
private bool disposedValue;
private Config configuration;
private SafeFontConfig sfc;
public IFontHandle GeneralFontHandle;
public IFontHandle LanguageFontHandle;
public UINewFontHandler(Config configuration = default)
{
this.configuration = configuration;
var AllUnicodeRanges = UnicodeRanges.All;
Echoglossian.PluginLog.Debug($"SymbolsFontPath: ${Echoglossian.SymbolsFontFilePath}");
Echoglossian.PluginLog.Debug($"FontFilePath: ${Echoglossian.FontFilePath}");
Echoglossian.PluginLog.Debug($"ComplementaryFont3FilePath: ${Echoglossian.ComplementaryFont3FilePath}");
Echoglossian.PluginLog.Debug($"ComplementaryFont4FilePath: ${Echoglossian.ComplementaryFont4FilePath}");
Echoglossian.PluginLog.Debug($"ComplementaryFont5FilePath: ${Echoglossian.ComplementaryFont5FilePath}");
Echoglossian.PluginLog.Debug($"ComplementaryFont6FilePath: ${Echoglossian.ComplementaryFont6FilePath}");
Echoglossian.PluginLog.Debug($"ComplementaryFont7FilePath: ${Echoglossian.ComplementaryFont7FilePath}");
Echoglossian.PluginLog.Debug($"SpecialFontFilePath: ${Echoglossian.SpecialFontFilePath}");
Echoglossian.PluginLog.Debug($"LangComboFontFilePath: ${Echoglossian.LangComboFontFilePath}");
Echoglossian.PluginLog.Debug($"DummyFontFilePath: ${Echoglossian.DummyFontFilePath}");
Echoglossian.PluginLog.Debug($"UndicodeRanges.All: ${UnicodeRanges.All.ToString()}");
this.GeneralFontHandle = Echoglossian.PluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(
e => e.OnPreBuild(tk =>
{
var rangeBuilder = default(FluentGlyphRangeBuilder)
.With(Echoglossian.CharsToAddToAll.AsSpan())
.With(Echoglossian.ScriptCharList.AsSpan())
.With(Echoglossian.PuaCharCodes.AsSpan())
.With(Echoglossian.PuaChars.AsSpan())
.With(AllUnicodeRanges.FirstCodePoint, AllUnicodeRanges.FirstCodePoint + AllUnicodeRanges.Length - 1)
.With(Echoglossian.LangComboItems.AsSpan());
// more ranges here
this.sfc = new SafeFontConfig
{
SizePx = this.configuration.FontSize,
GlyphRanges = rangeBuilder.Build(),
};
this.sfc.MergeFont = tk.Font = tk.AddFontFromFile(Echoglossian.LangComboFontFilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.SymbolsFontFilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.FontFilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.ComplementaryFont3FilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.ComplementaryFont4FilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.ComplementaryFont5FilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.ComplementaryFont6FilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.ComplementaryFont7FilePath, this.sfc);
if (!string.IsNullOrWhiteSpace(Echoglossian.SpecialFontFilePath))
{
tk.AddFontFromFile(Echoglossian.SpecialFontFilePath, this.sfc);
}
}));
this.LanguageFontHandle = Echoglossian.PluginInterface.UiBuilder.FontAtlas.NewDelegateFontHandle(
e => e.OnPreBuild(tk =>
{
var rangeBuilder = default(FluentGlyphRangeBuilder)
.With(Echoglossian.CharsToAddToAll.AsSpan())
.With(Echoglossian.ScriptCharList.AsSpan())
.With(Echoglossian.PuaCharCodes.AsSpan())
.With(Echoglossian.PuaChars.AsSpan())
.With(AllUnicodeRanges.FirstCodePoint, AllUnicodeRanges.FirstCodePoint + AllUnicodeRanges.Length - 1)
.With(Echoglossian.SelectedLanguage.ExclusiveCharsToAdd.AsSpan());
// more ranges here
this.sfc = new SafeFontConfig
{
SizePx = this.configuration.FontSize,
GlyphRanges = rangeBuilder.Build(),
};
this.sfc.MergeFont = tk.Font = tk.AddFontFromFile(Echoglossian.DummyFontFilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.SymbolsFontFilePath, this.sfc);
tk.AddFontFromFile(Echoglossian.FontFilePath, this.sfc);
if (!string.IsNullOrWhiteSpace(Echoglossian.SpecialFontFilePath))
{
tk.AddFontFromFile(Echoglossian.SpecialFontFilePath, this.sfc);
}
}));
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
this.disposedValue = true;
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~UINewFontHandler()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}