Change: Vertically centre sprite font relative to TrueType font.

pull/441/head
Peter Nelson 1 year ago committed by Tyler Trahan
parent 8599041ce4
commit daaa058493

@ -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.

@ -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;

@ -13,6 +13,7 @@
#include "../../strings_func.h"
#include "../../table/control_codes.h"
#include "../../fontcache.h"
#include "../../zoom_func.h"
#include "macos.h"
#include <CoreFoundation/CoreFoundation.h>
@ -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;

@ -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 <vector>
@ -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]);
}
}

Loading…
Cancel
Save