mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
speed up monospace fonts
This commit is contained in:
parent
4a11dd28ec
commit
4cc6a83872
4 changed files with 19 additions and 1 deletions
|
|
@ -26,6 +26,11 @@ Font::Font(
|
|||
pages(std::move(pages)),
|
||||
glyphs(std::move(glyphs)),
|
||||
fontFile(std::move(fontFile)) {
|
||||
if (this->fontFile.has_value()) {
|
||||
if (auto fontPtr = this->fontFile->lock()) {
|
||||
monospace = fontPtr->isMonospace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Font::~Font() = default;
|
||||
|
|
@ -34,6 +39,10 @@ int Font::getYOffset() const {
|
|||
return yoffset;
|
||||
}
|
||||
|
||||
bool Font::isMonospace() const {
|
||||
return monospace;
|
||||
}
|
||||
|
||||
int Font::getLineHeight() const {
|
||||
return lineHeight;
|
||||
}
|
||||
|
|
@ -53,7 +62,7 @@ bool Font::isPrintableChar(uint codepoint) const {
|
|||
|
||||
int FontMetrics::calcWidth(std::wstring_view text, size_t offset, size_t length) const {
|
||||
auto font = this->font.has_value() ? this->font->lock() : nullptr;
|
||||
if (font == nullptr) {
|
||||
if (font == nullptr || font->isMonospace()) {
|
||||
return std::min(text.length() - offset, length) * _glyphInterval;
|
||||
}
|
||||
int totalWidth = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue