Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - zh4ox

Pages: [1]
1
NGUI 3 Support / Re: Dynamic font support for NGUI
« on: January 10, 2013, 10:18:21 PM »
Ok I *think* I might have something that makes more sense.
No more magic number, it relies on the font import size (which unfortunately can't be accessed from code, it seems, so I set the value to a constant 16, since when you import a font, its size is set to 16.
zh4ox, can you test this and tell me what you think?
it still works not perfectily, I use YouYuan font, size 16 and test UILabel with char size 16, 64. Here is the result.


All the text is above the baseline, btw, 0.8203215f is not real magic number, it' seems the baseline of font size 1, and I have modified ur code, as u wish, now there r no limitation on font asset's size. Here is my result


U can test the modification on your machine

2
NGUI 3 Support / Re: Dynamic font support for NGUI
« on: January 10, 2013, 04:18:00 AM »
yeah there's this weird thing with vertical offsets. Frankly I haven't bothered too much about it since I was testing with smaller fonts like 12 to 18px, but I agree that this is problematic.
I'll try to have another look at this issue too. It seems we don't fully understand the values that the CharacterInfo class gives us for positioning fonts. In fact it might make sens to try to figure that out even outside of the NGUI context
I've searched the Unity's forum, no answer to it, After many times experiment, I found that when set the font asset's size to ONE, a magic solution come out.
  1.                                         float m = 0.8203215f;
  2.                                         float n = 1.0f - m;
  3.                                         float offsetY = (int)(m * dynamicFontSize) + n;
  4.  
  5.                                         v0.x = scale.x * (charInfo.vert.x + x);
  6.                                         v0.y = scale.y * (y + charInfo.vert.y - offsetY);
  7.  
  8.                                         v1.x = v0.x + scale.x * charInfo.vert.width;
  9.                                         v1.y = v0.y + scale.y * charInfo.vert.height;
  10.  
  11.                                         u0.x = charInfo.uv.xMin;
  12.                                         u0.y = charInfo.uv.yMax;
  13.  
  14.                                         u1.x = charInfo.uv.xMax;
  15.                                         u1.y = charInfo.uv.yMin;
  16.  
  17.                                         x += mSpacingX + (int)charInfo.width;
  18.  
  19.                                         for (int b = 0; b < 4; ++b)
  20.                                                 cols.Add(color);
  21.  
  22.                                         verts.Add(new Vector3(v1.x, v0.y));
  23.                                         verts.Add(new Vector3(v1.x, v1.y));
  24.                                         verts.Add(new Vector3(v0.x, v1.y));
  25.                                         verts.Add(new Vector3(v0.x, v0.y));
  26.  
  27.                                         if (charInfo.flipped)
  28.                                         {
  29.                                                 uvs.Add(new Vector2(u1.x, u0.y));
  30.                                                 uvs.Add(new Vector2(u0.x, u0.y));
  31.                                                 uvs.Add(new Vector2(u0.x, u1.y));
  32.                                                 uvs.Add(new Vector2(u1.x, u1.y));
  33.                                         }
  34.                                         else
  35.                                         {
  36.                                                 uvs.Add(new Vector2(u1.x, u0.y));
  37.                                                 uvs.Add(new Vector2(u1.x, u1.y));
  38.                                                 uvs.Add(new Vector2(u0.x, u1.y));
  39.                                                 uvs.Add(new Vector2(u0.x, u0.y));
  40.                                         }
set the font asset's size to 1, and add the offset to vert.y calculation, then it fits all font sizes, here is my program's result

3
NGUI 3 Support / Re: Dynamic font support for NGUI
« on: January 10, 2013, 03:48:04 AM »
Quote
@Unisip
I've ever try not change the size setting in the font asset, but failed. May I know how u calculate the v0.y to make all text inside the box?  e.g. the font asset's name is YouYuan, with size 16, the characterInfo.vert.y of 国 with size 16 is correct, it's -0.125f, so just set v0.y=(y - 0.125f)*scale.y is OK, but the characterInfo.vert.y of 国 with size 64 is 35.88f, and then what's the correct v0.y?
Nice job, man. I've read your code and test it. But the problem what I have mentioned seems not solved. Here is ur program's result -- all the text is above the top corner.



4
NGUI 3 Support / Re: Dynamic font support for NGUI
« on: January 09, 2013, 10:02:09 PM »
@sk8er123
Please take patience, when the work is done, I'll upload the code.
@jarjin
Yes, all size font in single texture, because I want the draw call as few as possible
@Unisip
I've ever try not change the size setting in the font asset, but failed. May I know how u calculate the v0.y to make all text inside the box?  e.g. the font asset's name is YouYuan, with size 16, the characterInfo.vert.y of 国 with size 16 is correct, it's -0.125f, so just set v0.y=(y - 0.125f)*scale.y is OK, but the characterInfo.vert.y of 国 with size 64 is 35.88f, and then what's the correct v0.y?

5
NGUI 3 Support / Re: Dynamic font support for NGUI
« on: January 09, 2013, 06:15:41 AM »
the work slows down because of multiple font sizes in one font texture --- it's very hard to place the text correctly,  but finally it solved, though I don't think myself's solution is perfect :( (u must first set the TTF's font size to ONE), btw, anyone have a better way to solve the problem?
Here is the pic, all text with different sizes (16, 24, 30, 36, 100) are got from the same one dynamic font texture, and their offsetX, offsetY is approximatively correct, all inside the box.



6
NGUI 3 Support / Re: Dynamic font support for NGUI
« on: January 08, 2013, 09:49:05 PM »
Unisip, u are awesome, I stiil have much work to do

7
NGUI 3 Support / Re: Dynamic font support for NGUI
« on: January 08, 2013, 09:40:14 AM »
So... all the dynamic font solutions (this is what, 3rd one in 2 days now? :)) are limited by the same clause -- that is the font must be in a separate texture and can't be using the atlas texture, right?
yep, it uses the dynamic font texture, the amount of texture is decided by how many fonts we use

Pages: [1]