import { Document } from "../Document" ; import { Helper } from "../Helper" ; import { Chp } from "../parser/Containers" ; export class RenderChp { public _chp : Chp ; constructor ( chp ) { this . _chp = chp ; } public apply ( doc , el ) { Helper . log ( "[rtf] RenderChp: " + el . textContent ) ; Helper . log ( "[rtf] RenderChp apply: " + JSON . stringify ( this . _chp ) ) ; if ( this . _chp . bold ) { el . style . fontWeight = "bold" ; } if ( this . _chp . italic ) { el . style . fontStyle = "italic" ; } if ( Object . prototype . hasOwnProperty . call ( this . _chp , "fontfamily" ) && doc . _fonts [ this . _chp . fontfamily ] ) { const fontFamily = doc . _fonts [ this . _chp . fontfamily ] . fontname . replace ( ";" , "" ) ; if ( fontFamily !== "Symbol" ) { el . style . fontFamily = fontFamily ; } } const deco = [ ] ; if ( this . _chp . underline !== Helper . UNDERLINE . NONE ) { deco . push ( "underline" ) ; } if ( this . _chp . strikethrough || this . _chp . dblstrikethrough ) { deco . push ( "line-through" ) ; } if ( deco . length > 0 ) { el . style . textDecoration = deco . join ( " " ) ; } if ( this . _chp . colorindex !== 0 ) { const color = doc . _lookupColor ( this . _chp . colorindex ) ; if ( color != null ) { el . style . color = Helper . _colorToStr ( color ) ; } } if ( this . _chp . highlightindex !== 0 ) { const color = doc . _lookupColor ( this . _chp . highlightindex ) ; if ( color != null ) { el . style . backgroundColor = Helper . _colorToStr ( color ) ; } } el . style . fontSize = Math . floor ( this . _chp . fontsize / 2 ) + "pt" ; } }