Skip to content

Commit

Permalink
Add drawable-interline-spacing (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannanilsson authored Jul 7, 2023
1 parent ff80cef commit d9c5541
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/drawables/drawable-interline-spacing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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";

export class DrawableInterlineSpacing implements IDrawable {
private readonly _interlineSpacing: number;

constructor(interlineSpacing: number) {
this._interlineSpacing = interlineSpacing;
}

draw(wand: IDrawingWand): void {
wand.interlineSpacing(this._interlineSpacing);
}
}
7 changes: 7 additions & 0 deletions src/drawables/drawing-wand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IDrawingWand extends IDisposable {
font(family: string): void;
fontPointSize(value: number): void;
gravity(value: Gravity): void;
interlineSpacing(value: number): void;
kerning(value: number): void;
rectangle(upperLeftX: number, upperLeftY: number, lowerRightX: number, lowerRightY: number): void;
roundRectangle(upperLeftX: number, upperLeftY: number, lowerRightX: number, lowerRightY: number, cornerWidth: number, cornerHeight: number): void;
Expand Down Expand Up @@ -88,6 +89,12 @@ export class DrawingWand extends NativeInstance implements IDrawingWand {
});
}

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

kerning(value: number): void {
Exception.usePointer(exception => {
ImageMagick._api._DrawingWand_TextKerning(this._instance, value, exception);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export * from './drawables/drawable-fill-opacity';
export * from './drawables/drawable-font-point-size';
export * from './drawables/drawable-font';
export * from './drawables/drawable-gravity';
export * from './drawables/drawable-interline-spacing';
export * from './drawables/drawable-kerning';
export * from './drawables/drawable-rectangle';
export * from './drawables/drawable-round-rectangle';
Expand Down
40 changes: 40 additions & 0 deletions tests/drawables/drawable-interline-spacing.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { DrawableText } from "../../src/drawables/drawable-text";
import { DrawableInterlineSpacing } from "../../src/drawables/drawable-interline-spacing";
import { DrawableFillColor } from "../../src/drawables/drawable-fill-color";
import { DrawableFont } from "../../src/drawables/drawable-font";
import { DrawableFontPointSize } from "../../src/drawables/drawable-font-point-size";
import { MagickColor } from "../../src/magick-color";
import { TestFonts } from "../test-fonts";
import { TestImages } from "../test-images";

describe("DrawableInterlineSpacing", () => {
it("should write text with increased interline spacing", () => {
TestImages.emptyCanvas.use((image) => {
image.draw([
new DrawableFont(TestFonts.kaushanScriptRegularTtf.name),
new DrawableFontPointSize(50),
new DrawableInterlineSpacing(10),
new DrawableFillColor(new MagickColor("pink")),
new DrawableText(50, 50, "I\nI"),
]);

expect(image).toHavePixelWithColor(60, 131, "#ffc0cbff");
});
});

it("should write text with default interline spacing", () => {
TestImages.emptyCanvas.use((image) => {
image.draw([
new DrawableFont(TestFonts.kaushanScriptRegularTtf.name),
new DrawableFontPointSize(50),
new DrawableFillColor(new MagickColor("pink")),
new DrawableText(50, 50, "I\nI"),
]);

expect(image).toHavePixelWithColor(60, 131, "#ffffffff");
});
});
});

0 comments on commit d9c5541

Please sign in to comment.