Closed marimelon closed 3 years ago
do you know of a monospaced font that does jp symbols?
"Noto Sans Mono CJK JP" is famous. This width ratio is alphabet : Japanese = 1:2
my idea
fonts : https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKjp-hinted.zip
public void UiBuilder_OnBuildFonts()
{
var fontData = SomethingNeedDoingPlugin.ReadResource("SomethingNeedDoing.Fonts.ProggyVectorRegular.ttf");
var fontPtr = Marshal.AllocHGlobal(fontData.Length);
Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
var JPfontData = SomethingNeedDoingPlugin.ReadResource("SomethingNeedDoing.Fonts.NotoSansMonoCJKtc-Regular.otf");
var JPfontPtr = Marshal.AllocHGlobal(JPfontData.Length);
Marshal.Copy(JPfontData, 0, JPfontPtr, JPfontData.Length);
unsafe{
ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
fontConfig.MergeMode = true;
fontConfig.PixelSnapH = true;
ProggyVectorFont = ImGui.GetIO().Fonts.AddFontFromMemoryTTF(fontPtr, fontData.Length, plugin.Configuration.CustomFontSize, fontConfig);
// Set Japanese Font GlyphRanges
// Copy from
// https://github.com/goatcorp/Dalamud/blob/master/Dalamud/Interface/GlyphRangesJapanese.cs
var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned);
NotoSansMonoFont = ImGui.GetIO().Fonts.AddFontFromMemoryTTF(JPfontPtr, JPfontData.Length, plugin.Configuration.CustomFontSize, fontConfig, japaneseRangeHandle.AddrOfPinnedObject());
japaneseRangeHandle.Free();
}
}
// PluginUI.DisplayMacroEdit()
ImGui.PushFont(ProggyVectorFont);
ImGui.PushFont(NotoSansMonoFont);
var contents = node.Contents;
if (ImGui.InputTextMultiline($"##{node.Name}-editor", ref contents, 100_000, new Vector2(-1, -1)))
{
node.Contents = contents;
plugin.SaveConfiguration();
}
ImGui.PopFont();
ImGui.PopFont();
I assume you meant NotoSansMonoCJKjp-Regular.otf and not tc?
Oh, my mistake.
I'm not familiar with c#, should we release fontPtr (and JPfontPtr) in Dispose?
let me see what dalamud does with the default font ptr
There is no dispose method, I think ImGui handles it.
Implemented in 1.0.0.10.
The Macro Editor does not display Japanese characters.