Skip to content

Commit

Permalink
Added textKerning to MagickSettings (#79).
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Apr 28, 2023
1 parent b1719c6 commit 385a746
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/settings/magick-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class MagickSettings {

textInterlineSpacing?: number;

textKerning?: number;

getDefine(name: string): string;
getDefine(format: MagickFormat, name: string): string;
getDefine(nameOrFormat: MagickFormat | string, name?: string): string {
Expand Down
3 changes: 3 additions & 0 deletions src/settings/native-magick-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export class NativeMagickSettings extends NativeInstance {
if (settings.textInterlineSpacing !== undefined)
this.setOption('interline-spacing', settings.textInterlineSpacing.toString());

if (settings.textKerning !== undefined)
this.setOption('kerning', settings.textKerning.toString());

for (const option in settings._options)
this.setOption(option, settings._options[option]);
}
Expand Down
25 changes: 25 additions & 0 deletions tests/settings/magick-settings/text-kerning.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
// Licensed under the Apache License, Version 2.0.

import { ImageMagick } from '../../../src/image-magick';
import { MagickReadSettings } from '../../../src/settings/magick-read-settings';
import { TestFiles } from '../../test-files';
import '../../custom-matcher';

beforeAll(() => { ImageMagick._api = global.native; });

describe('MagickSettings#textKerning', () => {
it.each([
[30, 373, 20],
[130, 1373, 20],
])('should draw text with the expected kerning %s', (textKerning: number, width: number, height: number) => {
const settings = new MagickReadSettings();
settings.font = TestFiles.Fonts.kaushanScriptRegularTtf.name;
settings.textKerning = textKerning;

ImageMagick.read('label:magick-wasm', settings, (image) => {
expect(image.width).toBe(width);
expect(image.height).toBe(height);
});
});
});

0 comments on commit 385a746

Please sign in to comment.