Requires: Direct2D.lg32
Creates a text layout object for a given string and dimension.
Set Obj = D2Layout(txt$, width!, height!)
Obj | : variable of type Object |
txt$ | : string expression |
width!, height! | : float expression |
A text layout object represents a block of text after it has been formatted and analyzed. The string txt$ is formatted according to the current font set with D2SetFont. Several attributes of the text layout object can be changed using D2DefLayout. After all properties for the text are applied it can be drawn using the D2TextLayout command.
The Obj variable stores the returned text layout COM object (IDWriteTextLayout). The width and height arguments determine the initial layout rectangle used to format the text, although the height value isn't used. D2TextSize can be used to obtain the final dimension of the rectangle after all settings are applied (using D2DefLayout). The maximum width will be obsereved, but the height will vary.
'
' D2Layout
'
$Library "direct2d"
OpenW 1, 0, 0, 300, 300, 48
Global Object RT1
Global Float RTWidth, RTHeight
Set RT1 = D2GetRT()
D2GetSizeRT RT1, RTWidth, RTHeight
' Build a Text Layout object for a given text
Global Txt1$ = "Hello DirectX" #10 "This is GB" #10 "(GFABASIC 32)"
Global TL As Object
Set TL = D2Layout(Txt1$, RTWidth, RTHeight)
' Layout object is formatted using RTWidth,
' the height argument is not used.
' Get the result width and height
Global w!, h!
D2TextSize TL, w!, h!
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2BeginDraw RT1, D2C_WhiteSmoke
D2TextLayout 0, 0, TL
D2Text 0, h!, "Text dimension:" + Str(w!) + " x" + Str(h!)
D2EndDraw
EndSub
D2Layout creates an IDWriteTextLayout object by calling IDWriteFactory::CreateTextLayout based on the current IDWriteTextFormat object, which must have been created using the D2SetFont command. These COM objects are not related to the render target, so D2SetRT isn’t required before operating on these objects.
{Created by Sjouke Hamstra; Last updated: 23/02/2021 by James Gaite; Other Contributors: Jean-Marie Melanson}