Skip to content

Commit

Permalink
Added DrawableStrokeWidth.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Nov 25, 2023
1 parent 67d70ab commit 495ddb6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/drawables/drawable-stroke-width.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { IDrawable } from './drawable';
import { IDrawingWand } from './drawing-wand';

/**
* Sets the width of the stroke used to draw object outlines.
*/
export class DrawableStrokeWidth implements IDrawable {
private readonly _width: number;

/**
* Initializes a new instance of the {@link DrawableStrokeWidth} class.
* @param width - The width.
*/
constructor(width: number) {
this._width = width;
}

draw(wand: IDrawingWand): void {
wand.strokeWidth(this._width);
}
}
7 changes: 7 additions & 0 deletions src/drawables/drawing-wand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface IDrawingWand extends IDisposable {
rectangle(upperLeftX: number, upperLeftY: number, lowerRightX: number, lowerRightY: number): void;
roundRectangle(upperLeftX: number, upperLeftY: number, lowerRightX: number, lowerRightY: number, cornerWidth: number, cornerHeight: number): void;
strokeColor(value: IMagickColor): void;
strokeWidth(value: number): void
text(x: number, y: number, value: string): void;
textAlignment(value: TextAlignment): void;
textAntialias(value: boolean): void;
Expand Down Expand Up @@ -134,6 +135,12 @@ export class DrawingWand extends NativeInstance implements IDrawingWand {
});
}

strokeWidth(value: number): void {
Exception.usePointer(exception => {
ImageMagick._api._DrawingWand_StrokeWidth(this._instance, value, exception);
});
}

text(x: number, y: number, value: string): void {
Exception.usePointer(exception => {
_withString(value, valuePtr => {
Expand Down
28 changes: 28 additions & 0 deletions tests/drawables/drawable-stroke-width.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { DrawableLine } from '@src/drawables/drawable-line';
import { DrawableStrokeColor } from '@src/drawables/drawable-stroke-color';
import { DrawableStrokeWidth } from '@src/drawables/drawable-stroke-width';
import { MagickColors } from '@src/magick-colors';
import { TestImages } from '@test/test-images';

describe('DrawableStrokeWidth', () => {
it('should change the width of a line', () => {
TestImages.empty150x150Canvas.use((image) => {
const strokeColor = MagickColors.Green;

image.draw([
new DrawableStrokeColor(strokeColor),
new DrawableStrokeWidth(10),
new DrawableLine(10, 10, 40, 50)
]);

expect(image).toHavePixelWithColor(9, 9, MagickColors.White);
expect(image).toHavePixelWithColor(10, 10, strokeColor);
expect(image).toHavePixelWithColor(6, 13, strokeColor);
expect(image).toHavePixelWithColor(44, 47, strokeColor);
expect(image).toHavePixelWithColor(40, 50, strokeColor);
});
});
});

0 comments on commit 495ddb6

Please sign in to comment.