From 05d31cbeeb5683ba7b351d462302a46a9026c686 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Sun, 3 Jan 2021 19:37:34 +0100 Subject: LibTTF: Add hack for recognizing fixed-width fonts --- Userland/Libraries/LibTTF/Font.cpp | 7 +++++++ Userland/Libraries/LibTTF/Font.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibTTF/Font.cpp b/Userland/Libraries/LibTTF/Font.cpp index aa7166683b..81efaa7ca9 100644 --- a/Userland/Libraries/LibTTF/Font.cpp +++ b/Userland/Libraries/LibTTF/Font.cpp @@ -510,6 +510,13 @@ u16 Font::weight() const return 400; } +bool Font::is_fixed_width() const +{ + // FIXME: Read this information from the font file itself. + // FIXME: Although, it appears some application do similar hacks + return glyph_metrics(glyph_id_for_codepoint('.'), 1, 1).advance_width == glyph_metrics(glyph_id_for_codepoint('X'), 1, 1).advance_width; +} + int ScaledFont::width(const StringView& string) const { Utf8View utf8 { string }; diff --git a/Userland/Libraries/LibTTF/Font.h b/Userland/Libraries/LibTTF/Font.h index d1e96c0267..2448e8f6af 100644 --- a/Userland/Libraries/LibTTF/Font.h +++ b/Userland/Libraries/LibTTF/Font.h @@ -78,7 +78,7 @@ public: String family() const; String variant() const; u16 weight() const; - bool is_fixed_width() const { return false; } /* TODO */ + bool is_fixed_width() const; private: enum class Offsets { -- cgit v1.2.3