zhangyi
Topic Author
Posts: 9
Joined: 09 Jul 2016, 09:31

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

28 Jan 2017, 10:57

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!
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

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

01 Feb 2017, 11:03

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?
 
zhangyi
Topic Author
Posts: 9
Joined: 09 Jul 2016, 09:31

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

05 Feb 2017, 08:17

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
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

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

06 Feb 2017, 13:49

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...

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests