Skip to content

Commit

Permalink
Added DrawableTextUnderColor.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jul 19, 2023
1 parent 7c8edec commit 4e78dfc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/drawables/drawable-text-under-color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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';
import { MagickColor } from '../magick-color';

export class DrawableTextUnderColor implements IDrawable {
private readonly _color: MagickColor;

constructor(color: MagickColor) {
this._color = color;
}

draw(wand: IDrawingWand): void {
wand.textUnderColor(this._color);
}
}
9 changes: 9 additions & 0 deletions src/drawables/drawing-wand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface IDrawingWand extends IDisposable {
textInterlineSpacing(value: number): void;
textInterwordspacing(value: number): void;
textKerning(value: number): void;
textUnderColor(value: MagickColor): void;
}

export class DrawingWand extends NativeInstance implements IDrawingWand {
Expand Down Expand Up @@ -151,6 +152,14 @@ export class DrawingWand extends NativeInstance implements IDrawingWand {
});
}

textUnderColor(value: MagickColor): void {
Exception.usePointer(exception => {
value._use(valuePtr => {
ImageMagick._api._DrawingWand_TextUnderColor(this._instance, valuePtr, exception);
});
});
}

/** @internal */
static _create(image: IMagickImage, settings: MagickSettings): DrawingWand {
return new DrawingWand(image, settings);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export * from './drawables/drawable-text-decoration';
export * from './drawables/drawable-text-interline-spacing';
export * from './drawables/drawable-text-interword-spacing';
export * from './drawables/drawable-text-kerning';
export * from './drawables/drawable-text-under-color';
export * from './drawables/drawable-text';
export * from './drawables/drawable';
export * from './drawables/drawing-wand';
Expand Down
41 changes: 41 additions & 0 deletions tests/drawables/drawable-text-under-color.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { DrawableFont } from "../../src/drawables/drawable-font";
import { DrawableFontPointSize } from "../../src/drawables/drawable-font-point-size";
import { DrawableText } from "../../src/drawables/drawable-text";
import { DrawableTextUnderColor } from "../../src/drawables/drawable-text-under-color";
import { MagickColors } from "../../src/magick-colors";
import { TestFonts } from "../test-fonts";
import { TestImages } from "../test-images";

describe("DrawableTextUnderColor", () => {
it("should write text without text under color to the image", () => {
TestImages.emptyCanvas.use((image) => {
image.draw([
new DrawableFont(TestFonts.kaushanScriptRegularTtf.name),
new DrawableFontPointSize(80),
new DrawableText(0, 100, "I"),
]);

expect(image).toHavePixelWithColor(37, 50, "#ffffffff");
expect(image).toHavePixelWithColor(38, 50, "#ffffffff");
expect(image).toHavePixelWithColor(39, 50, "#ffffffff");
});
});

it("should write text with text under color to the image", () => {
TestImages.emptyCanvas.use((image) => {
image.draw([
new DrawableFont(TestFonts.kaushanScriptRegularTtf.name),
new DrawableFontPointSize(80),
new DrawableTextUnderColor(MagickColors.Pink),
new DrawableText(0, 100, "I"),
]);

expect(image).toHavePixelWithColor(37, 50, "#ffc0cbff");
expect(image).toHavePixelWithColor(38, 50, "#fffcfdff");
expect(image).toHavePixelWithColor(39, 50, "#ffffffff");
});
});
});

0 comments on commit 4e78dfc

Please sign in to comment.