import PDFDict from 'src/core/objects/PDFDict' ; import PDFName from 'src/core/objects/PDFName' ; import PDFRef from 'src/core/objects/PDFRef' ; import PDFString from 'src/core/objects/PDFString' ; import PDFHexString from 'src/core/objects/PDFHexString' ; import PDFContext from 'src/core/PDFContext' ; import BorderStyle from 'src/core/annotation/BorderStyle' ; import PDFAnnotation from 'src/core/annotation/PDFAnnotation' ; import AppearanceCharacteristics from 'src/core/annotation/AppearanceCharacteristics' ; class PDFWidgetAnnotation extends PDFAnnotation { static fromDict = ( dict ) : PDFWidgetAnnotation => new PDFWidgetAnnotation ( dict ) ; static create = ( context , parent ) => { const dict = context . obj ( { Type : 'Annot' , Subtype : 'Widget' , Rect : [ 0 , 0 , 0 , 0 ] , Parent : parent , } ) ; return new PDFWidgetAnnotation ( dict ) ; } ; MK ( ) { const MK = this . dict . lookup ( PDFName . of ( 'MK' ) ) ; if ( MK instanceof PDFDict ) return MK ; return undefined ; } BS ( ) { const BS = this . dict . lookup ( PDFName . of ( 'BS' ) ) ; if ( BS instanceof PDFDict ) return BS ; return undefined ; } DA ( ) { const da = this . dict . lookup ( PDFName . of ( 'DA' ) ) ; if ( da instanceof PDFString || da instanceof PDFHexString ) return da ; return undefined ; } P ( ) { const P = this . dict . get ( PDFName . of ( 'P' ) ) ; if ( P instanceof PDFRef ) return P ; return undefined ; } setP ( page ) { this . dict . set ( PDFName . of ( 'P' ) , page ) ; } setDefaultAppearance ( appearance ) { this . dict . set ( PDFName . of ( 'DA' ) , PDFString . of ( appearance ) ) ; } getDefaultAppearance ( ) { const DA = this . DA ( ) ; if ( DA instanceof PDFHexString ) { return DA . decodeText ( ) ; } return DA ?. asString ( ) ; } getAppearanceCharacteristics ( ) { const MK = this . MK ( ) ; if ( MK ) return AppearanceCharacteristics . fromDict ( MK ) ; return undefined ; } getOrCreateAppearanceCharacteristics ( ) { const MK = this . MK ( ) ; if ( MK ) return AppearanceCharacteristics . fromDict ( MK ) ; const ac = AppearanceCharacteristics . fromDict ( this . dict . context . obj ( { } ) ) ; this . dict . set ( PDFName . of ( 'MK' ) , ac . dict ) ; return ac ; } getBorderStyle ( ) { const BS = this . BS ( ) ; if ( BS ) return BorderStyle . fromDict ( BS ) ; return undefined ; } getOrCreateBorderStyle ( ) { const BS = this . BS ( ) ; if ( BS ) return BorderStyle . fromDict ( BS ) ; const bs = BorderStyle . fromDict ( this . dict . context . obj ( { } ) ) ; this . dict . set ( PDFName . of ( 'BS' ) , bs . dict ) ; return bs ; } getOnValue ( ) { const normal = this . getAppearances ( ) ?. normal ; if ( normal instanceof PDFDict ) { const keys = normal . keys ( ) ; for ( let idx = 0 , len = keys . length ; idx < len ; idx ++ ) { const key = keys [ idx ] ; if ( key !== PDFName . of ( 'Off' ) ) return key ; } } return undefined ; } } export default PDFWidgetAnnotation ;