Page 1 of 1

How to measure the width of a fonts character in Noesis1.3

Posted: 28 Jan 2017, 10:57
by zhangyi
Hi everyone:
I want to measure the width of TextBlock with specifying font.
By the way, i am using noesis 1.3 beta4 in windows(native c++) and ios platform.

And i have found the topic viewtopic.php?f=3&t=295&p=1460&hilit=Font#p1460.
However, it does not work now.
Noesis::Drawing::IVGLFontSystem* fontSystem =
    NsGetSystem<Noesis::Drawing::IVGLFontSystem>().GetPtr();

Ptr<Noesis::Drawing::IVGLFont> font = fontSystem->CreateFont(
    fontFamilyName, fontWeight, fontStyle, fontSize, strokeThickness);
I can't find IVGLFontSystem and IVGLFontSystem in 1.3beta4.

Is there any idea or any alternative for this feature using 1.3beta4.
Thanks!

Re: How to measure the width of a fonts character in Noesis1

Posted: 01 Feb 2017, 11:03
by sfernandez
You can get the size of any UI element of the tree that has been measured through its ActualWidth and ActualHeight properties.

And you can update the measurement any time by calling UpdateLayout() on the element.

Would this be enough in your case?

Re: How to measure the width of a fonts character in Noesis1

Posted: 05 Feb 2017, 08:17
by zhangyi
Thanks for your reply!

ActualWidth is always same to Width for TextBlock in my case.

Actually, I want to measure the length of TextBlock according to uncertain text, to fit the content of text tightly.
NsString text = "abcde"; // it is uncertain;
TextBlockPtr block = *new TextBlock();
block->SetText(text);

NsFloat32 blockwidth = ?;
block->SetWidth(blockwidth); // textblock is just right to fit its content

Re: How to measure the width of a fonts character in Noesis1

Posted: 06 Feb 2017, 13:49
by sfernandez
You can measure the TextBlock manually:
textBlock->Measure(Noesis::Size::Infinite()); 
And get its desired size:
Noesis::Size desiredSize = textBlock->GetDesiredSize(); 
This will give you the minimum size required by the TextBlock to fit its text, according to all its font and text properties: FontFamily, FontSize, FontWeight..., TextWrapping, TextAlignment...