D2FontSize, D2FontBold, D2FontItalic, D2FontStretch, D2FontName, D2FontLocaleName Commands and Functions

Requires: Direct2D.lg32

Purpose

Modify or return a property of the current selected D2Font.

Syntax

D2FontSize(height!)
D2FontBold(weight%)
D2FontItalic(flag?)
D2FontStretch(stretch%)
D2FontName(fontname$)
D2FontLocaleName(loc$)

height! = D2FontSize()
weight% = D2FontBold()
flag? = D2FontItalic()
stretch% = D2FontStretch()
fontname$ = D2FontName()
loc$ = D2FontLocaleName()

Height! : float exp
weight%, stretch%: integer exp
Flag?: Boolean exp
Fontname$, loc$: string exp

Description

D2FontSize command sets the new height of the current font: Note the height! parameter must specify a DIP value (use the D2PointsToDIPS function to convert a points value to DIPs).

D2FontBold command sets the weight of the current font: weight% can have one of these predefined values

D2FontItalic command sets the italic style of the curent font; set Flag? to True for an intalics font.

D2FontStretch command sets the stretch style of the current font: stretch% can take one of these values:

D2FontName command specifies the name for the new font.

D2FontLocaleName command specifies the localename for the font, like "en-us".

Each command creates and selects a new D2Font object.

Each corresponding function returns the respective setting in the current font; Note that height! is returned as a DIP value so use D2DIPsToPoints to convert this to a point value, if required.

Example

'

' D2FontSize sample  (dpi-unaware)

'

$Library "direct2d"

Global Object Win1RT, DefaultFnt

OpenW 1, 0, 0, 320, 300, ~15

Set Win1RT = D2GetRT()

D2FontSize(D2PointsToDIPs(10))   ' in points

D2FontName("Trebuchet MS")

D2GetFontObj DefaultFnt

Do

Sleep

Until Me Is Nothing

 

Sub Win_1_Paint

Local sTxt As String = "Hello Direct2D World", fntHeight!

D2BeginDraw Win1RT, D2C_White

D2SetFont DefaultFnt                  ' use D2 default font

D2Text 10, 10, sTxt

' Modify currently selected font

fntHeight! = D2FontSize()             ' of current font

D2FontSize(fntHeight! * 1.5)          ' in DIPs (96 dpi pixels)

D2FontItalic(True)                    ' use italics

D2Text 10, 30, "Using DirectWrite"

D2EndDraw

EndSub

 

Sub Win_1_ReSize

D2ResizeRT Win1RT, _X, _Y

Remarks

Because each command creates and selects a new D2Font object, it might be preferable to create and cache D2Font objects before used in drawing. Using D2SetFont with a cached D2Font object is much faster than recreating the D2Font object each time one of these commands is executed.

See Also

D2Font, D2GetFontObj, D2PointsToDIPs, D2DIPsToPoints, D2RFont, D2SetFont, D2TextSize

{Created by Sjouke Hamstra; Last updated: 27/12/2021 by James Gaite}