Is there any demo about how to use the class FormattedText?
Posted: 28 Oct 2021, 03:36
I wanna to use DrawingContext to drawtext. I tried to get formattedtext from a textblock.But it did not work.
Welcome to our official discussion site. You’ll find topics on features, bugs, development, and general support here
https://www.noesisengine.com/forums/
void OnRender(DrawingContext* context)
{
mFormattedText->BuildTextRuns(mText.Str(), nullptr, mFont, FontWeight_Normal, FontStretch_Normal, FontStyle_Normal,
12.0f, 0.0f, nullptr, mForegroundBrush, nullptr, TextDecorations_None, 1);
mFormattedText->Layout(TextAlignment_Left, TextWrapping_Wrap, TextTrimming_None, mRenderSize.width, mRenderSize.height,
0.0f, LineStackingStrategy_MaxHeight);
context->DrawText(mFormattedText, Rect(mRenderSize));
}
Thanks!Hi, to draw a text using a FormattedText first provide the text or inlines that will generate the text runs, and then call the layout method to place the text according to the provided bounds and font properties.Code: Select allvoid OnRender(DrawingContext* context) { mFormattedText->BuildTextRuns(mText.Str(), nullptr, mFont, FontWeight_Normal, FontStretch_Normal, FontStyle_Normal, 12.0f, 0.0f, nullptr, mForegroundBrush, nullptr, TextDecorations_None, 1); mFormattedText->Layout(TextAlignment_Left, TextWrapping_Wrap, TextTrimming_None, mRenderSize.width, mRenderSize.height, 0.0f, LineStackingStrategy_MaxHeight); context->DrawText(mFormattedText, Rect(mRenderSize)); }