Author Topic: ngui label: fallback to "default font" if character is not available.  (Read 5718 times)

Lotti

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 47
    • View Profile
Hello Aaren!
I noticed that there is some sort of fallback on uilabel's font. Let me explain with an example.

If I use a font that has only the ascii charset on a uilabel that contains utf-8 character (chinese), the uilabel will show chinese text with a font that is different from mine ("fallback font"). Can you confirm this?

Plus, there is a way to force the fallback font with some method/hack? we need this to bypass our custom font only for certain languages. Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Assuming you are talking about dynamic fonts here, this is all Unity. NGUI merely requests characters from Unity. I'm not sure what happens inside and what "fallback" functionality is provided.

Lotti

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 47
    • View Profile
yes, it's dynamic font. thank you for your reply, i will investigate.

substantially, it prints characters in ARIAL instead of our setted font, when the character is not available.

Lotti

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 47
    • View Profile
Ok! i think i'm done.

Could you check if this is the "best place" to overwrite the setted font (on editor) on each UILabel? Thank you.

  1.        
  2. public Font trueTypeFont
  3.         {
  4.                 get
  5.                 {
  6.                         if (mTrueTypeFont != null) return mTrueTypeFont;
  7.                         return (mFont != null ? mFont.dynamicFont : null);
  8.                 }
  9.                 set
  10.                 {
  11.                         if (mTrueTypeFont != value)
  12.                         {
  13. #if DYNAMIC_FONT
  14.                                 //FIX per cambiare font per le lingue non supportate - VALERIO
  15.                                 #if !UNITY_EDITOR
  16.                                 if (Translate.defaultFontLanguages.Contains(Localization.language)) {
  17.                                         value = Translate.defaultFont;
  18.                                 }
  19.                                 #endif
  20. ........
  21.  

Lotti

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 47
    • View Profile
the previous snipper will not work on devices..

this one works.
UILabel.cs
  1.         public Font trueTypeFont
  2.         {
  3.                 get
  4.                 {
  5.                         //FIX set an alternative font for each languages that require it - Lotti
  6.                         #if !UNITY_EDITOR
  7.                         if (Translate.alternativeFontLanguages.Contains(Localization.language)
  8.                         && mTrueTypeFont != Translate.alternativeFont) {
  9.                                 trueTypeFont = Translate.alternativeFont;
  10.                         }
  11.                         #endif
  12.                         //ENDFIX
  13.  
  14.                         if (mTrueTypeFont != null) return mTrueTypeFont;
  15.                         return (mFont != null ? mFont.dynamicFont : null);
  16.                 }
  17.                 set
  18.                 {
  19.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I wouldn't do it like this. NGUI's fonts can be set up as "reference fonts", where your labels use a dummy font that points to a real one. Then when you switch languages you can also switch the font your reference font is pointing to.

Lotti

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 47
    • View Profile
how to create a reference font? i don't find this option inside font maker

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Create a game object, attach UIFont to it, save it as a prefab.