Text translation

Started by SileNTViP, Sat 29/12/2012 15:56:11

Previous topic - Next topic

SileNTViP

Please remove limit 128 chars from wfn fonts and make 256 for full ASCII support (2 languages)

acfonts.cpp
Spoiler
class WFNFontRenderer : public IAGSFontRenderer {
public:
  ...
  virtual bool SupportsExtendedCharacters(int fontNumber) { return false; } // Make TRUE
  ...
};

void WFNFontRenderer::EnsureTextValidForFont(char *text, int fontNumber)
{
    // Clear
}

int WFNFontRenderer::GetTextWidth(const char *texx, int fontNumber)
{
    ...
    if (((unsigned char)thisCharacter > 127) && (sizeof(tabaddr) <= 128)) thisCharacter = '?'; // Remove
    ...
}

int WFNFontRenderer::GetTextHeight(const char *texx, int fontNumber)
{
    ...
    if (((unsigned char)thisCharacter > 127) && (sizeof(tabaddr) <= 128)) thisCharacter = '?'; // Remove
    ...
}

int WFNFontRenderer::printchar(int xxx, int yyy, wgtfont foo, int charr)
{
  ...
  if (((unsigned char)charr > 127) && (sizeof(tabaddr) <= 128)) // Remove this strings
    charr = '?';
  ...
}

[close]

and add translation GUI::ListBox in acgui.c
Spoiler

void GUIListBox::Draw()
{
   ...
#ifdef THIS_IS_THE_ENGINE
    // Allow it to change the string to unicode if it's TTF
    char oritext[200];
    strcpy(oritext, get_translation(items[a + topItem]));
    ensure_text_valid_for_font(oritext, font);
#else
    char *oritext = items[a + topItem];
#endif

    if (alignment == GALIGN_LEFT)
      wouttext_outline(x + 1 + pixel_size, thisyp + 1, font, oritext);
    else {
      int textWidth = wgettextwidth(oritext, font);

      if (alignment == GALIGN_RIGHT)
        wouttext_outline(rightHandEdge - textWidth, thisyp + 1, font, oritext);
      else
        wouttext_outline(((rightHandEdge - x) / 2) + x - (textWidth / 2), thisyp + 1, font, oritext);
    }
  ...
[close]

Crimson Wizard

#1
The 256 support for WFN fonts was made by Alan v Drake, and I hope his changes will be used in official engine.
Thanks for tip about ListBox.

Also, if you have any real code improvements, like those you posted, consider use github.com service. There's a community repository there: https://github.com/adventuregamestudio. You may make a personal copy, do your changes and make a merge request. This way it will be both faster and convenient.

Crimson Wizard

The list box translation fix is making itself into second 3.3.0 beta or RC sub-version (adding this to our repo right away).
The 256-character WFN will be included into 3.3.1, I think.

Crimson Wizard

I was probably too quick with this fix. Now when I think about this, this translation might have been rejected on purpose; even if it wasn't, there might be cases when list box items should not be translated, e.g. when list box is populated with saved game filenames.

What if I add a new boolean property for ListBox, which would enable/disable translation for this control?
If it is a good idea, may such property be useful for other controls with text such as Label and Button?

Ghost

For main menu buttons alone it would be useful I think- right now you have to use graphics of your text if you want translations (by changing graphics depending on GetTranslation). If it isn't too much trouble, yes, please add this.

Crimson Wizard

Quote from: Ghost on Tue 23/04/2013 11:36:11
For main menu buttons alone it would be useful I think- right now you have to use graphics of your text if you want translations (by changing graphics depending on GetTranslation). If it isn't too much trouble, yes, please add this.
I think there's some misunderstanding. Button text should translate properly in 3.2.1 (don't know about lower versions).
I was speaking about letting to disable translations for certain gui controls.

Ghost

Yes, my bad. I confused something there.  :-\

Crimson Wizard

Ok, I added the Translated property to ListBox only for now for backward compatiblity (defaults to false for imported older projects). It may be easily added to buttons and labels if needed later.

SMF spam blocked by CleanTalk