@@ -606,4 +606,74 @@ class FontInfo {
606606 }
607607}
608608
609- export { CssFontInfo , FontInfo , SystemFontInfo } ;
609+ class FontPathInfo {
610+ static write ( path ) {
611+ let lengthEstimate = 0 ;
612+ const commands = [ ] ;
613+ for ( const cmd of path ) {
614+ const code = cmd . charCodeAt ( 0 ) ;
615+ const args = cmd . length > 1 ? cmd . slice ( 1 ) . split ( " " ) : null ;
616+ lengthEstimate += 2 + ( args ? args . length * 8 : 0 ) ;
617+ commands . push ( { code, args } ) ;
618+ }
619+
620+ const buffer = new ArrayBuffer ( 4 + lengthEstimate ) ;
621+ const view = new DataView ( buffer ) ;
622+ let offset = 0 ;
623+
624+ view . setUint32 ( offset , commands . length ) ;
625+ offset += 4 ;
626+ for ( const { code, args } of commands ) {
627+ view . setUint8 ( offset , code ) ;
628+ offset += 1 ;
629+ view . setUint8 ( offset , args ? args . length : 0 ) ;
630+ offset += 1 ;
631+ if ( args ) {
632+ for ( const arg of args ) {
633+ view . setFloat64 ( offset , parseFloat ( arg ) , true ) ;
634+ offset += 8 ;
635+ }
636+ }
637+ }
638+
639+ assert ( offset === buffer . byteLength , "FontPathInfo.write: Buffer overflow" ) ;
640+ return buffer ;
641+ }
642+
643+ #buffer;
644+
645+ #view;
646+
647+ constructor ( buffer ) {
648+ this . #buffer = buffer ;
649+ this . #view = new DataView ( this . #buffer) ;
650+ }
651+
652+ getSVG ( ) {
653+ const length = this . #view. getUint32 ( 0 ) ;
654+ const cmds = [ ] ;
655+ let offset = 4 ;
656+ for ( let i = 0 ; i < length ; i ++ ) {
657+ const code = String . fromCharCode ( this . #view. getUint8 ( offset ) ) ;
658+ offset += 1 ;
659+ const numArgs = this . #view. getUint8 ( offset ) ;
660+ offset += 1 ;
661+ let args = null ;
662+ if ( numArgs > 0 ) {
663+ args = [ ] ;
664+ for ( let j = 0 ; j < numArgs ; j ++ ) {
665+ args . push ( this . #view. getFloat64 ( offset , true ) ) ;
666+ offset += 8 ;
667+ }
668+ }
669+ cmds . push ( code + ( args ? args . join ( " " ) : "" ) ) ;
670+ }
671+ assert (
672+ offset === this . #buffer. byteLength ,
673+ "FontPathInfo.toString: Buffer overflow"
674+ ) ;
675+ return cmds . join ( "" ) ;
676+ }
677+ }
678+
679+ export { CssFontInfo , FontInfo , FontPathInfo , SystemFontInfo } ;
0 commit comments