Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: beermoney on December 28, 2013, 06:59:40 AM

Title: dynamic font not centered
Post by: beermoney on December 28, 2013, 06:59:40 AM
creating a button with a dynamic font centered in the middle, the text appears un-centered

repro:
drag NGUI button prefab into scene
change font to dynamic and then to using "oliver's barney" font from the free square pack font pack (https://www.assetstore.unity3d.com/#/content/4235)
change the font size to 50 to exaggerate the displacement

this is using NGUI 3.0.8, (previous versions 3.0.7 f3, worked fine with this font)

Title: Re: dynamic font not centered
Post by: ArenMook on December 28, 2013, 04:44:05 PM
Unity doesn't provide any clear way of properly retrieving the baseline for the character, so all ways of doing so manually are, pretty much -- hacks. Can you send me the font itself to support at tasharen.com? I'll have a look.
Title: Re: dynamic font not centered
Post by: beermoney on December 30, 2013, 05:50:16 AM
hope it's ok to attach here
Title: Re: dynamic font not centered
Post by: beermoney on March 10, 2014, 01:55:31 PM
Hey Aren,

I'm seeing this issue again with NGUI 3.5.3 and Bitmap/NGUI  fonts!
Title: Re: dynamic font not centered
Post by: ArenMook on March 10, 2014, 07:49:37 PM
In case of the font you posted the issue occurs because of the vast difference between how characters "_" and "`" are positioned in the font. Try drawing them. The "`" in particular is way higher than it should be. The creator of the font didn't respect the bounds at all.

P.S. I've modified the freetype parsing logic to calculate the offset a little differently in 3.5.4 though:
  1.                         int baseline = size + min;
  2.                         baseline += ((max - min - size) >> 1);
  3.  
  4.                         // Offset all glyphs so that they are not using the baseline
  5.                         for (int i = 0; i < entries.size; ++i)
  6.                         {
  7.                                 BMGlyph glyph = font.GetGlyph(entries[i], true);
  8.                                 glyph.offsetY += baseline;
  9.                         }