v0.4.0

GDI v0.1.0

Source
Fonts and text drawing through the Graphics Device Interface.

FW_NORMAL

pub const FW_NORMAL: int32 = 400;

FW_NORMAL: the regular weight of a font.

Source

FW_SEMIBOLD

pub const FW_SEMIBOLD: int32 = 600;

FW_SEMIBOLD: the weight between regular and bold, which Windows uses for headings.

Source

FW_BOLD

pub const FW_BOLD: int32 = 700;

FW_BOLD: the bold weight of a font.

Source

DEFAULT_CHARSET

pub const DEFAULT_CHARSET: uint32 = 1;

DEFAULT_CHARSET: let the font mapper choose the character set from the face name.

Source

OUT_DEFAULT_PRECIS

pub const OUT_DEFAULT_PRECIS: uint32 = 0;

OUT_DEFAULT_PRECIS: let the font mapper decide how closely the font must match.

Source

CLIP_DEFAULT_PRECIS

pub const CLIP_DEFAULT_PRECIS: uint32 = 0;

CLIP_DEFAULT_PRECIS: clip characters the default way.

Source

CLEARTYPE_QUALITY

pub const CLEARTYPE_QUALITY: uint32 = 5;

CLEARTYPE_QUALITY: draw the font with ClearType smoothing.

Source

DEFAULT_PITCH

pub const DEFAULT_PITCH: uint32 = 0;

DEFAULT_PITCH: let the font mapper choose fixed or variable pitch.

Source

TRANSPARENT

pub const TRANSPARENT: int32 = 1;

TRANSPARENT: text is drawn without filling the cell behind it.

Source

OPAQUE

pub const OPAQUE: int32 = 2;

OPAQUE: text is drawn on a cell filled with the background color.

Source

CreateFontW

pub extern func CreateFontW(
    height: int32,
    width: int32,
    escapement: int32,
    orientation: int32,
    weight: int32,
    italic: uint32,
    underline: uint32,
    strikeOut: uint32,
    charSet: uint32,
    outPrecision: uint32,
    clipPrecision: uint32,
    quality: uint32,
    pitchAndFamily: uint32,
    faceName: *char16
) -> *var opaque

Creates a logical font, which the mapper matches to the closest installed font when it is selected. A negative height asks for that many pixels of character height without the internal leading, which is how a point size is given: -(points * dpi / 72).

See also: https://learn.microsoft.com/windows/win32/api/wingdi/nf-wingdi-createfontw

Source

Parameters

NameTypeDescription
heightint32the character height in pixels, negative for the character height without the leading
widthint32the average character width, or zero to derive it from the height
escapementint32the angle of the text line, in tenths of a degree
orientationint32the angle of each character, in tenths of a degree
weightint32the weight, such as FW_NORMAL
italicuint32non-zero for italic
underlineuint32non-zero for underlined
strikeOutuint32non-zero for struck out
charSetuint32the character set, usually DEFAULT_CHARSET
outPrecisionuint32how closely the font must match, usually OUT_DEFAULT_PRECIS
clipPrecisionuint32how characters are clipped, usually CLIP_DEFAULT_PRECIS
qualityuint32how it is smoothed, such as CLEARTYPE_QUALITY
pitchAndFamilyuint32the pitch and family, usually DEFAULT_PITCH
faceName*char16the NUL-terminated UTF-16 face name, such as Segoe UI

Returns: the font, which the caller deletes with DeleteObject, or null on failure

DeleteObject

pub extern func DeleteObject(object: *var opaque) -> bool32

Deletes a GDI object such as a font, giving back what the system holds for it. An object still selected into a device context is not deleted, and the call fails.

See also: https://learn.microsoft.com/windows/win32/api/wingdi/nf-wingdi-deleteobject

Source

Parameters

NameTypeDescription
object*var opaquethe object to delete

Returns: non-zero on success, and zero when the handle is not valid or the object is still selected

SelectObject

pub extern func SelectObject(
    deviceContext: *var opaque,
    object: *var opaque
) -> *var opaque

Selects a font or another GDI object into a device context, replacing the one of the same kind. The object replaced is returned so it can be selected back before the context is given up.

See also: https://learn.microsoft.com/windows/win32/api/wingdi/nf-wingdi-selectobject

Source

Parameters

NameTypeDescription
deviceContext*var opaquethe device context
object*var opaquethe object to select

Returns: the object it replaced, or null on failure

SetBkMode

pub extern func SetBkMode(
    deviceContext: *var opaque,
    mode: int32
) -> int32

Sets whether text is drawn on a filled cell or straight onto what is already there.

See also: https://learn.microsoft.com/windows/win32/api/wingdi/nf-wingdi-setbkmode

Source

Parameters

NameTypeDescription
deviceContext*var opaquethe device context
modeint32TRANSPARENT or OPAQUE

Returns: the mode before the call, or zero on failure

SetTextColor

pub extern func SetTextColor(
    deviceContext: *var opaque,
    color: uint32
) -> uint32

Sets the color text is drawn in.

See also: https://learn.microsoft.com/windows/win32/api/wingdi/nf-wingdi-settextcolor

Source

Parameters

NameTypeDescription
deviceContext*var opaquethe device context
coloruint32the color as 0x00BBGGRR, such as one from GetSysColor

Returns: the color before the call, or CLR_INVALID (0xFFFFFFFF) on failure

TextOutW

pub extern func TextOutW(
    deviceContext: *var opaque,
    x: int32,
    y: int32,
    text: *char16,
    count: int32
) -> bool32

Draws a run of UTF-16 text with its top-left corner at a point, in the selected font and text color. The run is counted rather than NUL-terminated, and is not wrapped or clipped to the window.

See also: https://learn.microsoft.com/windows/win32/api/wingdi/nf-wingdi-textoutw

Source

Parameters

NameTypeDescription
deviceContext*var opaquethe device context
xint32the left edge, in pixels
yint32the top edge, in pixels
text*char16the UTF-16 units to draw
countint32how many units to draw

Returns: non-zero on success, and zero on failure