Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Vertically centre sprite font relative to TrueType font. #10254

Merged
merged 2 commits into from Dec 18, 2022

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented Dec 18, 2022

Motivation / Problem

Currently we try to draw the sprite font aligned to the base line of the TrueType font, however this has some issues:

  1. Individual sprite height is used but y_offs is ignored so sprites are not aligned correctly. This is noticeable with OpenGFX.
  2. If the TrueType font is smaller than the sprite font it overflows above the font.
  3. Since variable scaling, the sprite font is centred within the scaled font height when not using TrueType fonts.

Description

These are mostly resolved here by:

  1. Using the scaled sprite font height rather than individual sprite sizes. Alignment is always correct.
  2. & 3. Vertically centring the sprite within the TrueType font's height. This avoids overflowing above the font (it can still overflow, but this will be shared top & bottom), and makes the alignment consistent between TrueType and non-TrueType rendering.

Change when using Liberation Sans size 10 at 2x, old vs new:
image

Change when using Liberation Sans size 10 at 3x, old vs new:
image

Change in station label using Liberation Sans size 6 as 2x, old vs new:
image
image

(In these screenshots, it is the bus glyph that is incorrectly positioned before this change)

This change also fixes users of static function GetDefaultFontHeight() to call it properly.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@2TallTyler 2TallTyler merged commit daaa058 into OpenTTD:master Dec 18, 2022
@PeterN PeterN deleted the centre-sprite-font branch December 19, 2022 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants