File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,10 +27,12 @@ _hb_face_create
2727_hb_face_collect_unicodes
2828_hb_face_destroy
2929_hb_face_get_upem
30+ _hb_face_reference
3031_hb_face_reference_table
3132_hb_font_create
3233_hb_font_destroy
3334_hb_font_reference
35+ _hb_font_get_face
3436_hb_font_create_sub_font
3537_hb_font_glyph_to_string
3638_hb_font_set_scale
Original file line number Diff line number Diff line change @@ -39,8 +39,15 @@ export class Face {
3939 * @param index The index of the font in the blob. (0 for most files,
4040 * or a 0-indexed font number if the `blob` came from a font collection file.)
4141 */
42- constructor ( blob : Blob , index : number = 0 ) {
43- this . ptr = exports . hb_face_create ( blob . ptr , index ) ;
42+ constructor ( blob : Blob , index ?: number ) ;
43+ /** @internal Wrap an existing face pointer. */
44+ constructor ( existingPtr : number ) ;
45+ constructor ( arg : Blob | number , index : number = 0 ) {
46+ if ( typeof arg === "number" ) {
47+ this . ptr = exports . hb_face_reference ( arg ) ;
48+ } else {
49+ this . ptr = exports . hb_face_create ( arg . ptr , index ) ;
50+ }
4451 this . upem = exports . hb_face_get_upem ( this . ptr ) ;
4552 track ( this , exports . hb_face_destroy ) ;
4653 }
Original file line number Diff line number Diff line change 77} from "./helpers" ;
88import type { FontExtents , GlyphExtents , SvgPathCommand } from "./types" ;
99import type { Direction } from "./buffer" ;
10- import type { Face } from "./face" ;
10+ import { Face } from "./face" ;
1111import type { FontFuncs } from "./font-funcs" ;
1212import type { Variation } from "./variation" ;
1313
@@ -29,6 +29,7 @@ interface DrawPtrs {
2929 */
3030export class Font {
3131 readonly ptr : number ;
32+ private _face ?: Face ;
3233 private drawPtrs : DrawPtrs = {
3334 pathBuffer : "" ,
3435 } ;
@@ -44,6 +45,7 @@ export class Font {
4445 this . ptr = exports . hb_font_reference ( arg ) ;
4546 } else {
4647 this . ptr = exports . hb_font_create ( arg . ptr ) ;
48+ this . _face = arg ;
4749 }
4850 const ptr = this . ptr ;
4951 const drawState = this . drawPtrs ;
@@ -60,6 +62,14 @@ export class Font {
6062 } ) ;
6163 }
6264
65+ /** The {@link Face} associated with this font. */
66+ get face ( ) : Face {
67+ if ( ! this . _face ) {
68+ this . _face = new Face ( exports . hb_font_get_face ( this . ptr ) ) ;
69+ }
70+ return this . _face ;
71+ }
72+
6373 /**
6474 * Create a sub font that inherits this font's properties.
6575 * @returns A new Font object representing the sub font.
Original file line number Diff line number Diff line change @@ -363,6 +363,16 @@ describe("Face", function () {
363363} ) ;
364364
365365describe ( "Font" , function ( ) {
366+ it ( "exposes its face" , function ( ) {
367+ let blob = new hb . Blob (
368+ fs . readFileSync ( path . join ( __dirname , "fonts/noto/NotoSans-Regular.ttf" ) ) ,
369+ ) ;
370+ let face = new hb . Face ( blob ) ;
371+ let font = new hb . Font ( face ) ;
372+ expect ( font . face ) . to . equal ( face ) ;
373+ expect ( font . subFont ( ) . face . ptr ) . to . equal ( face . ptr ) ;
374+ } ) ;
375+
366376 it ( "subFont creates a sub font" , function ( ) {
367377 let blob = new hb . Blob (
368378 fs . readFileSync ( path . join ( __dirname , "fonts/noto/NotoSans-Regular.ttf" ) ) ,
You can’t perform that action at this time.
0 commit comments