D2TextSize command

Requires: Direct2D.lg32

Purpose

Obtains the size of a specified string or a D2TextLayout object.

Syntax

D2TextSize txt$, width!, height!
D2TextSize D2Layout, width!, height!

txt$: string expression
D2Layout: Object expression
width!, height!: float variables

Description

The first variant returns the text size based on the font set with D2SetFont in the variables width! and height! in device-independent pixels. When D2TextSize is passed a D2Layout object it will return the size of the text layout object. A text layout object is created with the D2Layout() function.

Example

'

' D2TextSize

'

$Library "direct2d"

OpenW 1, 0, 0, 300, 300, 48

Global Object RT1

Set RT1 = D2GetRT()

' Multiple line text

Global Txt1$ = "Hello DirectX" #10 "This is GB" #10 "(GFABASIC 32)"

Global w!, h!

D2TextSize Txt1$, w!, h!

Do

Sleep

Until Me Is Nothing

 

Sub Win_1_Paint

D2BeginDraw RT1, D2C_WhiteSmoke

D2Text 0, 0, Txt1$

D2Text 0, h!, "Text dimension:" + Str(w!) + " x" + Str(h!)

D2EndDraw

EndSub

See Also

D2SetFont, D2Text, D2Layout

{Created by Sjouke Hamstra; Last updated: 21/02/2021 by James Gaite; Other Contributors: Jean-Marie Melanson}