Skip to content

Commit

Permalink
add getData to HbBlob
Browse files Browse the repository at this point in the history
  • Loading branch information
chearon committed Jun 22, 2024
1 parent 78332b3 commit cbaf113
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/text-font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ export class FaceMatch {
}

getExclusiveLanguage() {
const os2 = this.face.reference_table('OS/2');
const os2 = this.face.referenceTable('OS/2');
if (os2) {
const words = new Uint16Array(os2);
const buffer = os2.getData();
const words = new Uint16Array(buffer);
const [version] = words;

if (version === 1 || version === 2 || version === 3 || version == 4 || version === 5) {
const codePageRange1 = os2[78 /* bytes */ / 2];
const codePageRange1 = buffer[78 /* bytes */ / 2];
const bits17to20 = codePageRange1 & 0x1E0000;
if ((codePageRange1 & (1 << 17)) === bits17to20) return 'ja';
if ((codePageRange1 & (1 << 18)) === bits17to20) return 'zh-cn';
Expand Down
18 changes: 10 additions & 8 deletions src/text-harfbuzz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ export class HbBlob {
countFaces(): number {
return exports.hb_face_count(this.ptr);
}

getData() {
const length = exports.hb_blob_get_length(this.ptr);
const ptr = exports.hb_blob_get_data(this.ptr, null);
return heapu8.subarray(ptr, ptr + length);
}
}

export function createBlob(blob: Uint8Array) {
Expand Down Expand Up @@ -189,14 +195,6 @@ export class HbFace {
this.upem = exports.hb_face_get_upem(ptr);
}

reference_table(table: string) {
const blob = exports.hb_face_reference_table(this.ptr, hb_tag(table));
const length = exports.hb_blob_get_length(blob);
if (!length) return;
const blobptr = exports.hb_blob_get_data(blob, null);
return heapu8.subarray(blobptr, blobptr + length);
}

getAxisInfos() {
const axis = exports.malloc(64 * 32);
const c = exports.malloc(4);
Expand Down Expand Up @@ -245,6 +243,10 @@ export class HbFace {
return exports.hb_ot_layout_has_positioning(this.ptr);
}

referenceTable(tag: string) {
return new HbBlob(exports.hb_face_reference_table(this.ptr, hb_tag(tag)));
}

getScripts() {
const lengthPtr = bytes4;
const maxLength = 8;
Expand Down

0 comments on commit cbaf113

Please sign in to comment.