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

Text (rtl) are not show on ios (safary and chrome) - #6121

Closed
liorGameDev opened this issue May 25, 2022 · 5 comments
Closed

Text (rtl) are not show on ios (safary and chrome) - #6121

liorGameDev opened this issue May 25, 2022 · 5 comments

Comments

@liorGameDev
Copy link

liorGameDev commented May 25, 2022

Version

  • Phaser Version: 3.24.1
  • Operating system: ios
  • Browser: chrome / safari

Description

When runing my game on ios devices, the text (rtl) is not shown.
On desktop and on Android it works fine. On ios it doesn't work on chrome nor safari.

Example Test Code

import { GameObjectExtender, TextObjectExtender, TextUtil } from ".";
import { textStyles } from '../GameConfig';

export default class ExtraText extends Phaser.GameObjects.Text {
  constructor(scene, x, y, text, config, noTranslateText) {
    config = config || textStyles.getStyle();
    if (!config.metrics) {
      config.metrics = TextUtil.getMetricsFromFont(config.fontFamily, parseInt(config.fontSize));
    }

    super(scene, x, y, text, config);

    if (!config.metrics) {
      TextUtil.addFontMatrix(config.fontFamily, parseInt(config.fontSize), this.getTextMetrics());
    }

    this.initRTL();
    
    if (noTranslateText) {
        this.setText(this.text, noTranslateText);
    }
    scene.add.existing(this);

    GameObjectExtender(this);
    TextObjectExtender(this, config.align);
  }

  setText(text, noTranslateText) {
    if (!isNaN(text)) {
      super.setText(text);
      return;
    }
    let translated = TextUtil.translate(text);
    if (noTranslateText) {
        translated += noTranslateText;
        text += noTranslateText;
    }
    super.setText((translated || text));
  }

  destroy() {
    super.destroy();
  }
}

Additional Information

@javurtez
Copy link

Had the same problem. Don't use the text style to initiate the RTL, instead use its function, which is text.initRTL().

@liorGameDev
Copy link
Author

@javurtez Thank you very much for the response.
I added the code to the issue + using the text.initRTL() as you suggested. It seems not to work.
Do you have any idea why? did it work for you?

@javurtez
Copy link

@javurtez Thank you very much for the response. I added the code to the issue + using the text.initRTL() as you suggested. It seems not to work. Do you have any idea why? did it work for you?

Did you also use the text style to initiate the font family and font size? If that's the case, then you should also 'setFontFamily' and 'setFontSize'.

@javurtez
Copy link

javurtez commented Nov 8, 2022

Okay, after rechecking the problem again in iOS15, I think the workaround for this is after setting the textObject.text/textObject.setText to a new text string, or even adjust the fontSize, you need to call 'initRTL' and then 'setWordWrapWidth'.

Also, font size should also be not large.

let textObj = scene.add.text(0, 0, 'این یک آزمایش است.', { 
   fontFamily: font, 
   fontSize: size, 
   color: color, 
   rtl: true
});

// without calling the functions below, rtl doesn't show
textObj.initRTL();
textObj.setWordWrapWidth(600);

or

let textObj = scene.add.text(0, 0, '', { 
   fontFamily: font, 
   fontSize: size, 
   color: color, 
   rtl: true
});

textObj.setText('این یک آزمایش است.');
// textObj.text = 'این یک آزمایش است.';

// without calling the functions below, rtl doesn't show
textObj.initRTL();
textObj.setWordWrapWidth(600);

or

let textObj = scene.add.text(0, 0, 'این یک آزمایش است.', { 
   fontFamily: font, 
   color: color, 
   rtl: true
});

textObj.initRTL();
textObj.setWordWrapWidth(600);


// any adjustments of the text will make the text get hidden again unless call the initRTL and setWordWrapWidth
textObj.setFontSize(size);

// without calling the functions below, rtl doesn't show
textObj.initRTL();
textObj.setWordWrapWidth(600);

@photonstorm @liorGameDev

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

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

No branches or pull requests

3 participants