mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 06:51: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
|
|
@ -30,6 +30,7 @@ namespace {
|
||||||
public:
|
public:
|
||||||
FTFontFile(FT_Face face, util::Buffer<ubyte> buffer)
|
FTFontFile(FT_Face face, util::Buffer<ubyte> buffer)
|
||||||
: face(std::move(face)), buffer(std::move(buffer)) {
|
: face(std::move(face)), buffer(std::move(buffer)) {
|
||||||
|
monospace = this->face->face_flags & FT_FACE_FLAG_FIXED_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
~FTFontFile() {
|
~FTFontFile() {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,12 @@ namespace vector_fonts {
|
||||||
virtual std::unique_ptr<Texture> renderPage(
|
virtual std::unique_ptr<Texture> renderPage(
|
||||||
int pageid, std::vector<Glyph>& glyphs, int size
|
int pageid, std::vector<Glyph>& glyphs, int size
|
||||||
) = 0;
|
) = 0;
|
||||||
|
|
||||||
|
bool isMonospace() const {
|
||||||
|
return monospace;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
bool monospace = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,11 @@ Font::Font(
|
||||||
pages(std::move(pages)),
|
pages(std::move(pages)),
|
||||||
glyphs(std::move(glyphs)),
|
glyphs(std::move(glyphs)),
|
||||||
fontFile(std::move(fontFile)) {
|
fontFile(std::move(fontFile)) {
|
||||||
|
if (this->fontFile.has_value()) {
|
||||||
|
if (auto fontPtr = this->fontFile->lock()) {
|
||||||
|
monospace = fontPtr->isMonospace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::~Font() = default;
|
Font::~Font() = default;
|
||||||
|
|
@ -34,6 +39,10 @@ int Font::getYOffset() const {
|
||||||
return yoffset;
|
return yoffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Font::isMonospace() const {
|
||||||
|
return monospace;
|
||||||
|
}
|
||||||
|
|
||||||
int Font::getLineHeight() const {
|
int Font::getLineHeight() const {
|
||||||
return lineHeight;
|
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 {
|
int FontMetrics::calcWidth(std::wstring_view text, size_t offset, size_t length) const {
|
||||||
auto font = this->font.has_value() ? this->font->lock() : nullptr;
|
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;
|
return std::min(text.length() - offset, length) * _glyphInterval;
|
||||||
}
|
}
|
||||||
int totalWidth = 0;
|
int totalWidth = 0;
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public:
|
||||||
);
|
);
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
|
bool isMonospace() const;
|
||||||
int getLineHeight() const;
|
int getLineHeight() const;
|
||||||
int getYOffset() const;
|
int getYOffset() const;
|
||||||
|
|
||||||
|
|
@ -94,6 +95,7 @@ private:
|
||||||
int lineHeight;
|
int lineHeight;
|
||||||
int yoffset;
|
int yoffset;
|
||||||
int glyphInterval;
|
int glyphInterval;
|
||||||
|
bool monospace = true;
|
||||||
std::vector<std::unique_ptr<Texture>> pages;
|
std::vector<std::unique_ptr<Texture>> pages;
|
||||||
std::vector<Glyph> glyphs;
|
std::vector<Glyph> glyphs;
|
||||||
std::optional<std::weak_ptr<vector_fonts::FontFile>> fontFile;
|
std::optional<std::weak_ptr<vector_fonts::FontFile>> fontFile;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue