Author Topic: dynamic font not centered  (Read 4298 times)

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
dynamic font not centered
« 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)


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: dynamic font not centered
« Reply #1 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.

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
Re: dynamic font not centered
« Reply #2 on: December 30, 2013, 05:50:16 AM »
hope it's ok to attach here

beermoney

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 80
    • View Profile
Re: dynamic font not centered
« Reply #3 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!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: dynamic font not centered
« Reply #4 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.                         }
« Last Edit: March 10, 2014, 08:05:30 PM by ArenMook »