Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline vrenken  
#1 Posted : Thursday, January 9, 2014 10:42:19 PM(UTC)
vrenken

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

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline elasto  
#2 Posted : Friday, January 10, 2014 12:29:51 PM(UTC)
elasto

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.

thanks 1 user thanked elasto for this useful post.
vrenken on 1/10/2014(UTC)
Offline Michael Koch  
#3 Posted : Friday, January 10, 2014 5:06:51 PM(UTC)
Michael Koch

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... Cool
Offline Michael Koch  
#4 Posted : Friday, January 10, 2014 5:33:35 PM(UTC)
Michael Koch

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);
        }
thanks 1 user thanked Michael Koch for this useful post.
vrenken on 1/10/2014(UTC)
Offline elasto  
#5 Posted : Friday, January 10, 2014 5:45:39 PM(UTC)
elasto

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

Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
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.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.057 seconds.