New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

harfbuzzjs

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

harfbuzzjs - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

4

examples/hbjs.example.js

@@ -27,2 +27,4 @@ function example(hb, fontBlob, text) {

var unicodes = face.collectUnicodes()
buffer.destroy();

@@ -32,3 +34,3 @@ font.destroy();

blob.destroy();
return { shape: result, glyphs: glyphs };
return { shape: result, glyphs: glyphs, unicodes: unicodes };
}

@@ -35,0 +37,0 @@

type Pointer = number;
const HB_MEMORY_MODE_WRITABLE: number = 2;
const HB_SET_VALUE_INVALID: Pointer = -1;

@@ -23,2 +24,12 @@ class HarfBuzzExports {

readonly hb_font_destroy: (ptr: Pointer) => void
readonly hb_face_collect_unicodes: (facePtr: Pointer, setPtr: Pointer) => void
readonly hb_set_create: () => Pointer
readonly hb_set_destroy: (setPtr: Pointer) => void
readonly hb_set_get_population: (setPtr: Pointer) => number
readonly hb_set_next_many: (
setPtr: Pointer,
greaterThanUnicodePtr: Pointer,
outputU32ArrayPtr: Pointer,
size: number,
) => number
readonly hb_buffer_create: () => Pointer

@@ -48,2 +59,7 @@ readonly hb_buffer_add_utf8: (bufferPtr: Pointer, stringPtr: Pointer, stringLength: number, itemOffset: number, itemLength: number) => void

this.hb_face_destroy = exports.hb_face_destroy;
this.hb_face_collect_unicodes = exports.hb_face_collect_unicodes;
this.hb_set_create = exports.hb_set_create;
this.hb_set_destroy = exports.hb_set_destroy;
this.hb_set_get_population = exports.hb_set_get_population;
this.hb_set_next_many = exports.hb_set_next_many;
this.hb_font_create = exports.hb_font_create;

@@ -97,2 +113,24 @@ this.hb_font_set_scale = exports.hb_font_set_scale;

function typedArrayFromSet<T extends 'u8' | 'u32' | 'i32'>(setPtr: Pointer, arrayType: T) {
const heap = hb[`heap${arrayType}`];
const bytesPerElment = heap.BYTES_PER_ELEMENT;
const setCount = hb.hb_set_get_population(setPtr);
const arrayPtr = hb.malloc(
setCount * bytesPerElment,
);
const arrayOffset = arrayPtr / bytesPerElment;
const array = heap.subarray(
arrayOffset,
arrayOffset + setCount,
) as typeof hb[`heap${T}`];
heap.set(array, arrayOffset);
hb.hb_set_next_many(
setPtr,
HB_SET_VALUE_INVALID,
arrayPtr,
setCount,
);
return array;
}
export class HarfBuzzFace {

@@ -109,2 +147,10 @@ readonly ptr: Pointer;

collectUnicodes() {
const unicodeSetPtr = hb.hb_set_create();
hb.hb_face_collect_unicodes(this.ptr, unicodeSetPtr);
const result = typedArrayFromSet(unicodeSetPtr, 'u32');
hb.hb_set_destroy(unicodeSetPtr);
return result;
}
destroy() {

@@ -111,0 +157,0 @@ hb.hb_face_destroy(this.ptr);

@@ -12,2 +12,3 @@ function hbjs(instance) {

var HB_MEMORY_MODE_WRITABLE = 2;
var HB_SET_VALUE_INVALID = -1;

@@ -59,2 +60,38 @@ function hb_tag(s) {

/**
* Return the typed array of HarfBuzz set contents.
* @template {typeof Uint8Array | typeof Uint32Array | typeof Int32Array | typeof Float32Array} T
* @param {number} setPtr Pointer of set
* @param {T} arrayClass Typed array class
* @returns {InstanceType<T>} Typed array instance
*/
function typedArrayFromSet(setPtr, arrayClass) {
let heap = heapu8;
if (arrayClass === Uint32Array) {
heap = heapu32;
} else if (arrayClass === Int32Array) {
heap = heapi32;
} else if (arrayClass === Float32Array) {
heap = heapf32;
}
const bytesPerElment = arrayClass.BYTES_PER_ELEMENT;
const setCount = exports.hb_set_get_population(setPtr);
const arrayPtr = exports.malloc(
setCount * bytesPerElment,
);
const arrayOffset = arrayPtr / bytesPerElment;
const array = heap.subarray(
arrayOffset,
arrayOffset + setCount,
);
heap.set(array, arrayOffset);
exports.hb_set_next_many(
setPtr,
HB_SET_VALUE_INVALID,
arrayPtr,
setCount,
);
return array;
}
/**
* Create an object representing a Harfbuzz face.

@@ -104,2 +141,12 @@ * @param {object} blob An object returned from `createBlob`.

/**
* Return unicodes the face supports
*/
collectUnicodes: function() {
var unicodeSetPtr = exports.hb_set_create();
exports.hb_face_collect_unicodes(ptr, unicodeSetPtr);
var result = typedArrayFromSet(unicodeSetPtr, Uint32Array);
exports.hb_set_destroy(ptr);
return result;
},
/**
* Free the object.

@@ -106,0 +153,0 @@ */

{
"name": "harfbuzzjs",
"version": "0.3.0",
"version": "0.3.1",
"description": "Minimal version of HarfBuzz for JavaScript use",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc