import { IColor } from "./parser/destinations/ColortblDestinations" ; export class RTFJSError extends Error { constructor ( message ) { super ( message ) ; Object . setPrototypeOf ( this , new . target . prototype ) ; } } let isLoggingEnabled = true ; export function loggingEnabled ( enabled ) { isLoggingEnabled = enabled ; } export class Helper { public static JUSTIFICATION = { LEFT : "left" , CENTER : "center" , RIGHT : "right" , JUSTIFY : "justify" , } ; public static BREAKTYPE = { NONE : "none" , COL : "col" , EVEN : "even" , ODD : "odd" , PAGE : "page" , } ; public static PAGENUMBER = { DECIMAL : "decimal" , UROM : "urom" , LROM : "lrom" , ULTR : "ultr" , LLTR : "lltr" , } ; public static UNDERLINE = { NONE : "none" , CONTINUOUS : "continuous" , DOTTED : "dotted" , DASHED : "dashed" , DASHDOTTED : "dashdotted" , DASHDOTDOTTED : " dashdotdotted" , DOUBLE : "double" , HEAVYWAVE : "heavywave" , LONGDASHED : "longdashed" , THICK : "thick" , THICKDOTTED : "thickdotted" , THICKDASHED : "thickdashed" , THICKDASHDOTTED : "thickdashdotted" , THICKDASHDOTDOTTED : "thickdashdotdotted" , THICKLONGDASH : "thicklongdash" , DOUBLEWAVE : "doublewave" , WORD : "word" , WAVE : "wave" , } ; public static FONTPITCH = { DEFAULT : 0 , FIXED : 1 , VARIABLE : 2 , } ; public static CHARACTER_TYPE = { LOWANSI : "loch" , HIGHANSI : "hich" , DOUBLE : "dbch" , } ; public static log ( message ) { if ( isLoggingEnabled ) { console . log ( message ) ; } } public static _isalpha ( str ) { const len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { const ch = str . charCodeAt ( i ) ; if ( ! ( ( ch >= this . _A && ch <= this . _Z ) || ( ch >= this . _a && ch <= this . _z ) ) ) { return false ; } } return len > 0 ; } public static _isdigit ( str ) { const len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { const ch = str . charCodeAt ( i ) ; if ( ch < this . _0 || ch > this . _9 ) { return false ; } } return len > 0 ; } public static _parseHex ( str ) { const len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { const ch = str . charCodeAt ( i ) ; if ( ! ( ( ch >= this . _0 && ch <= this . _9 ) || ( ch >= this . _a && ch <= this . _f ) || ( ch >= this . _A && ch <= this . _F ) ) ) { return NaN ; } } if ( len > 0 ) { return parseInt ( str , 16 ) ; } return NaN ; } public static _blobToBinary ( blob ) { const view = new Uint8Array ( blob ) ; let ret = "" ; const len = view . length ; for ( let i = 0 ; i < len ; i ++ ) { ret += String . fromCharCode ( view [ i ] ) ; } return ret ; } public static _hexToBlob ( str ) { let len = str . length ; const buf = new ArrayBuffer ( Math . floor ( len -- / 2 ) ) ; const view = new Uint8Array ( buf ) ; let d = 0 ; for ( let i = 0 ; i < len ; i += 2 ) { const val = this . _parseHex ( str . substr ( i , 2 ) ) ; if ( isNaN ( val ) ) { return null ; } view [ d ++ ] = val ; } return buf ; } public static _hexToBinary ( str ) { let bin = "" ; const len = str . length - 1 ; for ( let i = 0 ; i < len ; i += 2 ) { const val = this . _parseHex ( str . substr ( i , 2 ) ) ; if ( isNaN ( val ) ) { return null ; } bin += String . fromCharCode ( val ) ; } return bin ; } public static _mapCharset ( idx ) { return this . _charsetMap [ idx . toString ( ) ] ; } public static _mapColorTheme ( name ) { return this . _colorThemeMap [ name ] ; } public static _colorToStr ( color ) { return "rgb(" + color . r + "," + color . g + "," + color . b + ")" ; } public static _twipsToPt ( twips ) { return Math . floor ( twips / 20 ) ; } public static _twipsToPx ( twips ) { return Math . floor ( twips / 20 * 96 / 72 ) ; } public static _pxToTwips ( px ) { return Math . floor ( px * 20 * 72 / 96 ) ; } private static _A = "A" . charCodeAt ( 0 ) ; private static _a = "a" . charCodeAt ( 0 ) ; private static _F = "F" . charCodeAt ( 0 ) ; private static _f = "f" . charCodeAt ( 0 ) ; private static _Z = "Z" . charCodeAt ( 0 ) ; private static _z = "z" . charCodeAt ( 0 ) ; private static _0 = "0" . charCodeAt ( 0 ) ; private static _9 = "9" . charCodeAt ( 0 ) ; private static _charsetMap : { [ key ] : number ; } = { 0 : 1252 , 2 : 42 , 77 : 10000 , 78 : 10001 , 79 : 10003 , 80 : 10008 , 81 : 10002 , 83 : 10005 , 84 : 10004 , 85 : 10006 , 86 : 10081 , 87 : 10021 , 88 : 10029 , 89 : 10007 , 128 : 932 , 129 : 949 , 130 : 1361 , 134 : 936 , 136 : 950 , 161 : 1253 , 162 : 1254 , 163 : 1258 , 177 : 1255 , 178 : 1256 , 186 : 1257 , 204 : 1251 , 222 : 874 , 238 : 1250 , 254 : 437 , 255 : 850 , } ; private static _colorThemeMap : { [ key ] : null ; } = { maindarkone : null , mainlightone : null , maindarktwo : null , mainlighttwo : null , accentone : null , accenttwo : null , accentthree : null , accentfour : null , accentfive : null , accentsix : null , hyperlink : null , followedhyperlink : null , backgroundone : null , textone : null , backgroundtwo : null , texttwo : null , } ; }