From daaa05849304e6325778dac7fd4322df02a5a565 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 17 Dec 2022 23:34:19 +0000 Subject: [PATCH] Change: Vertically centre sprite font relative to TrueType font. --- src/fontcache.h | 4 ++-- src/gfx_layout.cpp | 7 ++++--- src/os/macosx/string_osx.cpp | 3 ++- src/os/windows/string_uniscribe.cpp | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/fontcache.h b/src/fontcache.h index 8eb6535a53..6cde1ab65e 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -29,12 +29,12 @@ protected: int descender; ///< The descender value of the font. int units_per_em; ///< The units per EM value of the font. - static int GetDefaultFontHeight(FontSize fs); - public: FontCache(FontSize fs); virtual ~FontCache(); + static int GetDefaultFontHeight(FontSize fs); + /** * Get the FontSize of the font. * @return The FontSize. diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index 01b5421bcf..40f9adeb94 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -11,6 +11,7 @@ #include "gfx_layout.h" #include "string_func.h" #include "strings_func.h" +#include "zoom_func.h" #include "debug.h" #include "table/control_codes.h" @@ -345,11 +346,11 @@ FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(Font *font, const for (int i = 0; i < this->glyph_count; i++) { this->glyphs[i] = font->fc->MapCharToGlyph(chars[i]); if (isbuiltin) { - this->positions[2 * i + 1] = font->fc->GetAscender(); // Apply sprite font's ascender. + this->positions[2 * i + 1] = font->fc->GetAscender(); // Apply sprite font's ascender. } else if (chars[i] >= SCC_SPRITE_START && chars[i] <= SCC_SPRITE_END) { - this->positions[2 * i + 1] = font->fc->GetAscender() - font->fc->GetGlyph(this->glyphs[i])->height - 1; // Align sprite glyphs to font baseline. + this->positions[2 * i + 1] = (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2; // Align sprite font to centre } else { - this->positions[2 * i + 1] = 0; // No ascender adjustment. + this->positions[2 * i + 1] = 0; // No ascender adjustment. } this->positions[2 * i + 2] = this->positions[2 * i] + font->fc->GetGlyphWidth(this->glyphs[i]); this->glyph_to_char[i] = i; diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index 5cd14e8e1e..c79ca88894 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -13,6 +13,7 @@ #include "../../strings_func.h" #include "../../table/control_codes.h" #include "../../fontcache.h" +#include "../../zoom_func.h" #include "macos.h" #include @@ -245,7 +246,7 @@ CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END) { this->glyphs[i] = font->fc->MapCharToGlyph(buff[this->glyph_to_char[i]]); this->positions[i * 2 + 0] = pts[i].x; - this->positions[i * 2 + 1] = font->fc->GetAscender() - font->fc->GetGlyph(this->glyphs[i])->height - 1; // Align sprite glyphs to font baseline. + this->positions[i * 2 + 1] = (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2; // Align sprite font to centre } else { this->glyphs[i] = gl[i]; this->positions[i * 2 + 0] = pts[i].x; diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index 7c70557b61..d4b122346a 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -14,6 +14,7 @@ #include "../../strings_func.h" #include "../../string_func.h" #include "../../table/control_codes.h" +#include "../../zoom_func.h" #include "win32.h" #include @@ -195,7 +196,7 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b if (buff[range.pos + i] >= SCC_SPRITE_START && buff[range.pos + i] <= SCC_SPRITE_END) { auto pos = range.char_to_glyph[i]; range.ft_glyphs[pos] = range.font->fc->MapCharToGlyph(buff[range.pos + i]); - range.offsets[pos].dv = range.font->fc->GetAscender() - range.font->fc->GetGlyph(range.ft_glyphs[pos])->height - 1; // Align sprite glyphs to font baseline. + range.offsets[pos].dv = (range.font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(range.font->fc->GetSize()))) / 2; // Align sprite font to centre range.advances[pos] = range.font->fc->GetGlyphWidth(range.ft_glyphs[pos]); } }