Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Dual Font Support #4267

Closed
wzdev-ci opened this issue Dec 29, 2014 · 20 comments
Closed

Dual Font Support #4267

wzdev-ci opened this issue Dec 29, 2014 · 20 comments

Comments

@wzdev-ci
Copy link
Contributor

resolution_Requesting more information about issue type_patch (an actual patch, not a request for one) | by wuz21m


This patch adds Xolonium Bold 24p for Bold(Main Menu) and Exo 2 15p Regular for Regular (everywhere else).

GLC fallback still works. Appropriate error messages are generated when a font is missing.
If both are missing, an awful looking fallback that is neither is used.
If Exo2 is missing, Xolonium is used everywhere.
If Xolonium is missing, Exo2 is used everywhere.


Issue migrated from trac:4267 at 2022-04-16 11:48:11 -0700

@wzdev-ci
Copy link
Contributor Author

wuz21m uploaded file new_fonts.patch (6.2 KiB)

@wzdev-ci
Copy link
Contributor Author

wuz21m commented


This patch is based on discussions here: forums.wz2100.net/viewtopic.php?f=33&t=11954

Here are two catches:
-The patch is made against a week-old version of Warzone master. I haven't updated because I didn't make a branch (sorry for being lazy!)
-The locale you are testing for now must be supported by both Xolonium and Exo 2. Note that both these fonts support a wide array of languages, but not every locale in the game

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 3, 2015

stiv changed blocking which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 3, 2015

stiv changed blockedby which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 3, 2015

stiv commented


If both are missing, an awful looking fallback that is neither is used.

Why are we using an 'awful' font for the fallback?

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 5, 2015

wuz21m changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 5, 2015

wuz21m commented


It is the default chosen by GLC I believe.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 7, 2015

wuz21m uploaded file big_font_patch.patch (16.2 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 7, 2015

wuz21m changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 7, 2015

wuz21m commented


As vexed correctly asserted. Trying to change font sizes or fonts is pretty cumbersome with the current system.

I went ahead and wrote a large patch. This patch, does the following:
A font configuration file is added. It resides at fonts/font.cfg and is in the JSON format. In this configuration file, a pair of fonts (Regular and Bold) along with sizes for small,regular,medium and bold can be supplied. The configurations are per-locale. For example, Xolonium 21p is the Bold font and Exo 2 is used for everything else (at the original sizes).
If the current language is not assigned a font in the config file, an error message is logged and a "Default" configuration (the current font used for Warzone 2100, aka, DejaVu Sans Book and Bold) is used.
The font subsystem can switch fonts on the fly now. In other words, if the language is changed in the "config" menu, the font is immediately reconfigured preventing garbled fonts from being shown.

These are the summary of code changes:
1- A function called getLocale is implemented based on getLanguage. The reason I added this new function is that I needed a function that will tell me the language (I care about the charset, not the full locale). getLanguage is unusable because getLanguage has two issues:

-It return "" when "system default" is picked. We need the actual language (e.g. Russian, English).
-It returns en_GB, en_US, when we are only interested in the "en" part.

2- Added a new config file at fonts/font.cfg. Its structure assigns a font and font size per locale.
3- To read the font config file only once, a map called fontMap is added to textdraw. Fontmap is a map from language (e.g. "en", "ru") to parameters (FontProperties font name and size).
4- iV_font is no longer called from outside. iV_loadFontConfig is called along with the wrf files (more on this later). Another function that is called from outside (more than once this time) is iV_TextInit (State is stored so extra calls to iV_TextInit and iV_loadFontConfig are skipped).
5- I had to add the font config to both basic.wrf and frontend.wrf. frontend.wrt is loaded on normal start, but it is circumvented when the game is called with the --game=XYZ option. So I added font.cfg to both files. As I stated in point 4, multiple calls are avoided because the state is checked. dataFontCfgLoad is added so the appropriate wrf file fields are parsed.
6- I had to move the iV_TextInit calls outside where is used to (systemInitialize in init.cpp) and moved it downwards to "frontendInitialise" and "stageTwoInitialise" init.cpp. Also, an extra is added to "runGameOptionsMenu" every time a font is accessed so the appropriate font is re-selected based on the fontMap.

I will be very happy to get any feedback.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 7, 2015

vexed commented


No, haven't looked at this yet, but, this should be a patch for master (3.1 is feature locked), although, we can use the new font files for 3.1.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 8, 2015

wuz21m changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 8, 2015

wuz21m commented


Based on suggestion from cybersphinx, I split the patch into multiple patch files so they could be reviewed more easily.

This is a survey of the patches:

i18n.patch -> Changes to the internationalization package
Addition of function getLocale(). The difference this function has of getLanguage (on which it is based is that)
-It always returns a language (even if default is picked) if the language is unsupported, it returns en
-It returns en instead of en_GB, en_US and so on

wrf.patch -> additions to the wrf file and respective changes in data.cpp
Added file font.cfg to wrf. This allows moddable fonts from what I understand of WZ2100
Added a new format (FONTCFG) and handling function dataFontCfgLoad.

text_interface.patch -> Changes to how textdraw is configured from outside
No calls to iV_font from outside. It is called internally by textdraw.cpp
Instead iV_loadFontConfig is called from data.cpp (in wrf.patch)
To initialize text, previously. iV_TextInit was called only once before any wrf files were loaded. This had to change. Now iV_TextInit is called whenever a wrf is loaded. Duplicate calls are blocked internally by textdraw.cpp to enhance performance

textdraw.patch -> the real deal, changes to textdraw.cpp
This contains these major code changes:
font_family[128] is replaced by font_family_regular and font_family_bold, this allows separate fonts to be used for Bold (used in menu) vs the rest of places.
font_regular_size, font_medium_size, font_bold_size and font_small_size are now variables. They used to be hard-coded to 12, 16, 21 and 9 respectively. They are configured based on font.cfg.
FontProperties is a data structure filled by font.cfg
fontMap stores all the loaded data front font.cfg. As a result, we will load font.cfg only once.
iV_font has a different interface now. It configures fontfaces as well as font sizes.
iV_chooseFont selects font based on the current locale (getLocale in i18n.patch)
iV_loadFontConfig given the font.cfg file, it fills the fontMap (called from data.cpp)
iV_initializeGLC used to block second calls. Now it will clean-up and start anew.
iV_TextInit calls chooseFont. If the font indeed changed (checked by mustUpdateFont) it will call re initialized the fonts.

I think that's all!

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 8, 2015

wuz21m uploaded file i18n.patch (2.1 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 8, 2015

wuz21m uploaded file wrf.patch (1.7 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 8, 2015

wuz21m uploaded file textdraw.patch (9.7 KiB)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 8, 2015

wuz21m uploaded file text_interface.patch (2.7 KiB)

@wzdev-ci
Copy link
Contributor Author

vexed changed status from new to closed

@wzdev-ci
Copy link
Contributor Author

vexed changed resolution from `` to Requesting more information about issue

@wzdev-ci
Copy link
Contributor Author

vexed commented


I know we have changed font rendering engines since this ticket was made, and it seems this got lost, and wouldn't apply anymore.

Is this still an issue or is something that is needed?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant