Changeset - r26658:a512a968af89
[Not reviewed]
master
0 4 0
Peter Nelson - 21 months ago 2022-12-17 23:34:19
peter1138@openttd.org
Change: Vertically centre sprite font relative to TrueType font.
4 files changed with 10 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/fontcache.h
Show inline comments
 
@@ -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.
src/gfx_layout.cpp
Show inline comments
 
@@ -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::FallbackVisualR
 
	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;
src/os/macosx/string_osx.cpp
Show inline comments
 
@@ -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::CoreTextVisualR
 
		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;
src/os/windows/string_uniscribe.cpp
Show inline comments
 
@@ -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 Unis
 
					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]);
 
					}
 
				}
0 comments (0 inline, 0 general)