Using different fonts in the Translation settings file for 'normal font'

Started by Gal Shemesh, Tue 20/06/2023 12:52:07

Previous topic - Next topic

Gal Shemesh

Hi everyone,

I'm having an issue setting up a specific font style for the 'normal font' text in my Hebrew translation file. According to the 'Translation settings' section, these are the instructions:

// ** Translation settings are below
// ** Leave them as "DEFAULT" to use the game settings
// The normal font to use - DEFAULT or font number
//#NormalFont=DEFAULT
// The speech font to use - DEFAULT or font number
//#SpeechFont=DEFAULT
// Text direction - DEFAULT, LEFT or RIGHT
//#TextDirection=RIGHT


I wish to have separated English and Hebrew fonts in my game, and not a mix of one font that has the characters of both languages, as I found that if my English letters are taller than my Hebrew ones, the Hebrew letters will have more 'empty space' on their top / bottom side and vise versa.

I understand that if the values above remain as DEFAULT the engine will use the default fonts in index 0 and 1 (there's also index 2 for the outline font for which I have another question below). So I added 3 additional fonts that contain the Hebrew letters in index 3 (for normal font), 4 (for speech) and 5 (for outline), and I wish that the engine will pick them up if the game is run in Hebrew from the game setup.



So I went into the Translation file and set the NormalFont line to 3 and the SpeechFont to 4, however the engine still go and pick the Normal font in index 0 even if Hebrew is picked for the game language in the game setup, and so the game appears in gibberish since there's no Hebrew letters drawn in the normal font index 0. If I import the Hebrew font over the normal font index 0 then everything appears fine of course.

Any idea of why the engine doesn't pick the new index font numbers even if it's set up in the Translation file?

As for the outline font question, since it's not mentioned in the translation file instructions, is whether there's a "//#SpeechOutlineFont=" option for setting up a custom outline font for the engine to pick if run in Hebrew from the game setup?

Thanks
Gal Shemesh,
goldeng

Crimson Wizard

Sorry for the silly question, but have you recompiled translation after changing this?

Quote from: Gal Shemesh on Tue 20/06/2023 12:52:07As for the outline font question, since it's not mentioned in the translation file instructions, is whether there's a "//#SpeechOutlineFont=" option for setting up a custom outline font for the engine to pick if run in Hebrew from the game setup?

No, but you may configure this in the Hebrew font itself (in the editor).

Gal Shemesh

Not silly question at all. I very appreciate your prompt responses and your kindness trying to help me out. :)

Yep, I did compiled the translation file. I even tried to update it and also to rebuild all files just to be on the safe side, although it may not be necessary. Nothing helps... The engine seems to ignore the fact that
Code: ags
//#NormalFont=3
and
Code: ags
//#SpeechFont=4
are present in the translation file.

As for your reference to my outline font question - thanks! Didn't know it can be done from the editor. Silly me...
Gal Shemesh,
goldeng

Crimson Wizard

I need to clarify, how do you see that the font is not replaced? Do you refer to the GUI?

If i remember right, the GUI fonts are not replaced by translation options at all. These options affect only speech and messages done using Display.
NormalFont is for general messages, SpeechFont is for the speech only.

If you need to replace fonts on GUI, you need to run over all guis and replace the font property on all eligible controls
Spoiler
Code: ags
function ReplaceFontOnAllGUI(int old_font, int new_font)
{
    for (int i = 0; i < Game.GUICount; i++)
    {
         for (int j = 0; j < guis[i].ControlCount; j++)
         {
              GUIControl* c= guis[i].Controls[j];
              Button* btn = c.AsButton;
              if (btn != null && btn.Font == old_font)
                   btn.Font = new_font;
              // and so on
         }
    }
}
[close]

Sinitrena

Okay, it's forever since I did anything in AGS and especially with translations, so ignore me if I'm on a completely wrong track here, but:

Doesn't // usually mean that that part of the script is commeted out and the editor therefore won't run this line? Try removing // in front of your code.

Crimson Wizard

Quote from: Sinitrena on Wed 21/06/2023 00:13:35Doesn't // usually mean that that part of the script is commeted out and the editor therefore won't run this line? Try removing // in front of your code.

Translation files use comments to also have options.

https://adventuregamestudio.github.io/ags-manual/Translations.html#additional-options

Gal Shemesh

Quote from: Crimson Wizard on Wed 21/06/2023 00:09:46I need to clarify, how do you see that the font is not replaced? Do you refer to the GUI?

If i remember right, the GUI fonts are not replaced by translation options at all. These options affect only speech and messages done using Display.
NormalFont is for general messages, SpeechFont is for the speech only.

If you need to replace fonts on GUI, you need to run over all guis and replace the font property on all eligible controls
Spoiler
Code: ags
function ReplaceFontOnAllGUI(int old_font, int new_font)
{
    for (int i = 0; i < Game.GUICount; i++)
    {
         for (int j = 0; j < guis[i].ControlCount; j++)
         {
              GUIControl* c= guis[i].Controls[j];
              Button* btn = c.AsButton;
              if (btn != null && btn.Font == old_font)
                   btn.Font = new_font;
              // and so on
         }
    }
}
[close]

Yep, you're right. I'm checking this on the GUI panels and I just now realize that the translation file settings don't affect them. I didn't even went to check if it works on regular speech and just now after reading your comment I find that it works for speech.

Thanks for the workaround code. But won't it be a static solution only for the font that is set there? I mean, the idea I had in mind is that the GUI font will be different for either English and Hebrew - again, only so I could have taller / shorter letters for each language. Otherwise from what I had checked, if both languages are set on the same 256 characters font set, the height of the font will be based on the taller character in the entire set. So if I have taller English letters and shorter Hebrew ones, the Hebrew ones will look like they have a gap of empty space from top / bottom...
Gal Shemesh,
goldeng

Crimson Wizard

Quote from: Gal Shemesh on Wed 21/06/2023 00:21:42Thanks for the workaround code. But won't it be a static solution only for the font that is set there? I mean, the idea I had in mind is that the GUI font will be different for either English and Hebrew - again, only so I could have taller / shorter letters for each language. Otherwise from what I had checked, if both languages are set on the same 256 characters font set, the height of the font will be based on the taller character in the entire set. So if I have taller English letters and shorter Hebrew ones, the Hebrew ones will look like they have a gap of empty space from top / bottom...

I'm sorry, I could not understand what you are asking about exactly?
The GUI are aligning text according to the font size, if a Font reference is changed in script, then it will recalculate text's position accordingly.

Gal Shemesh

Sorry, maybe I did not make myself clear.

You're right - in GUI elements the font is centered. However, in message boxes like in the screenshot below, if one of the languages has taller characters, whether they're in use in the string or not, the language with the shorter characters will be drawn in runtime with more space around the letters. I took the original template font and copied only the Hebrew alphabet characters to it to show what I mean.

As you can see in the screenshot below, there's more 'gap' below the Hebrew characters - gap which is based of the English characters height. Moreover, some characters like punctuation marks are shared between both languages if they're both on the same font file, and so it makes their alignment to one of the languages to look odd as you can see.

The other problem I find is if say a game has more than 2 languages - everything regarding speech will be okay as the appropriate language font index number can be set in the translation file. But all the GUI elements will be based on font index 0 which has only up to 2 sets of language characters. So the 3rd language and above won't be able to reflect for GUI elements if I understand it correctly...



Gal Shemesh,
goldeng

Crimson Wizard

Quote from: Gal Shemesh on Wed 21/06/2023 10:03:16As you can see in the screenshot below, there's more 'gap' below the Hebrew characters - gap which is based of the English characters height. Moreover, some characters like punctuation marks are shared between both languages if they're both on the same font file, and so it makes their alignment to one of the languages to look odd as you can see.

Well, it's the general issue when using fonts that contain multiple languages, just like any Unicode fonts for instance. Of course, the font height is a fixed value, and engine uses it and not the particular letter sizes when aligning the text, or wrapping a text, breaking it in several lines with vertical gaps in between.
This is more a question of designing a font well.

If that bugs you, options are to redesign the multilang font, or use separate fonts per language, where you would adjust punctuation for each language separately.


Quote from: Gal Shemesh on Wed 21/06/2023 10:03:16The other problem I find is if say a game has more than 2 languages - everything regarding speech will be okay as the appropriate language font index number can be set in the translation file. But all the GUI elements will be based on font index 0 which has only up to 2 sets of language characters. So the 3rd language and above won't be able to reflect for GUI elements if I understand it correctly...

Yes, like I mentioned, GUI fonts are not remapped automatically by the translation's option. This is current limitation of AGS: if you add a language, which requires another font, then you need to also add this font into the game, and order GUIs to swap to that font depending on current translation in script (either on startup, or after the language is changed in game menu).

The existing alternatives currently are:
1) Switch to Unicode mode (this is default since 3.6.0, unless you imported an older project), and provide unicode fonts that contain multiple languages. Then these fonts could be used for all or most of the translations.
2) Provide a font file replacement by manually placing it in the game dir along with translation. This will of course "lock out" other translations, and require another manual replacement to play with another language. This method is commonly used with "unofficial" translations.

SMF spam blocked by CleanTalk