Delta Engine
»
Support
»
Rendering
»
Font Size / scaling
Joined: 12/31/2013(UTC) Posts: 11 Location: Enschede
Thanks: 2 times
|
Hi,
is it possible to draw Fonts at a different size without using different contents? I want to create some kind of buttons that scales when the user hovers over them.
At the moment i'm fiddling around with FontText entities and alter the Size property, but somehow the Size and DrawArea of this entity type seem to be quite empty.
On a sidenote: is there some kind of MeasureString option? I've found the TextConverter, TextParser and TextWrapper, but none of these allows me to measure a piece of text.
Did i overlook something?
Thanks in advance,
Peter Vrenken
|
|
|
|
Joined: 8/23/2011(UTC) Posts: 245
Thanks: 6 times Was thanked: 12 time(s) in 11 post(s)
|
No, there's currently no simple way to instruct the characters of a font to render at a different size from how they are in the png.
The DrawArea/Position/Size of FontText only indirectly controls how the text gets drawn: For example, if the text is center-aligned then it will center the text in the center of the DrawArea - and so on for left or right aligned.
---
There is also no direct MeasureString function; You could construct your own though:
The key is to get the array of GlyphDrawData from the FontText - ie. fontText.Get<GlyphDrawData[]>();
Loop through all glyphs and get each one's DrawArea. Then find the minimum DrawArea.Left and Top, and the maximum Right and Bottom, and then subtraction of minimum from maximum to give you the text's width and height. Note that this will be a value in pixels not quadratic.
(Also, don't rely on the absolute values of the DrawArea - this is all relative data not absolute - but hence subtracting will be fine)
---
Sorry, not the answer you were looking for, and someone else may post saying we can improve this further, but I hope this helps clarify.
|
 1 user thanked elasto for this useful post.
|
|
|
Joined: 12/27/2013(UTC) Posts: 41 Location: Regensburg
Thanks: 3 times Was thanked: 1 time(s) in 1 post(s)
|
Hahaha, I was just logging in to ask exactly the same thing about text/string size measurement. Now, let see what this GlyphDrawData thing is about...
|
|
|
|
Joined: 12/27/2013(UTC) Posts: 41 Location: Regensburg
Thanks: 3 times Was thanked: 1 time(s) in 1 post(s)
|
Doing it like so now. The result seems valid. Code:// --------------------------------------------------------------------------------------
public float GetTextPixelSizeX(FontText fT)
// --------------------------------------------------------------------------------------
{
GlyphDrawData[] grd = fT.Get<GlyphDrawData[]>();
int iLength = grd.GetLength(0);
if (iLength == 0) return 0.0f;
float fPixelPosMin = float.MaxValue;
float fPixelPosMax = 0;
for (int i=0;i<iLength;i++)
{
if (grd[i].DrawArea.Left < fPixelPosMin) fPixelPosMin = grd[i].DrawArea.Left;
if (grd[i].DrawArea.Right > fPixelPosMax) fPixelPosMax = grd[i].DrawArea.Right;
}
return (fPixelPosMax - fPixelPosMin);
}
|
 1 user thanked Michael Koch for this useful post.
|
|
|
Joined: 8/23/2011(UTC) Posts: 245
Thanks: 6 times Was thanked: 12 time(s) in 11 post(s)
|
Looks good - although for safety I would initialize fPixelPosMax to float.MinValue instead since it *might* be possible for all values to be negative. (Might have to be something weird like the FontText having a negative width DrawArea though...) --- Good job though, and glad to hear the results look sensible to you. - Phil Edited by user Friday, January 10, 2014 5:46:11 PM(UTC)
| Reason: Not specified
|
|
|
|
Delta Engine
»
Support
»
Rendering
»
Font Size / scaling
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.