Introduced extended FontRenderer plugin API, more fixes for "Clifftop's" SpriteFont #1744
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1742
CC: @criezy
This is an experimental change and related to plugin API, so opening as a draft for now. But it actually fixes all the "Whispers of the machine" font issues.
The reasoning for changes:
The old
IAGSFontRenderer
interface unfortunately did not provide proper means to return neither font height nor custom linespacing. Instead it had GetTextHeight(text), which in my honest opinion was a mistake to add, as fonts normally should have a specific height property even if individual characters (glyphs) have varied height.But anyway, the "Clifftop Games" abused GetTextHeight to also return linespacing depending on which text is passed as an argument, using "secret knowledge" about which lines engine uses for a font height test. This mechanic was doomed to be unreliable and eventually got broken after certain changes in the engine (see #1742 for details).
The proposed solution is to implement an extended FontRenderer interface, that lets to explicitly query for necessary font properties. In addition, engine plugin API needs a function for notifiying if the custom font have changed - because the SpriteFont allows to modify fonts from script in any given moment.
Proposed changes
Added
IAGSFontRenderer2
interface that inheritsIAGSFontRenderer
and adds following new members:Added new function to the engine API called
ReplaceFontRenderer2(int fontNumber, IAGSFontRenderer2* newRenderer)
, for setting new font renderer type. The reason why it needs a separate function is mainly that the old interface IAGSFontRenderer does not have any means to find out its version, therefore engine won't be able to find out if it's an extended interface or not. But since IAGSFontRenderer2 includes GetVersion function, it will be possible from now on.Added new function to the engine API called
NotifyFontUpdated(int fontNumber)
. This may be used by plugins to tell that the custom font has changed, so that engine could react to this (if it has cached font properties or has to redraw stuff, or else).In SpriteFont plugin: all font renderers implement IAGSFontRenderer2. Fixed VariableWidthSpriteFontRendererClifftopGames class to not return text height based on secret argument handling, but instead provide font height and linespacing in corresponding new functions.