Replace Greek and Mathematical Operators font fallback with Iosevka Extended for improved font handling.

This commit is contained in:
2026-01-11 12:07:24 -08:00
parent a8abda4b87
commit 4c402f5ef3
4 changed files with 40 additions and 60 deletions

View File

@@ -18,6 +18,7 @@
#include "GUITheme.h" #include "GUITheme.h"
#include "fonts/Font.h" // embedded default font (DefaultFont) #include "fonts/Font.h" // embedded default font (DefaultFont)
#include "fonts/FontRegistry.h" #include "fonts/FontRegistry.h"
#include "fonts/IosevkaExtended.h"
#include "syntax/HighlighterRegistry.h" #include "syntax/HighlighterRegistry.h"
#include "syntax/NullHighlighter.h" #include "syntax/NullHighlighter.h"
@@ -369,30 +370,19 @@ GUIFrontend::LoadGuiFont_(const char * /*path*/, const float size_px)
&config, &config,
io.Fonts->GetGlyphRangesDefault()); io.Fonts->GetGlyphRangesDefault());
// Merge Greek and Coptic // Merge Greek and Mathematical symbols from IosevkaExtended
config.MergeMode = true; config.MergeMode = true;
static const ImWchar greek_ranges[] = { static const ImWchar extended_ranges[] = {
0x0370, 0x03FF, // Greek and Coptic 0x0370, 0x03FF, // Greek and Coptic
0,
};
io.Fonts->AddFontFromMemoryCompressedTTF(
kte::Fonts::DefaultFontData,
kte::Fonts::DefaultFontSize,
size_px,
&config,
greek_ranges);
// Merge Mathematical Operators
static const ImWchar math_ranges[] = {
0x2200, 0x22FF, // Mathematical Operators 0x2200, 0x22FF, // Mathematical Operators
0, 0,
}; };
io.Fonts->AddFontFromMemoryCompressedTTF( io.Fonts->AddFontFromMemoryCompressedTTF(
kte::Fonts::DefaultFontData, kte::Fonts::IosevkaExtended::DefaultFontRegularCompressedData,
kte::Fonts::DefaultFontSize, kte::Fonts::IosevkaExtended::DefaultFontRegularCompressedSize,
size_px, size_px,
&config, &config,
math_ranges); extended_ranges);
io.Fonts->Build(); io.Fonts->Build();
return true; return true;

View File

@@ -560,7 +560,7 @@ ImGuiRenderer::Draw(Editor &ed)
(size_t) std::max<size_t>( (size_t) std::max<size_t>(
1, (size_t) (tail.size() / 4))) 1, (size_t) (tail.size() / 4)))
: 1; : 1;
start += skip; start += skip;
std::string candidate = tail.substr(start); std::string candidate = tail.substr(start);
ImVec2 cand_sz = ImGui::CalcTextSize(candidate.c_str()); ImVec2 cand_sz = ImGui::CalcTextSize(candidate.c_str());
if (cand_sz.x <= avail_px) { if (cand_sz.x <= avail_px) {
@@ -618,11 +618,11 @@ ImGuiRenderer::Draw(Editor &ed)
std::size_t total = ed.BufferCount(); std::size_t total = ed.BufferCount();
if (total > 0) { if (total > 0) {
std::size_t idx1 = ed.CurrentBufferIndex() + 1; // 1-based for display std::size_t idx1 = ed.CurrentBufferIndex() + 1; // 1-based for display
left += "["; left += "[";
left += std::to_string(static_cast<unsigned long long>(idx1)); left += std::to_string(static_cast<unsigned long long>(idx1));
left += "/"; left += "/";
left += std::to_string(static_cast<unsigned long long>(total)); left += std::to_string(static_cast<unsigned long long>(total));
left += "] "; left += "] ";
} }
} }
left += fname; left += fname;
@@ -631,9 +631,9 @@ ImGuiRenderer::Draw(Editor &ed)
// Append total line count as "<n>L" // Append total line count as "<n>L"
{ {
unsigned long lcount = static_cast<unsigned long>(buf->Rows().size()); unsigned long lcount = static_cast<unsigned long>(buf->Rows().size());
left += " "; left += " ";
left += std::to_string(lcount); left += std::to_string(lcount);
left += "L"; left += "L";
} }
// Build right text (cursor/mark) // Build right text (cursor/mark)

View File

@@ -142,13 +142,13 @@ protected:
p.save(); p.save();
p.setClipRect(viewport); p.setClipRect(viewport);
// Iterate visible lines // Iterate visible lines
for (std::size_t i = rowoffs, vis_idx = 0; i < last_row; ++i, ++vis_idx) { for (std::size_t i = rowoffs, vis_idx = 0; i < last_row; ++i, ++vis_idx) {
// Materialize the Buffer::Line into a std::string for // Materialize the Buffer::Line into a std::string for
// regex/iterator usage and general string ops. // regex/iterator usage and general string ops.
const std::string line = static_cast<std::string>(lines[i]); const std::string line = static_cast<std::string>(lines[i]);
const int y = viewport.y() + static_cast<int>(vis_idx) * line_h; const int y = viewport.y() + static_cast<int>(vis_idx) * line_h;
const int baseline = y + fm.ascent(); const int baseline = y + fm.ascent();
// Helper: convert src col -> rx with tab expansion // Helper: convert src col -> rx with tab expansion
auto src_to_rx_line = [&](std::size_t src_col) -> std::size_t { auto src_to_rx_line = [&](std::size_t src_col) -> std::size_t {
@@ -453,11 +453,11 @@ protected:
std::size_t total = ed_->BufferCount(); std::size_t total = ed_->BufferCount();
if (total > 0) { if (total > 0) {
std::size_t idx1 = ed_->CurrentBufferIndex() + 1; // 1-based std::size_t idx1 = ed_->CurrentBufferIndex() + 1; // 1-based
left += QStringLiteral(" ["); left += QStringLiteral(" [");
left += QString::number(static_cast<qlonglong>(idx1)); left += QString::number(static_cast<qlonglong>(idx1));
left += QStringLiteral("/"); left += QStringLiteral("/");
left += QString::number(static_cast<qlonglong>(total)); left += QString::number(static_cast<qlonglong>(total));
left += QStringLiteral("] "); left += QStringLiteral("] ");
} else { } else {
left += QStringLiteral(" "); left += QStringLiteral(" ");
} }
@@ -477,9 +477,9 @@ protected:
// total lines suffix " <n>L" // total lines suffix " <n>L"
unsigned long lcount = static_cast<unsigned long>(buf->Rows().size()); unsigned long lcount = static_cast<unsigned long>(buf->Rows().size());
left += QStringLiteral(" "); left += QStringLiteral(" ");
left += QString::number(static_cast<qlonglong>(lcount)); left += QString::number(static_cast<qlonglong>(lcount));
left += QStringLiteral("L"); left += QStringLiteral("L");
} }
// Build right segment: cursor and mark // Build right segment: cursor and mark
@@ -602,12 +602,12 @@ protected:
int d_cols = 0; int d_cols = 0;
if (std::fabs(v_scroll_accum_) >= 1.0 && (!horiz_mode || std::fabs(v_scroll_accum_) > std::fabs( if (std::fabs(v_scroll_accum_) >= 1.0 && (!horiz_mode || std::fabs(v_scroll_accum_) > std::fabs(
h_scroll_accum_))) { h_scroll_accum_))) {
d_rows = static_cast<int>(v_scroll_accum_); d_rows = static_cast<int>(v_scroll_accum_);
v_scroll_accum_ -= d_rows; v_scroll_accum_ -= d_rows;
} }
if (std::fabs(h_scroll_accum_) >= 1.0 && (horiz_mode || std::fabs(h_scroll_accum_) >= std::fabs( if (std::fabs(h_scroll_accum_) >= 1.0 && (horiz_mode || std::fabs(h_scroll_accum_) >= std::fabs(
v_scroll_accum_))) { v_scroll_accum_))) {
d_cols = static_cast<int>(h_scroll_accum_); d_cols = static_cast<int>(h_scroll_accum_);
h_scroll_accum_ -= d_cols; h_scroll_accum_ -= d_cols;
} }

View File

@@ -1,4 +1,5 @@
#include "Font.h" #include "Font.h"
#include "IosevkaExtended.h"
#include "imgui.h" #include "imgui.h"
@@ -20,30 +21,19 @@ Font::Load(const float size) const
&config, &config,
io.Fonts->GetGlyphRangesDefault()); io.Fonts->GetGlyphRangesDefault());
// Merge Greek and Coptic // Merge Greek and Mathematical symbols from IosevkaExtended as fallback
config.MergeMode = true; config.MergeMode = true;
static const ImWchar greek_ranges[] = { static const ImWchar extended_ranges[] = {
0x0370, 0x03FF, // Greek and Coptic 0x0370, 0x03FF, // Greek and Coptic
0,
};
io.Fonts->AddFontFromMemoryCompressedTTF(
this->data_,
this->size_,
size,
&config,
greek_ranges);
// Merge Mathematical Operators
static const ImWchar math_ranges[] = {
0x2200, 0x22FF, // Mathematical Operators 0x2200, 0x22FF, // Mathematical Operators
0, 0,
}; };
io.Fonts->AddFontFromMemoryCompressedTTF( io.Fonts->AddFontFromMemoryCompressedTTF(
this->data_, kte::Fonts::IosevkaExtended::DefaultFontRegularCompressedData,
this->size_, kte::Fonts::IosevkaExtended::DefaultFontRegularCompressedSize,
size, size,
&config, &config,
math_ranges); extended_ranges);
io.Fonts->Build(); io.Fonts->Build();
} }