Documentation/D2DGraphics
classWORKER

D2DGraphics

js/d2d.js:698

Typically used inside on_paint.
Use on_paint(dgr) for D2DGraphics members hints in auto-completion list.
Note: there are many different ways to get colours: window.GetColourDUI/window.GetColourCUI, RGB function from Helpers.js, utils.ColourPicker and etc.

classWORKERCLONEABLE

MeasureStringInfo

js/d2d.js:1163

Example

include(`${fb.ComponentPath}docs\\Flags.js`);
include(`${fb.ComponentPath}docs\\Helpers.js`);

let sf = StringFormat(StringAlignment.Near, StringAlignment.Near);
let text = utils.ReadTextFile("z:\\info.txt");
let font = window.GetFontDUI(0);

function on_paint(gr) {
    gr.DrawString(text, font, RGB(255, 0, 0), 0, 0, window.Width, window.Height, sf);
    let temp = gr.MeasureString(text, font, 0, 0, window.Width, 10000, sf);
    // If we want to calculate height, we must set the height to be far larger than what
    // the text could possibly be.

    console.log(temp.Height); // 2761.2421875 // far larger than my panel height!
    console.log(temp.Chars); // 7967
}
propertyWORKERreadonly

Chars

js/d2d.js:1189
Chars: number
propertyWORKERreadonly

Height

js/d2d.js:1196
Height: float
propertyWORKERreadonly

Height

js/d2d.js:1257
Height: number = 480

Currect height of device context surface.

propertyWORKERreadonly

Lines

js/d2d.js:1203
Lines: number
propertyWORKERreadonly

Width

js/d2d.js:1224
Width: float
propertyWORKERreadonly

Width

js/d2d.js:1250
Width: number = 640

Currect width of device context surface.

propertyWORKERreadonly

X

js/d2d.js:1210
X: float
propertyWORKERreadonly

Y

js/d2d.js:1217
Y: float
methodWORKER

AlphaBlend

js/d2d.js:962
AlphaBlend(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH, alpha)

Parameters

NameTypeDescription
imgD2DBitmap
dstXnumber
dstYnumber
dstWnumber
dstHnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
alpha = 255optionalnumber

Valid values 0-255.

methodWORKER

ApplyTransform

js/d2d.js:1153
ApplyTransform(matrix)

Applies specified transformation matrix of 3x2 size to the current D2DGraphics matrix.
Matrix3x2 helper class from the component/docs/Matrix.js will be useful

Parameters

NameTypeDescription
matrixFloat32Array

Array that presents 3x2 matrix for transformation (length = 6)

Example source

methodWORKER

CalcTextHeight

js/d2d.js:711
CalcTextHeight(str, font)

Calculates text height for DrawText.
Note: this will only calculate the text height of one line.

Parameters

NameTypeDescription
strstring
fontD2DFont

Returns

number
methodWORKER

CalcTextWidth

js/d2d.js:722
CalcTextWidth(str, font, use_exact)

Calculates text width for DrawText.

Note: When the str contains a kerning pair that is found in the specified font, the return value will be larger than the actual drawn width of the text. If accurate values are required, set use_exact to true.

Parameters

NameTypeDescription
strstring
fontD2DFont
use_exact = falseoptionalboolean

Uses a slower, but more accurate method of calculating text width which accounts for kerning pairs.

Returns

number
methodWORKER

DrawEffect

js/d2d.js:737
DrawEffect(effect, dstX, dstY, srcX, srcY, srcW, srcH, compositionMode)

Parameters

NameTypeDescription
imgD2DEffect
dstXnumber
dstYnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
compositionMode = CompositeMode.SourceOveroptionalCompositeMode

See CompositeMode

methodWORKER

DrawEllipse

js/d2d.js:750
DrawEllipse(x, y, w, h, line_width, colour_or_brush, strokeStyle)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
line_widthnumber
colour_or_brush*

colour ARGB or D2DBrush object

strokeStyle = DashStyle.Solidoptional(DashStyle|D2DStrokeStyle)

DashStyle shorthand or reusable D2DStrokeStyle

Example source

methodWORKER

DrawImage

js/d2d.js:763
DrawImage(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH, angle, alpha)

Parameters

NameTypeDescription
imgD2DBitmap
dstXnumber
dstYnumber
dstWnumber
dstHnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
angle = 0optionalfloat
alpha = 255optionalnumber

Valid values 0-255.

methodWORKER

DrawLine

js/d2d.js:795
DrawLine(x1, y1, x2, y2, line_width, colour_or_brush, strokeStyle, startCap, endCap)

Parameters

NameTypeDescription
x1number
y1number
x2number
y2number
line_widthnumber
colour_or_brush*

colour ARGB or D2DBrush object

strokeStyle = DashStyle.Solidoptional(DashStyle|D2DStrokeStyle)

DashStyle shorthand or reusable D2DStrokeStyle

startCap = CapStyle.FlatoptionalCapStyle

Legacy start cap used only when strokeStyle is a DashStyle value. A D2DStrokeStyle carries its own caps.

endCap = CapStyle.FlatoptionalCapStyle

Legacy end cap used only when strokeStyle is a DashStyle value. A D2DStrokeStyle carries its own caps.

Example source

methodWORKER

DrawLines

js/d2d.js:810
DrawLines(colour_or_brush, line_width, points, strokeStyle)

Draws a connected sequence of lines.

Parameters

NameTypeDescription
colour_or_brush*

colour ARGB or D2DBrush object

line_widthnumber
pointsArray<number>

array of connected points [x1, y1, x2, y2, ...]

strokeStyle = DashStyle.Solidoptional(DashStyle|D2DStrokeStyle)

DashStyle shorthand or reusable D2DStrokeStyle

Example source

methodWORKER

DrawPolygon

js/d2d.js:822
DrawPolygon(colour_or_brush, line_width, points, strokeStyle)

Draws a connected sequence of lines with connection of last and first points (unlike DrawLines).

Parameters

NameTypeDescription
colour_or_brush*

colour ARGB or D2DBrush object

line_widthnumber
pointsArray<number>

array of connected points [x1, y1, x2, y2, ...]

strokeStyle = DashStyle.Solidoptional(DashStyle|D2DStrokeStyle)

DashStyle shorthand or reusable D2DStrokeStyle

Example source

methodWORKER

DrawRect

js/d2d.js:849
DrawRect(x, y, w, h, line_width, colour_or_brush, strokeStyle)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
line_widthnumber
colour_or_brush*

colour ARGB or D2DBrush object

strokeStyle = DashStyle.Solidoptional(DashStyle|D2DStrokeStyle)

DashStyle shorthand or reusable D2DStrokeStyle

Example source

methodWORKER

DrawRoundRect

js/d2d.js:862
DrawRoundRect(x, y, w, h, arc_width, arc_height, line_width, colour_or_brush, strokeStyle)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
arc_widthnumber
arc_heightnumber
line_widthnumber
colour_or_brush*

colour ARGB or D2DBrush object

strokeStyle = DashStyle.Solidoptional(DashStyle|D2DStrokeStyle)

DashStyle shorthand or reusable D2DStrokeStyle

Example source

methodWORKER

DrawString

js/d2d.js:834
DrawString(str, font, colour_or_brush, x, y, w, h, flags)

Should be only used when DrawText is not applicable.

Parameters

NameTypeDescription
strstring
fontD2DFont
colour_or_brush*

colour ARGB or D2DBrush object

xnumber
ynumber
wnumber
hnumber
flags = 0optionalnumber

See StringFormatFlags flags

methodWORKER

DrawStrokedText

js/d2d.js:1019
DrawStrokedText(str, font, strokeColor, strokeWidth, fillColor, x, y, w, h)

Draws stroked text in clipped rectangle. Flags for formatting text are not supported.

Parameters

NameTypeDescription
strstring
fontD2DFont
strokeColornumber
strokeWidthnumber
xnumber
ynumber
wnumber
hnumber
methodWORKER

DrawText

js/d2d.js:994
DrawText(str, font, colour_or_brush, x, y, w, h, format)

Provides faster and better rendering than DrawString.

Do not use this to draw text on transparent background or with D2DGraphics other than the one passed in on_paint callback: this will result in visual artifacts caused by ClearType hinting.
Use DrawString instead in such cases.

To calculate text dimensions use CalcTextHeight, CalcTextWidth.

Note: uses special rules for & character by default, which consumes the & and causes the next character to be underscored. This behaviour can be changed (or disabled) via format parameter.

Parameters

NameTypeDescription
strstring
fontD2DFont
colour_or_brush*

colour ARGB or D2DBrush object

xnumber
ynumber
wnumber
hnumber
format = 0optionalnumber

See flags like DT_LEFT

methodWORKER

EstimateLineWrap

js/d2d.js:877
EstimateLineWrap(str, font, max_width)

Parameters

NameTypeDescription
strstring
fontD2DFont
max_widthnumber

Returns

Array<Array> —

index | meaning
[0] text line 1
[1] width of text line 1 (in pixel)
[2] text line 2
[3] width of text line 2 (in pixel)
...
[2n + 2] text line n
[2n + 3] width of text line n (px)

methodWORKER

FillEllipse

js/d2d.js:894
FillEllipse(x, y, w, h, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
colour_or_brush*

colour ARGB or D2DBrush object

methodWORKER

FillGradRect

js/d2d.js:904
FillGradRect(x, y, w, h, angle, colour1, colour2, focus)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
anglefloat
colour1number
colour2number
focus = 1.0optionalfloat

Specify where the centred colour will be at its highest intensity. Valid values between 0 and 1.

methodWORKER

FillGradRectV2

js/d2d.js:917
FillGradRectV2(x, y, w, h, angle, stops)

Fills rect with gradient in arbitrary quantity of stops.

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
anglefloat
stopsArray

Specifies gradient stops in form of [pos0, argb0, ..., posN, argbN]

Example

dgr.FillGradRectV2(10, 10, 200, 100, 0, [0.0, 0xFF0000FF, 0.5, 0xFFFF0000, 1.0, 0xFF000000]);
methodWORKER

FillPolygon

js/d2d.js:932
FillPolygon(colour_or_brush, fillmode, points)

Parameters

NameTypeDescription
colour_or_brush*

colour ARGB or D2DBrush object

fillmodenumber

0 alternate, 1 winding.

pointsArray<Array<number>>
methodWORKER

FillRoundRect

js/d2d.js:940
FillRoundRect(x, y, w, h, arc_width, arc_height, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
arc_widthnumber
arc_heightnumber
colour_or_brush*

colour ARGB or D2DBrush object

methodWORKER

FillSolidRect

js/d2d.js:952
FillSolidRect(x, y, w, h, colour_or_brush)

Parameters

NameTypeDescription
xnumber
ynumber
wnumber
hnumber
colour_or_brush*

colour ARGB or D2DBrush object

methodWORKER

GdiAlphaBlend

js/d2d.js:977
GdiAlphaBlend(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH, alpha)

Compatibility alias of AlphaBlend.

Parameters

NameTypeDescription
imgD2DBitmap
dstXnumber
dstYnumber
dstWnumber
dstHnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
alpha = 255optionalnumber
methodWORKER

GdiDrawBitmap

js/d2d.js:779
GdiDrawBitmap(img, dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH)

Compatibility alias of DrawImage.

Parameters

NameTypeDescription
imgD2DBitmap
dstXnumber
dstYnumber
dstWnumber
dstHnumber
srcXnumber
srcYnumber
srcWnumber
srcHnumber
methodWORKER

GetTransform

js/d2d.js:1127
GetTransform()

Gets D2DGraphics current transformation matrix of 3x2 size (Float32Array(6))
Matrix3x2 helper class from the component/docs/Matrix.js will be useful

Returns

Float32Array

Example source

methodWORKER

MeasureString

js/d2d.js:1033
MeasureString(str, font, x, y, w, h, flags)

Calculates text dimensions for DrawString.

Parameters

NameTypeDescription
strstring
fontD2DFont
xnumber
ynumber
wnumber
hnumber
flags = 0optionalnumber

See StringFormatFlags flags

Returns

MeasureStringInfo
methodWORKER

PopClip

js/d2d.js:1062
PopClip()

Restores the clipping region that was active before the matching PushClip call.
Does nothing if the clip stack is empty.
The current transform and other graphics state are not affected.

methodWORKER

PopTransform

js/d2d.js:1121
PopTransform()

Restores D2DGraphics matrix from internal stack pushed previously by PushTransform.

methodWORKER

PushClip

js/d2d.js:1048
PushClip(x, y, width, height)

Pushes a rectangular clipping region onto the clip stack.
The new clipping region is intersected with the current clipping region.
Calls may be nested and should be paired with PopClip.
The current transform and other graphics state are not affected.

Parameters

NameTypeDescription
xnumber

left coordinate of the clipping rectangle

ynumber

top coordinate of the clipping rectangle

widthnumber

width of the clipping rectangle

heightnumber

height of the clipping rectangle

methodWORKER

PushTransform

js/d2d.js:1115
PushTransform()

Saves current D2DGraphics matrix in internal stack. To restore the matrix use PopTransform.

methodWORKER

ResetTransform

js/d2d.js:1147
ResetTransform()

Resets current D2DGraphics matrix to original identity matrix.

methodWORKER

Rotate

js/d2d.js:1080
Rotate(angle, cx, cy)

Applies rotation matrix to the current D2DGraphics matrix.
For more information see https://learn.microsoft.com/en-us/windows/win32/api/d2d1helper/nf-d2d1helper-matrix3x2f-rotation

Parameters

NameTypeDescription
anglefloat

Angle of rotation in degrees

cx = 0optionalnumber

Rotation center point x coord

cy = 0optionalnumber

Rotation center point y coord

methodWORKER

Scale

js/d2d.js:1091
Scale(sz, sy, cx, cy)

Applies scale matrix to the current D2DGraphics matrix.
For more information see https://learn.microsoft.com/en-us/windows/win32/api/d2d1helper/nf-d2d1helper-matrix3x2f-scale(d2d1_size_f_d2d1_point_2f)

Parameters

NameTypeDescription
sxfloat

The x-axis scale factor

sy = 0optionalfloat

The y-axis scale factor. If zero sx will be used as sy

cx = 0optionalnumber

Scale center point x coord

cy = 0optionalnumber

Scale center point y coord

methodWORKER

SetInterpolationMode

js/d2d.js:1232
SetInterpolationMode(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See InterpolationMode enum

methodWORKER

SetSmoothingMode

js/d2d.js:1238
SetSmoothingMode(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See SmoothingMode enum

methodWORKER

SetTextRenderingHint

js/d2d.js:1244
SetTextRenderingHint(mode)

Parameters

NameTypeDescription
mode = 0optionalnumber

See TextRenderingHint enum

methodWORKER

SetTransform

js/d2d.js:1137
SetTransform(matrix)

Replaces the current D2DGraphics matrix with specified transformation matrix of 3x2 size.
Matrix3x2 helper class from the component/docs/Matrix.js will be useful

Parameters

NameTypeDescription
matrixFloat32Array

Array that presents 3x2 matrix for transformation (length = 6)

Example source

methodWORKER

Skew

js/d2d.js:1103
Skew(angleX, angleY, cx, cy)

Applies skew matrix to the current D2DGraphics matrix.
For more information see https://learn.microsoft.com/en-us/windows/win32/api/d2d1helper/nf-d2d1helper-matrix3x2f-skew

Parameters

NameTypeDescription
angleXfloat

The x-axis skew angle, which is measured in degrees counterclockwise from the y-axis.

angleYfloat

The y-axis skew angle, which is measured in degrees clockwise from the x-axis.

cx = 0optionalnumber

Skew center point x coord

cy = 0optionalnumber

Skew center point y coord

methodWORKER

Translate

js/d2d.js:1070
Translate(dx, dy)

Applies translation matrix to the current D2DGraphics matrix.
For more information see https://learn.microsoft.com/en-us/windows/win32/api/d2d1helper/nf-d2d1helper-matrix3x2f-translation(d2d1_size_f)

Parameters

NameTypeDescription
dxnumber
dynumber