import { Document } from "../../Document" ; import { Helper , RTFJSError } from "../../Helper" ; import { GlobalState } from "../Containers" ; import { DestinationBase } from "./DestinationBase" ; export class FonttblDestinationSub extends DestinationBase { public index : number ; public fontname : string ; public altfontname : string ; public family : string ; public pitch : number ; public bias : number ; public charset : number ; private _fonttbl : FonttblDestination ; constructor ( fonttbl ) { super ( "fonttbl:sub" ) ; this . _fonttbl = fonttbl ; this . index = null ; this . fontname = null ; this . altfontname = null ; this . family = null ; this . pitch = Helper . FONTPITCH . DEFAULT ; this . bias = 0 ; this . charset = null ; } public handleKeyword ( keyword , param ) { switch ( keyword ) { case "f" : this . index = param ; return true ; case "fnil" : return true ; case "froman" : case "fswiss" : case "fmodern" : case "fscript" : case "fdecor" : case "ftech" : case "fbidi" : case "flomajor" : case "fhimajor" : case "fdbmajor" : case "fbimajor" : case "flominor" : case "fhiminor" : case "fdbminor" : case "fbiminor" : this . family = keyword . slice ( 1 ) ; return true ; case "fprq" : switch ( param ) { case 0 : this . pitch = Helper . FONTPITCH . DEFAULT ; break ; case 1 : this . pitch = Helper . FONTPITCH . FIXED ; break ; case 2 : this . pitch = Helper . FONTPITCH . VARIABLE ; break ; } return true ; case "fbias" : if ( param != null ) { this . bias = param ; } return true ; case "fcharset" : if ( param != null ) { this . charset = Helper . _mapCharset ( param ) ; if ( this . charset == null ) { Helper . log ( "Unknown font charset: " + param ) ; } } return true ; case "cpg" : if ( param != null ) { this . charset = param ; } return true ; } return false ; } public appendText ( text ) { if ( this . fontname == null ) { this . fontname = text ; } else { this . fontname += text ; } } public apply ( ) { if ( this . index == null ) { throw new RTFJSError ( "No font index provided" ) ; } if ( this . fontname == null ) { throw new RTFJSError ( "No font name provided" ) ; } this . _fonttbl . addSub ( this ) ; delete this . _fonttbl ; } public setAltFontName ( name ) { this . altfontname = name ; } } export class FonttblDestination extends DestinationBase { private _fonts : FonttblDestinationSub [ ] ; private _sub : FonttblDestinationSub ; private inst : Document ; constructor ( parser , inst ) { super ( "fonttbl" ) ; this . _fonts = [ ] ; this . _sub = null ; this . inst = inst ; } public sub ( ) { return new FonttblDestinationSub ( this ) ; } public apply ( ) { Helper . log ( "[fonttbl] apply()" ) ; for ( const idx in this . _fonts ) { Helper . log ( "[fonttbl][" + idx + "] index = " + this . _fonts [ idx ] . fontname + " alternative: " + this . _fonts [ idx ] . altfontname ) ; } this . inst . _fonts = this . _fonts ; delete this . _fonts ; } public appendText ( text ) { this . _sub . appendText ( text ) ; this . _sub . apply ( ) ; } public handleKeyword ( keyword , param ) { if ( keyword === "f" ) { this . _sub = this . sub ( ) ; } this . _sub . handleKeyword ( keyword , param ) ; } public addSub ( sub ) { this . _fonts [ sub . index ] = sub ; } }