Download

FCanvasTextItem with Text Wrapping?

Hello,

Does anyone know how to use text wrapping with FCanvasTextItem ? I want to draw dialogue text via canvas, however I didn’t notice any text wrapping related fields for FCanvasItem.
I’m aware that UMG’s TextBlock has this Auto Text Wrap capability, but I want to try using canvas if possible.

Thanks for you attention.

Regards,

Anton

Just want to update, in the end I managed to split a string into lines by using UCanvas’s WrapString static function.



UFont* font = LoadAssetFromPath<UFont>(TEXT("Font'/Engine/EngineFonts/Roboto.Roboto'"));  //based on Rama's function https://wiki.unrealengine.com/Dynamic_Load_Object
FCanvasWordWrapper wrapper;
FTextSizingParameters params;
TArray<FWrappedStringElement> lines;
params.DrawFont = font;
params.DrawX = dlgStartX;
params.DrawXL = dlgWidth - totalPaddingX;
params.DrawY = dlgStartY;
params.DrawYL = dlgHeight -totalPaddingY;
params.Scaling = FVector2D(fontScaling, fontScaling);
UCanvas::WrapString(wrapper, params, 0, *myString, lines);


As for calculating string height, I use UFont’s GetStringHeightSize.