diff --git a/src/drawables/drawable-interline-spacing.ts b/src/drawables/drawable-interline-spacing.ts new file mode 100644 index 00000000..c7cfa050 --- /dev/null +++ b/src/drawables/drawable-interline-spacing.ts @@ -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); + } +} \ No newline at end of file diff --git a/src/drawables/drawing-wand.ts b/src/drawables/drawing-wand.ts index 4b33ebf7..977a3213 100644 --- a/src/drawables/drawing-wand.ts +++ b/src/drawables/drawing-wand.ts @@ -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; @@ -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); diff --git a/src/index.ts b/src/index.ts index e6597ea4..8b2dc310 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/tests/drawables/drawable-interline-spacing.spec.ts b/tests/drawables/drawable-interline-spacing.spec.ts new file mode 100644 index 00000000..f5daaeac --- /dev/null +++ b/tests/drawables/drawable-interline-spacing.spec.ts @@ -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"); + }); + }); +});