Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Lotti on July 01, 2014, 07:50:48 AM

Title: ngui label: fallback to "default font" if character is not available.
Post by: Lotti on July 01, 2014, 07:50:48 AM
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.
Title: Re: ngui label: fallback to "default font" if character is not available.
Post by: ArenMook on July 02, 2014, 03:37:41 AM
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.
Title: Re: ngui label: fallback to "default font" if character is not available.
Post by: Lotti on July 02, 2014, 03:41:49 AM
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.
Title: Re: ngui label: fallback to "default font" if character is not available.
Post by: Lotti on July 02, 2014, 06:04:05 AM
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.  
Title: Re: ngui label: fallback to "default font" if character is not available.
Post by: Lotti on July 02, 2014, 08:11:32 AM
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.  
Title: Re: ngui label: fallback to "default font" if character is not available.
Post by: ArenMook on July 03, 2014, 03:51:40 AM
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.
Title: Re: ngui label: fallback to "default font" if character is not available.
Post by: Lotti on July 03, 2014, 06:48:03 AM
how to create a reference font? i don't find this option inside font maker
Title: Re: ngui label: fallback to "default font" if character is not available.
Post by: ArenMook on July 04, 2014, 12:53:15 PM
Create a game object, attach UIFont to it, save it as a prefab.