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

Introduced extended FontRenderer plugin API, more fixes for "Clifftop's" SpriteFont #1744

Conversation

ivan-mogilko
Copy link
Contributor

@ivan-mogilko ivan-mogilko commented Jul 27, 2022

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 inherits IAGSFontRenderer and adds following new members:

Member function Description
int GetVersion () Returns engine API version this font renderer complies to. Must not be lower than 26 (this interface was added at API v26). If the interface is going to be expanded further in the future, the engine will be able to use this to find out whether it's safe to use newer methods.
const char* GetRendererName () Returns an arbitrary renderer name; this is for informational purposes only (logging, etc)
const char* GetFontName (int fontNumber) Returns given font's name (if available); again for informational purposes
int GetFontHeight (int fontNumber) Returns the given font's height: that is the maximal vertical size that the font glyphs may occupy.
int GetLineSpacing (int fontNumber) Returns the given font's linespacing; is allowed to return 0, telling that no specific linespacing is assigned for this font.

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.

@ivan-mogilko ivan-mogilko force-pushed the experiment--spritefontpluginapi branch 3 times, most recently from 1333f72 to 2da9a9f Compare July 30, 2022 05:27
@ivan-mogilko ivan-mogilko marked this pull request as ready for review July 30, 2022 05:33
@ivan-mogilko ivan-mogilko force-pushed the experiment--spritefontpluginapi branch from 2da9a9f to f07e8e2 Compare July 30, 2022 20:43
@ivan-mogilko
Copy link
Contributor Author

Fixed few bugs, added 1 potential optimization, confirmed that it's working with both "Kathy Rain" and "WoaM".

@ivan-mogilko ivan-mogilko merged commit de26927 into adventuregamestudio:master Jul 31, 2022
@ivan-mogilko ivan-mogilko deleted the experiment--spritefontpluginapi branch July 31, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in text display in Whispers of a Machine
1 participant