Skip to content

Commit 3e8317f

Browse files
committed
Bind hb_ot_layout_lookup_get_optical_bound()
1 parent a4df29e commit 3e8317f

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

config-override.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
#undef HB_NO_VAR_COMPOSITES
1212
#undef HB_NO_NAME
1313
#undef HB_NO_LAYOUT_FEATURE_PARAMS
14+
#undef HB_NO_LAYOUT_RARELY_USED
1415
#define HB_BUFFER_MESSAGE_MORE 1

harfbuzz.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ _hb_ot_layout_table_get_feature_tags
7979
_hb_ot_layout_script_get_language_tags
8080
_hb_ot_layout_language_get_feature_tags
8181
_hb_ot_layout_feature_get_lookups
82+
_hb_ot_layout_lookup_get_optical_bound
8283
_hb_ot_layout_get_glyph_class
8384
_hb_ot_layout_feature_get_name_ids
8485
_hb_ot_name_list_names

src/font.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
string_to_utf8_ptr,
77
} from "./helpers";
88
import type { FontExtents, GlyphExtents, SvgPathCommand } from "./types";
9+
import type { Direction } from "./buffer";
910
import type { Face } from "./face";
1011
import type { FontFuncs } from "./font-funcs";
1112
import type { Variation } from "./variation";
@@ -453,4 +454,25 @@ export class Font {
453454
setFuncs(fontFuncs: FontFuncs): void {
454455
exports.hb_font_set_funcs(this.ptr, fontFuncs.ptr);
455456
}
457+
458+
/**
459+
* Fetches the optical bound of a glyph positioned at the margin of text.
460+
* The direction identifies which edge of the glyph to query.
461+
* @param lookupIndex Index of the feature lookup to query.
462+
* @param direction Edge of the glyph to query.
463+
* @param glyph A glyph id.
464+
* @returns Adjustment value. Negative values mean the glyph will stick out of the margin.
465+
*/
466+
getLookupOpticalBound(
467+
lookupIndex: number,
468+
direction: Direction,
469+
glyph: number,
470+
): number {
471+
return exports.hb_ot_layout_lookup_get_optical_bound(
472+
this.ptr,
473+
lookupIndex,
474+
direction,
475+
glyph,
476+
);
477+
}
456478
}

test/index.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,23 @@ describe("Font", function () {
520520
expect(font.glyph(0x10ffff)).to.equal(font.nominalGlyph(0x10ffff));
521521
});
522522

523+
it("getLookupOpticalBound returns some value", function () {
524+
let blob = new hb.Blob(
525+
fs.readFileSync(path.join(__dirname, "fonts/noto/NotoSans-Regular.ttf")),
526+
);
527+
let face = new hb.Face(blob);
528+
let font = new hb.Font(face);
529+
const kernIndex = face.getTableFeatureTags("GPOS").indexOf("kern");
530+
const [lookupIndex] = face.getFeatureLookups("GPOS", kernIndex);
531+
const glyph = font.glyphFromName("A");
532+
const opticalBound = font.getLookupOpticalBound(
533+
lookupIndex,
534+
hb.Direction.LTR,
535+
glyph,
536+
);
537+
expect(opticalBound).to.be.a("number");
538+
});
539+
523540
it("setVariations affects advances", function () {
524541
let blob = new hb.Blob(
525542
fs.readFileSync(

0 commit comments

Comments
 (0)