Skip to content

Commit 5538abe

Browse files
committed
Add Script class wrapping hb_script_t
1 parent 2c16afe commit 5538abe

6 files changed

Lines changed: 424 additions & 19 deletions

File tree

MIGRATING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Affected APIs:
7070
- `Buffer.serialize` now takes a single options object: `{ font, start, end, format, flags }` (all optional). The previous positional signature is gone.
7171
- `shape` and `shapeWithTrace` now take `Feature[]` instead of a comma-separated string. Use the new `Feature` class (e.g. `new Feature("liga", 0)` or `Feature.fromString("-liga")`).
7272
- `Buffer.setLanguage`, `Face.getName`, `Face.listNames`, and `otTagToLanguage` now use the new `Language` class instead of plain BCP 47 strings (e.g. `buffer.setLanguage(new Language("en"))`).
73+
- `Buffer.setScript` and `otTagToScript` now use the new `Script` class instead of plain ISO 15924 tag strings (e.g. `buffer.setScript(new Script("Latn"))` or, for the predefined ISO 15924 scripts, `buffer.setScript(Script.LATIN)`).
7374
- `Buffer.addText` / `Buffer.addCodePoints`: `itemLength` accepts `undefined` (or omission), instead of `null`.
7475
- `Face.getFeatureNameIds`: returns `undefined` on failure, instead of `null`.
7576
- `Font.glyphHOrigin` / `glyphVOrigin` / `glyphExtents` / `glyphFromName`: return `undefined` on failure, instead of `null`.

src/buffer.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import {
44
track,
55
hb_tag,
66
utf8_ptr_to_string,
7-
string_to_ascii_ptr,
87
string_to_utf16_ptr,
98
type ValueOf,
109
} from "./helpers";
1110
import type { GlyphInfo, GlyphPosition } from "./types";
1211
import { Font } from "./font";
1312
import type { Language } from "./language";
13+
import type { Script } from "./script";
1414

1515
export const BufferContentType = {
1616
INVALID: 0,
@@ -186,15 +186,10 @@ export class Buffer {
186186

187187
/**
188188
* Set buffer script explicitly.
189-
* @param script The buffer script
189+
* @param script The buffer script.
190190
*/
191-
setScript(script: string): void {
192-
const str = string_to_ascii_ptr(script);
193-
exports.hb_buffer_set_script(
194-
this.ptr,
195-
exports.hb_script_from_string(str.ptr, -1),
196-
);
197-
str.free();
191+
setScript(script: Script): void {
192+
exports.hb_buffer_set_script(this.ptr, script.value);
198193
}
199194

200195
/**

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from "./font-funcs";
99
export * from "./buffer";
1010
export * from "./feature";
1111
export * from "./language";
12+
export * from "./script";
1213
export * from "./shape";
1314

1415
init(await createHarfBuzz());

0 commit comments

Comments
 (0)