- Andreas Schooll
- Posts: 25
- Joined:
Measuring the width of a fonts character
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
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
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: Measuring the width of a fonts character
Hi,
Information about text width can be obtained through the IVGLFont interface.
First of all you have to load the font using the IVGLFontSystem:
Then you can get the bounding box of a text:
Or get the exact position of each character in the text:
Information about text width can be obtained through the IVGLFont interface.
First of all you have to load the font using the IVGLFontSystem:
Code: Select all
Noesis::Drawing::IVGLFontSystem* fontSystem =
NsGetSystem<Noesis::Drawing::IVGLFontSystem>().GetPtr();
Ptr<Noesis::Drawing::IVGLFont> font = fontSystem->CreateFont(
fontFamilyName, fontWeight, fontStyle, fontSize, strokeThickness);
Code: Select all
Noesis::Drawing::Size size = font->GetBounds(text, alignment, maxWidth, 0);
Code: Select all
NsVector<Noesis::Drawing::Point> glyphPositions;
font->GetGlyphPositions(text, alignment, maxWidth, 0, glyphPositions);
- Andreas Schooll
- Posts: 25
- Joined:
Re: Measuring the width of a fonts character
I forget to mention that we are using Noesis for Unity. Are those interfaces available in Unity?
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: Measuring the width of a fonts character
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.
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
- Posts: 25
- Joined:
Re: Measuring the width of a fonts character
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
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
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: Measuring the width of a fonts character
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.
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.
Re: Measuring the width of a fonts character
Implemented in v1.1.5
Who is online
Users browsing this forum: Ahrefs [Bot] and 0 guests