Requires: Direct2D.lg32
Reads and returns the text layout properties for a text character.
Value = D2RLayout(D2Layout, prop [, charpos])
D2Layout | : Object variable referencing a text layout object |
prop, charpos | : integer |
D2RLayout returns a property value for a character specified by charpos. D2RLayout calls the IDWriteTextLayout get-property methods. Not all get-properties require a charpos, in these cases charpos can be omitted.
The prop argument can take the following values:
D2TL_FONTNAME | Returns the font name for the char. |
D2TL_WEIGHT | Returns the weight of the font for the char. The return value is a DWRITE_FONT_WEIGHT constant. See D2DefLayout for more details |
D2TL_STYLE | Returns the style of the font for the char. The return value is a DWRITE_FONT_STYLE constant. See D2DefLayout for more details. |
D2TL_FONTSIZE | Returns the font size (float) of the font for a char. |
D2TL_STRETCH | Returns the font stretch for the char. The return value is a DWRITE_FONT_STRETCH constant. See D2DefLayout for more details. |
D2TL_UNDERLINE | Returns a boolean indicating underlining (True/False) for a char. |
D2TL_STRIKETHRU | Returns a boolean indicating strikethrough (True/False) for a char. |
D2TL_LOCALENAME | Returns the locale name for a char. |
D2TL_INLINE | Returns an Object with a reference to an IDWriteInlineObject object. Use Set to store the return value in a variable of type Object. Not supported. |
D2TL_TYPOGRAPHY | Returns an Object with a reference to an IDWriteTypography object. Use Set to store the return value in a variable. Not supported. |
D2TL_DRAWINGEFFECT | Returns an Object to an application-defined drawing effects object. Not supported. |
D2TL_FONTCOLLECTION | Returns an Object with the font collection object IDWriteFontCollection. Use Set to store the return value in a variable. Not supported. |
D2TL_MAXWIDTH, D2TL_MAXHEIGHT | These properties return the maximum width and height (float) of the layout rectangle. Probably the same values specified with the D2Layout() function. The char argument may be omitted. |
D2TL_MINWIDTH | Determines the minimum possible width (float) the layout can be set to without emergency breaking between the characters of whole words occurring. The char argument may be omitted. |
'
' D2RLayout
' Shows attributes for a character in a D2Layout object
$Library "direct2d"
OpenW 1, 0, 0, 300, 300, 48
Global Object RT1
Set RT1 = D2GetRT()
' Build a Text Layout object for a given text
Global Txt1$ = "Hello DirectX" #10 "This is GB" #10 "(GFABASIC 32)"
D2SetFont "Gabriola", 18 ' set a base font for TextLayout
' Obtain TextLayout for text with current font.
' If Txt1 or dimension changes recreate the TextLayout object.
Global oTL1 As Object
Set oTL1 = D2Layout(Txt1$, 100, 60)
' Set font data for text ranges
D2DefLayout oTL1, 0, 5, D2TL_FONTNAME, "Courier New"
D2DefLayout oTL1, 0, 5, D2TL_UNDERLINE, True
D2DefLayout oTL1, 0, 5, D2TL_STRIKETHRU, True
D2DefLayout oTL1, 0, 5, D2TL_FONTSIZE, 12
' Show the text layout properties in Debug output window
Debug.Show
Trace D2RLayout(oTL1, D2TL_FONTNAME, 2) ' of char #2
Trace D2RLayout(oTL1, D2TL_LOCALENAME, 2) ' of char #2
Trace D2RLayout(oTL1, D2TL_WEIGHT, 2)
Trace D2RLayout(oTL1, D2TL_STYLE, 2)
Trace D2RLayout(oTL1, D2TL_STRETCH, 2)
Trace D2RLayout(oTL1, D2TL_FONTSIZE, 2)
Trace D2RLayout(oTL1, D2TL_UNDERLINE, 2)
Trace D2RLayout(oTL1, D2TL_STRIKETHRU, 2)
Trace D2RLayout(oTL1, D2TL_MAXWIDTH)
Trace D2RLayout(oTL1, D2TL_MAXHEIGHT)
Trace D2RLayout(oTL1, D2TL_MINWIDTH)
Trace D2RLayout(oTL1, D2TL_DRAWINGEFFECT, 2)
Trace D2RLayout(oTL1, D2TL_INLINE, 2)
Trace D2RLayout(oTL1, D2TL_TYPOGRAPHY, 2)
Trace D2RLayout(oTL1, D2TL_FONTCOLLECTION, 2)
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2BeginDraw RT1, D2C_WhiteSmoke
Local w!, h!
D2TextSize oTL1, w!, h!
D2SetFont DEFAULT_GUI_FONT ' for D2Text
D2Text 0, 0, "TextLayout's dimension:" + Str(w!) + " x" + Str(h!)
D2TextLayout 10, 10, oTL1, D2T_CENTER ' no clipping
D2EndDraw
EndSub
D2RLayout is the reverse of D2DefLayout.
D2RLayout is a wrapper for the IDWriteTextLayout get methods: see here for more information.
D2Layout, D2DefLayout, D2TextLayout
{Created by Sjouke Hamstra; Last updated: 29/03/2020 by James Gaite}