Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Measuring the width of a fonts character

05 Feb 2014, 10:50

Hey,

we need to write a custom word wrapping function for chinese text in textblocks. In order to do correct measurement of the amount of characters fitting into one textblock line it would be necessary to know the width of a fonts character.

I googled if there is a way to accomplish this in WPF and most posts where referencing FormattedText as a class that can be used for such purposes. Noesis has a interface to FormattedText but it seems that it does not expose the width and height properties.

Is there any way to accomplish character measuring with Noesis Guiß

best regards,
Andreas
 
User avatar
sfernandez
Site Admin
Posts: 3152
Joined: 22 Dec 2011, 19:20

Re: Measuring the width of a fonts character

05 Feb 2014, 22:36

Hi,

Information about text width can be obtained through the IVGLFont interface.

First of all you have to load the font using the IVGLFontSystem:
Noesis::Drawing::IVGLFontSystem* fontSystem =
    NsGetSystem<Noesis::Drawing::IVGLFontSystem>().GetPtr();

Ptr<Noesis::Drawing::IVGLFont> font = fontSystem->CreateFont(
    fontFamilyName, fontWeight, fontStyle, fontSize, strokeThickness);
Then you can get the bounding box of a text:
Noesis::Drawing::Size size = font->GetBounds(text, alignment, maxWidth, 0);
Or get the exact position of each character in the text:
NsVector<Noesis::Drawing::Point> glyphPositions;
font->GetGlyphPositions(text, alignment, maxWidth, 0, glyphPositions);
;)
 
Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Re: Measuring the width of a fonts character

06 Feb 2014, 14:09

I forget to mention that we are using Noesis for Unity. Are those interfaces available in Unity?
 
User avatar
sfernandez
Site Admin
Posts: 3152
Joined: 22 Dec 2011, 19:20

Re: Measuring the width of a fonts character

07 Feb 2014, 11:34

Unfortunately we don't have these interfaces exposed to Unity :(

What exactly do you need to know? Line width? or individual character width?
Because the FormattedText API in WPF only provides info about whole lines, not individual characters, and my guess is you will need individual character widths to perform any word wrap by yourself.

Let me know so we can comment what is the best approach to provide you the correct info.
 
Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Re: Measuring the width of a fonts character

07 Feb 2014, 12:44

Hey,

thanks for your resonse.

The best thing would be to know individual character width. So i can add character by character until i reach the end of the line.

best regards,
Andreas
 
User avatar
sfernandez
Site Admin
Posts: 3152
Joined: 22 Dec 2011, 19:20

Re: Measuring the width of a fonts character

07 Feb 2014, 17:28

Ok.

This API is not yet available in Unity. We will take a look at WPF's GlyphTypeFace class that provides exactly what you want through its AdvanceWidths property, and figure out how to expose it in Unity.

It will be available as soon as possible.
 
Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Re: Measuring the width of a fonts character

10 Feb 2014, 12:23

Thank you.
 
User avatar
jsantos
Site Admin
Posts: 4123
Joined: 20 Jan 2012, 17:18
Contact:

Re: Measuring the width of a fonts character

28 Feb 2014, 14:58

Implemented in v1.1.5

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests