Skip to content

Commit

Permalink
more localisation support
Browse files Browse the repository at this point in the history
add glyph ranges
fix resizing of tabs in addons window
  • Loading branch information
DeltaGW2 committed Mar 17, 2024
1 parent c992925 commit 5cf712e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
43 changes: 29 additions & 14 deletions src/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,18 +640,33 @@ namespace GUI

std::filesystem::path fontPath{};

ImVector<ImWchar> ranges;

ImFontGlyphRangesBuilder rb{};
ImWchar rangesLatinExt[] =
{
0x0100, 0x017F,
0x0180, 0x024F,
0,
};
rb.AddRanges(io.Fonts->GetGlyphRangesDefault());
rb.AddRanges(rangesLatinExt);
rb.AddRanges(io.Fonts->GetGlyphRangesCyrillic());
rb.AddRanges(io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
rb.BuildRanges(&ranges);

/* add user font, or fallback to default */
if (!LinkArcDPSStyle && std::filesystem::exists(Path::F_FONT))
{
fontPath = Path::F_FONT;
std::string strFont = Path::F_FONT.string();
io.Fonts->AddFontFromFileTTF(strFont.c_str(), FontSize, nullptr, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
io.Fonts->AddFontFromFileTTF(strFont.c_str(), FontSize, nullptr, ranges.Data);
}
else if (LinkArcDPSStyle && std::filesystem::exists(Path::D_GW2_ADDONS / "arcdps" / "arcdps_font.ttf"))
{
fontPath = Path::D_GW2_ADDONS / "arcdps" / "arcdps_font.ttf";
std::string strFont = (Path::D_GW2_ADDONS / "arcdps" / "arcdps_font.ttf").string();
io.Fonts->AddFontFromFileTTF(strFont.c_str(), FontSize, nullptr, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
io.Fonts->AddFontFromFileTTF(strFont.c_str(), FontSize, nullptr, ranges.Data);
}
else
{
Expand All @@ -673,35 +688,35 @@ namespace GUI

/* small UI*/
FontIndex.emplace(EFont::Menomonia_Small, io.Fonts->AddFontFromMemoryTTF(resM, szM, 16.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 16.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 16.0f, &config, ranges.Data); }
FontIndex.emplace(EFont::MenomoniaBig_Small, io.Fonts->AddFontFromMemoryTTF(resM, szM, 22.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 22.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 22.0f, &config, ranges.Data); }
FontIndex.emplace(EFont::Trebuchet_Small, io.Fonts->AddFontFromMemoryTTF(resT, szT, 15.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 15.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 15.0f, &config, ranges.Data); }

/* normal UI*/
FontIndex.emplace(EFont::Menomonia_Normal, io.Fonts->AddFontFromMemoryTTF(resM, szM, 18.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 18.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 18.0f, &config, ranges.Data); }
FontIndex.emplace(EFont::MenomoniaBig_Normal, io.Fonts->AddFontFromMemoryTTF(resM, szM, 24.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 24.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 24.0f, &config, ranges.Data); }
FontIndex.emplace(EFont::Trebuchet_Normal, io.Fonts->AddFontFromMemoryTTF(resT, szT, 16.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 16.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 16.0f, &config, ranges.Data); }

/* large UI*/
FontIndex.emplace(EFont::Menomonia_Large, io.Fonts->AddFontFromMemoryTTF(resM, szM, 20.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 20.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 20.0f, &config, ranges.Data); }
FontIndex.emplace(EFont::MenomoniaBig_Large, io.Fonts->AddFontFromMemoryTTF(resM, szM, 26.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 26.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 26.0f, &config, ranges.Data); }
FontIndex.emplace(EFont::Trebuchet_Large, io.Fonts->AddFontFromMemoryTTF(resT, szT, 17.5f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 17.5f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 17.5f, &config, ranges.Data); }

/* larger UI*/
FontIndex.emplace(EFont::Menomonia_Larger, io.Fonts->AddFontFromMemoryTTF(resM, szM, 22.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 22.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 22.0f, &config, ranges.Data); }
FontIndex.emplace(EFont::MenomoniaBig_Larger, io.Fonts->AddFontFromMemoryTTF(resM, szM, 28.0f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 28.0f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 28.0f, &config, ranges.Data); }
FontIndex.emplace(EFont::Trebuchet_Larger, io.Fonts->AddFontFromMemoryTTF(resT, szT, 19.5f));
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 19.5f, &config, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); }
if (!fontPath.empty()) { io.Fonts->AddFontFromFileTTF(fontPath.string().c_str(), 19.5f, &config, ranges.Data); }
}

io.Fonts->Build();
Expand Down
12 changes: 8 additions & 4 deletions src/GUI/Widgets/Addons/CAddonsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ namespace GUI

ImVec2 text1sz = ImGui::CalcTextSize(Language.Translate("((000031))"));
ImVec2 text2sz = ImGui::CalcTextSize(Language.Translate("((000032))"));
ImVec2 text1offset = ImVec2(((92.0f * Renderer::Scaling) - text1sz.x) / 2, ((24.0f * Renderer::Scaling) - text1sz.y) / 2);
ImVec2 text2offset = ImVec2(((92.0f * Renderer::Scaling) - text2sz.x) / 2, ((24.0f * Renderer::Scaling) - text2sz.y) / 2);

float tab1width = 92.0f > text1sz.x ? 92.0f : text1sz.x + 50.0f;
float tab2width = 92.0f > text2sz.x ? 92.0f : text2sz.x + 50.0f;

ImVec2 text1offset = ImVec2(((tab1width * Renderer::Scaling) - text1sz.x) / 2, ((24.0f * Renderer::Scaling) - text1sz.y) / 2);
ImVec2 text2offset = ImVec2(((tab2width * Renderer::Scaling) - text2sz.x) / 2, ((24.0f * Renderer::Scaling) - text2sz.y) / 2);

ImVec2 tab1origin = ImGui::GetCursorPos(); // 28.0f, 28.0f

Expand All @@ -116,7 +120,7 @@ namespace GUI
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));

if (ImGui::ImageButton(!Tab1Hovered ? TabBtn->Resource : TabBtnHover->Resource, ImVec2(92.0f * Renderer::Scaling, 24.0f * Renderer::Scaling)))
if (ImGui::ImageButton(!Tab1Hovered ? TabBtn->Resource : TabBtnHover->Resource, ImVec2(tab1width * Renderer::Scaling, 24.0f * Renderer::Scaling)))
{
TabIndex = 0;
}
Expand All @@ -126,7 +130,7 @@ namespace GUI

ImVec2 tab2origin = ImGui::GetCursorPos();

if (ImGui::ImageButton(!Tab2Hovered ? TabBtn->Resource : TabBtnHover->Resource, ImVec2(92.0f * Renderer::Scaling, 24.0f * Renderer::Scaling)))
if (ImGui::ImageButton(!Tab2Hovered ? TabBtn->Resource : TabBtnHover->Resource, ImVec2(tab2width * Renderer::Scaling, 24.0f * Renderer::Scaling)))
{
TabIndex = 1;
}
Expand Down

0 comments on commit 5cf712e

Please sign in to comment.