[]
DsPdfJS API / BmpContext
Represents a drawing context for a Bitmap.
new BmpContext(
width,height,scale?,backColor?):BmpContext
Creates a new Bitmap with BmpContext and optionally fills the Bitmap with a background color.
number
The width of drawing surface, in context units (not in pixels, unless scale is 1.0).
number
The height of drawing surface, in context units (not in pixels, unless scale is 1.0).
number
The optional scale factor for mapping from context units to pixels. The default is 1.0 which means that the width and height are in pixels.
An optional background color to fill the drawing surface.
Color | null
BmpContext
DrawingContext.constructor
new BmpContext(
om,width,height,scale?,backColor?):BmpContext
Creates a new Bitmap with BmpContext and optionally fills the Bitmap with a background color.
An object manager that controls the lifetime of the BmpContext object.
number
The width of drawing surface, in context units (not in pixels, unless scale is 1.0).
number
The height of drawing surface, in context units (not in pixels, unless scale is 1.0).
number
The optional scale factor for mapping from context units to pixels. The default is 1.0 which means that the width and height are in pixels.
An optional background color to fill the drawing surface.
Color | null
BmpContext
DrawingContext.constructor
get aliased():
boolean
Gets or sets a value indicating whether the graphic objects are drawn without anti-aliasing.
boolean
set aliased(
value):void
Gets or sets a value indicating whether the graphic objects are drawn without anti-aliasing.
boolean
void
get backgroundBitmap():
Bitmap|null
Gets or sets a Bitmap providing background for all drawing and filling operations. The same bitmap cannot be used as background and target at the same time. The background bitmap must be of the same pixel size as the target bitmap.
Bitmap | null
set backgroundBitmap(
background):void
Gets or sets a Bitmap providing background for all drawing and filling operations. The same bitmap cannot be used as background and target at the same time. The background bitmap must be of the same pixel size as the target bitmap.
Bitmap | null
void
get backgroundContainsUnmodifiedImage():
boolean
Gets or sets a value indicating that copying pixels from the BmpContext#backgroundBitmap to the target bitmap should not be marked as changed in the BmpContext#updatedPixelMask. The default is false, indicating that pixels copied from the background bitmap to the target are marked as changed.
boolean
set backgroundContainsUnmodifiedImage(
value):void
Gets or sets a value indicating that copying pixels from the BmpContext#backgroundBitmap to the target bitmap should not be marked as changed in the BmpContext#updatedPixelMask. The default is false, indicating that pixels copied from the background bitmap to the target are marked as changed.
boolean
void
get bitmap():
Bitmap
Gets the Bitmap object associated with this drawing context.
get blendMode():
BlendMode
Gets or sets the current blend mode for drawing operations.
set blendMode(
blendMode):void
Gets or sets the current blend mode for drawing operations.
void
get drawTextAsPath():
boolean
Gets or sets a value indicating if text is rendered using the graphic paths instead of the specialized text drawing services. Assigning a null value resets the property to a default value that depends on context type. This property does not affect drawing to BmpContext.
boolean
set drawTextAsPath(
value):void
Gets or sets a value indicating if text is rendered using the graphic paths instead of the specialized text drawing services. Assigning a null value resets the property to a default value that depends on context type. This property does not affect drawing to BmpContext.
boolean | null
void
get fontCollection():
FontCollection|null
Gets or sets the FontCollection used by measureText and DrawingContext#drawText/DrawingContext#drawLayout methods.
FontCollection | null
set fontCollection(
coll):void
Gets or sets the FontCollection used by measureText and DrawingContext#drawText/DrawingContext#drawLayout methods.
FontCollection | null
void
get forceAntialiasingForText():
boolean
Gets or sets a value specifying whether text is always drawn with antialiasing regardless the value of the 'aliased' property.
boolean
set forceAntialiasingForText(
value):void
Gets or sets a value specifying whether text is always drawn with antialiasing regardless the value of the 'aliased' property.
boolean
void
get height():
number
Gets the height of the context, in context graphic units.
number
get id():
number
Gets the reference to the object.
number
get interpolationMode():
InterpolationMode
Gets or sets the sampling mode to use when drawing images with resizing.
set interpolationMode(
interpolationMode):void
Gets or sets the sampling mode to use when drawing images with resizing.
void
get matrix():
number[]
Gets or sets the transformation matrix. The matrix consists of six numbers (their meaning is simplified for clarity): m11 - scales the drawing horizontally m12 - skew the the drawing horizontally m21 - skew the the drawing vertically m22 - scales the drawing vertically m31 - moves the the drawing horizontally m32 - moves the the drawing vertically
number[]
set matrix(
matrix):void
Gets or sets the transformation matrix. The matrix consists of six numbers (their meaning is simplified for clarity): m11 - scales the drawing horizontally m12 - skew the the drawing horizontally m21 - skew the the drawing vertically m22 - scales the drawing vertically m31 - moves the the drawing horizontally m32 - moves the the drawing vertically
number[]
void
get om():
ObjectManager
Gets the owner ObjectManager instance.
get slowAntialiasing():
boolean
Gets or sets a value indicating whether the antialiasing algorithm should produce better quality with lower speed.
boolean
set slowAntialiasing(
value):void
Gets or sets a value indicating whether the antialiasing algorithm should produce better quality with lower speed.
boolean
void
get transform():
Transform
Gets or sets the current transformation of the drawing surface.
set transform(
transform):void
Gets or sets the current transformation of the drawing surface.
void
get transparencyMask():
GrayscaleBitmap|null
Gets or sets a GrayscaleBitmap providing transparency mask for all drawing and filling operations. Pixels in the mask with value 0 are fully opaque and will completely mask any drawing (i.e. the pixels of the target bitmap will remain unchanged). Pixels in the mask with value 255 are fully transparent, i.e. any drawing will have the same effect as if there was no mask. Pixels with values between 0 and 255 will modify the transparency of the pixels being drawn according to their value. Note that the transparency mask bitmap must be of the same pixel size as the target bitmap.
GrayscaleBitmap | null
set transparencyMask(
mask):void
Gets or sets a GrayscaleBitmap providing transparency mask for all drawing and filling operations. Pixels in the mask with value 0 are fully opaque and will completely mask any drawing (i.e. the pixels of the target bitmap will remain unchanged). Pixels in the mask with value 255 are fully transparent, i.e. any drawing will have the same effect as if there was no mask. Pixels with values between 0 and 255 will modify the transparency of the pixels being drawn according to their value. Note that the transparency mask bitmap must be of the same pixel size as the target bitmap.
GrayscaleBitmap | null
void
get type():
ContextType
Gets the type of DrawingContext.
get updatedPixelMask():
BilevelBitmap|null
Gets or sets a BilevelBitmap to monitor changes in the target bitmap. Its pixels are used as boolean flags indicating changes in the corresponding pixels of the target bitmap. When a pixel in the target bitmap is changed, the corresponding pixel in this bitmap is set to 1 (true). The BilevelBitmap must have the same pixel size as the target bitmap. It is user's responsibility to clear this bitmap (fill it with zeros) before any drawing on the target occurs.
BilevelBitmap | null
set updatedPixelMask(
pixelMask):void
Gets or sets a BilevelBitmap to monitor changes in the target bitmap. Its pixels are used as boolean flags indicating changes in the corresponding pixels of the target bitmap. When a pixel in the target bitmap is changed, the corresponding pixel in this bitmap is set to 1 (true). The BilevelBitmap must have the same pixel size as the target bitmap. It is user's responsibility to clear this bitmap (fill it with zeros) before any drawing on the target occurs.
BilevelBitmap | null
void
get width():
number
Gets the width of the context, in context graphic units.
number
applyTransform(
transform):void
Applies a new transformation to the current transformation matrix.
The Transform object to be multiplied by the current transformation matrix.
void
createPath():
GraphicsPath
Creates a new GraphicsPath.
A new instance of the GraphicsPath.
drawEllipse(
x,y,width,height,drawEllipseOptions):void
Draws and fills an ellipse.
number
The X coordinate of the rectangle enclosing an ellipse.
number
The Y coordinate of the rectangle enclosing an ellipse.
number
The width of the rectangle enclosing an ellipse.
number
The height of the rectangle enclosing an ellipse.
The options for drawing and filling an ellipse.
void
drawEllipse(
bounds,drawEllipseOptions):void
Draws and fills an ellipse.
The rectangle enclosing an ellipse.
The options for drawing and filling an ellipse.
void
drawImage(
image,x,y,width,height,drawImageOptions?):void
Draws an image or bitmap with specified size, location, and opacity.
The image object to draw.
number
The X coordinate of the destination rectangle.
number
The Y coordinate of the destination rectangle.
number
The width of the destination rectangle.
number
The height of the destination rectangle.
The options for drawing an image.
void
drawImage(
image,bounds,drawImageOptions?):void
Draws an image or bitmap with specified size, location, and opacity.
The image object to draw.
The destination rectangle.
The options for drawing an image.
void
drawLayout(
layout,x,y):void
Draws a Layout at the specified position.
An existing Layout object or the properties describing a new Layout settings.
number
The X coordinate at which to draw the Layout.
number
The Y coordinate at which to draw the Layout.
void
const font = Font.getPdfFont(StandardPdfFont.CourierBold);
const sb = new SolidBrush("CadetBlue");
const lgb = new LinearGradientBrush({
startColor: "Red", startPoint: { x: 0, y: 0 },
gradientStops: [{ offset: 0.5, color: "Green" }],
endColor: "Blue", endPoint: { x: 1, y: 0 }
});
const rgb = new RadialGradientBrush({ startColor: "Red", endColor: "Green" });
const bitmap = new Bitmap(600, 420);
const ctx = bitmap.newContext({ backColor: "Yellow" });
const tf = new Format({ font: font, fontSize: 40 });
ctx.drawLayout({
maxWidth: 600,
firstLineIndent: 50,
runs: [
{ text: "test font Solid fill brush in DsPdfJS\n", format: tf,
fillBrush: sb },
{ text: "test Linear Gradient fill in DsPdfJS\n", format: tf,
fillBrush: lgb },
{ text: "test Radial Gradient fill that spans multiple lines in DsPdfJS",
format: tf, fillBrush: rgb }
]
}, 0, 0);
const res: Uint8Array = bitmap.saveAsPng();
drawLine(
x1,y1,x2,y2,pen):void
Draws a line between two points, using the specified pen.
number
The X coordinate of the first point.
number
The Y coordinate of the first point.
number
The X coordinate of the second point.
number
The Y coordinate of the second point.
The Pen object or settings for creating a pen.
void
drawLines(
points,pen):void
Draws a series of connected lines, using a specified pen.
Point[]
The array of points to connect.
The Pen object or settings for creating a pen.
void
drawPath(
path,drawPathOptions):void
Draws and fills a graphics path.
The GraphicsPath object to draw.
The options for drawing and filling the GraphicsPath.
void
const ctx = new BmpContext(800, 600, 0.5, "Honeydew");
const path = ctx.createPath();
path.beginFigure(100, 350);
path.addLine(210, 310);
path.addArc({
size: { width: 183, height: 173 },
sweepDirection: SweepDirection.Clockwise,
point: { x: 550, y: 205 }
});
path.addLine(650, 170);
path.addLine(680, 250);
path.addLine(575, 285);
path.addArc({
size: { width: 183, height: 173 },
sweepDirection: SweepDirection.Clockwise,
point: { x: 240, y: 390 }
});
path.addLine(130, 430);
path.endFigure(true);
path.addEllipse({ x: 295, y: 197, width: 200, height: 190 });
ctx.drawPath(path, {
fillColor: "MediumAquamarine",
lineColor: "Green",
lineWidth: 20
});
const res: Uint8Array = ctx.bitmap.saveAsPng();
drawPolygon(
points,drawPolygonOptions):void
Draws and fills a polygon.
The array of points or a quadrilateral specifying the polygon.
Point[] | Quadrilateral
The options for drawing and filling a polygon.
void
drawRect(
x,y,width,height,drawRectangleOptions):void
Draws and fills a rectangle or rounded rectangle.
number
The X coordinate of the rectangle.
number
The Y coordinate of the rectangle.
number
The width of the rectangle.
number
The height of the rectangle.
The options for drawing and filling a rectangle.
void
drawRect(
bounds,drawRectangleOptions):void
Draws and fills a rectangle or rounded rectangle.
The rectangle bounds.
The options for drawing and filling a rectangle.
void
drawSvg(
svgDocument,x,y,opacity?):void
Draws a SvgDocument at a point specifying the position of SVG viewport. To specify the position of SVG content rather than viewport, see the drawSvgContent method.
The SvgDocument to draw.
number
The X coordinate of SVG viewport.
number
The Y coordinate of SVG viewport.
number
The opacity factor to be applied to SVG content, between 0.0 (fully transparent) and 1.0 (fully opaque). The default is 1.0.
void
const svgDoc = SvgDocument.load(svgData);
const margin = 50;
const rect = svgDoc.measure(0, 0);
const ctx = new BmpContext(
rect.width + margin * 2,
rect.height + margin * 2,
0.7,
"Linen"
});
ctx.slowAntialiasing = true;
ctx.drawSvg(svgDoc, -rect.x + margin, -rect.y + margin);
const res: Uint8Array = ctx.bitmap.saveAsPng();
drawSvgContent(
svgDocument,x,y,opacity?):void
Draws the content of a specified SvgDocument at a point specifying the top-left corner of SVG content. To specify the position of SVG viewport rather than content, see the drawSvg method.
The SvgDocument to draw.
number
The X coordinate of SVG content.
number
The Y coordinate of SVG content.
number
The opacity factor to be applied to SVG content, between 0.0 (fully transparent) and 1.0 (fully opaque). The default is 1.0.
void
drawSvgToContentRect(
svgDocument,contentX,contentY,contentWidth,contentHeight,opacity?):void
Draws the content of a specified SvgDocument, resizing the content to fit into a specified rectangle. To draw the SVG resizing its viewport rather than just the content, see the drawSvgToRect method.
The SvgDocument to draw.
number
The X coordinate of the target rectangle for SVG content.
number
The Y coordinate of the target rectangle for SVG content.
number
The width of the target rectangle for SVG content.
number
The height of the target rectangle for SVG content.
number
The opacity factor to be applied to SVG content, between 0.0 (fully transparent) and 1.0 (fully opaque). The default is 1.0.
void
DrawingContext.drawSvgToContentRect
drawSvgToContentRect(
svgDocument,contentBounds,opacity?):void
Draws the content of a specified SvgDocument, resizing the content to fit into a specified rectangle. To draw the SVG resizing its viewport rather than just the content, see the drawSvgToRect method.
The SvgDocument to draw.
The target rectangle for SVG content.
number
The opacity factor to be applied to SVG content, between 0.0 (fully transparent) and 1.0 (fully opaque). The default is 1.0.
void
DrawingContext.drawSvgToContentRect
drawSvgToRect(
svgDocument,x,y,width,height,opacity?):void
Draws a SvgDocument, resizing its viewport to fit into the specified rectangle. To draw just the content of the SVG ignoring viewport position, see the drawSvgToContentRect method.
The SvgDocument to draw.
number
The X coordinate of the target rectangle for SVG viewport.
number
The Y coordinate of the target rectangle for SVG viewport.
number
The width of the target rectangle for SVG viewport.
number
The height of the target rectangle for SVG viewport.
number
The opacity factor to be applied to SVG content, between 0.0 (fully transparent) and 1.0 (fully opaque). The default is 1.0.
void
drawSvgToRect(
svgDocument,bounds,opacity?):void
Draws a SvgDocument, resizing its viewport to fit into the specified rectangle. To draw just the content of the SVG ignoring viewport position, see the drawSvgToContentRect method.
The SvgDocument to draw.
The target rectangle for SVG viewport.
number
The opacity factor to be applied to the SVG content, between 0.0 (fully transparent) and 1.0 (fully opaque). The default is 1.0.
void
drawText(
text,format,x,y,maxWidth?):void
Draws text using a specified format at the specified position.
string
The text to draw.
The text format to use.
number
The X coordinate at which to draw the text.
number
The Y coordinate at which to draw the text.
If provided, specifies the maximum width of text.
number | null
void
drawText(
text,font,fontSize,foreColor,x,y,maxWidth?):void
Draws text using a specified attributes at a specified location.
string
The text to draw.
The font to use.
number
The font size.
The text color.
number
The X coordinate at which to draw the text.
number
The Y coordinate at which to draw the text.
If provided, specifies the maximum width of text.
number | null
void
drawText(
textRun,x,y,maxWidth?):void
Draws a text run at the specified position.
The formatted text section to draw.
number
The X coordinate at which to draw the text.
number
The Y coordinate at which to draw the text.
If provided, specifies the maximum width of text.
number | null
void
const pericFont = Font.load(await Util.loadFontAsArray("peric.ttf"));
const emojiFont = Font.load(await Util.loadFontAsArray("seguiemj.ttf"));
const fontColl = new FontCollection();
fontColl.loadFont(await Util.loadFontAsArray("arial.ttf"));
const g = new BmpContext(540, 320, 2, "FloralWhite");
g.fontCollection = fontColl;
g.drawText("Peric Font", pericFont, 40, "Black", 4, 90);
g.drawText({ text: "Arial Font", fontFamily: "Arial", fontSize: 20 }, 300, 110);
g.drawText({
text: "Emoji: " + String.fromCodePoint(0x1F433, 0x1F349, 0x1F367),
font: emojiFont,
fontSize: 40,
paletteIndex: 0
}, 4, 140);
const res: Uint8Array = g.bitmap.saveAsPng();
free():
void
Detaches the object from the ObjectManager and deallocates its memory, if possible.
void
measureText(
text,format,maxWidth?):Size
Measures text using a specified Format.
string
The string to measure.
The text format to use.
If provided, specifies the maximum width of text.
number | null
The actual size needed to draw the text.
measureText(
text,font,fontSize,maxWidth?):Size
Measures text using a specified font, font size and layout width.
string
The string to measure.
The font to use.
number
The font size to use.
If provided, specifies the maximum width of text.
number | null
The actual size needed to draw the text.
measureText(
textRun,maxWidth?):Size
Measures the size of the given text run.
The formatted text section to measure.
If provided, specifies the maximum width of text.
number | null
The actual size needed to draw the text.
popClip():
void
Removes the last clip. After this method is called, the last clip is no longer applied to subsequent drawing operations.
void
popLayer():
void
Stops redirecting drawing operations to the transparency layer that was created by the last pushLayer call.
void
popTransform():
void
Restores the previously pushed transformation from the stack.
void
pushClip(
x,y,width,height):void
Specifies a rectangle to which all subsequent drawing operations are clipped.
number
The X coordinate of the clipping rectangle.
number
The Y coordinate of the clipping rectangle.
number
The width of the clipping rectangle.
number
The height of the clipping rectangle.
void
pushClip(
bounds):void
Specifies a rectangle to which all subsequent drawing operations are clipped.
The clipping rectangle.
void
pushClip(
path):void
Specifies a path to which all subsequent drawing operations are clipped.
The GraphicsPath object defining clipping area.
void
pushLayer(
opacity,contentBounds?):void
Adds a transparency layer to the target surface. That layer receives all subsequent drawing operations until popLayer is called.
number
An opacity value that is applied uniformly to all drawings in the layer when compositing to the backplate. The value is between 0.0 and 1.0.
The content bounds of the transparency layer. Content won't render outside these bounds. If not set, the content bounds are effectively taken to be the bounds of the target surface.
Bounds | null
void
pushTransform():
void
Saves the current transformation to the stack.
void
rebind(
omTo):void
Rebinds the object from the current ObjectManager to the specified one.
The new ObjectManager for the object.
void
resetTransform():
void
Resets the transformation to the identity matrix.
void
rotate(
angle,angleUnits?,cx?,cy?):void
Applies the rotation transformation.
number
The rotation angle.
The angle units. The default is Degrees.
number
The optional center point X offset.
number
The optional center point Y offset.
void
scale(
scaleFactor,cx?,cy?):void
Applies the scaling transformation.
number
The value to scale by on the X and Y axes.
number
The optional center point X offset.
number
The optional center point Y offset.
void
scaleXY(
scaleX,scaleY,cx?,cy?):void
Applies the scaling transformation.
number
The value to scale by on the X axis.
number
The value to scale by on the Y axis.
number
The optional center point X offset.
number
The optional center point Y offset.
void
skew(
angleX,angleY,angleUnits?,cx?,cy?):void
Applies the skew transformation.
number
The X angle.
number
The Y angle.
The angle units. The default is Degrees.
number
The optional center point X offset.
number
The optional center point Y offset.
void
skewX(
angle,angleUnits?):void
Applies the skew transformation along the X axis.
number
The X angle.
The angle units. The default is Degrees.
void
skewY(
angle,angleUnits?):void
Applies the skew transformation along the Y axis.
number
The Y angle.
The angle units. The default is Degrees.
void
translate(
offsetX,offsetY):void
Applies the translation transformation.
number
The horizontal offset.
number
The vertical offset.
void