import { IQuestion , QuestionCheckboxModel } from 'survey-core' ; import { IRect , ISize , DocController , IPoint } from '../doc_controller' ; import { IPdfBrick , PdfBrick } from './pdf_brick' ; import { TextBrick } from './pdf_text' ; import { SurveyHelper } from '../helper_survey' ; export class CheckItemBrick extends PdfBrick { private static readonly FONT_SIZE_SCALE : number = 0.7 ; private static readonly CHECKMARK_READONLY_SYMBOL : string = '3' ; private static readonly CHECKMARK_READONLY_FONT : string = 'zapfdingbats' ; public static readonly CHECKMARK_READONLY_FONT_SIZE_SCALE : number = 1.0 - Math . E / 10.0 ; protected question : QuestionCheckboxModel ; public constructor ( question , controller , rect , protected fieldName , protected readonly , protected checked ) { super ( question , controller , rect ) ; this . question = < QuestionCheckboxModel > question ; this . textColor = this . formBorderColor ; } public async renderInteractive ( ) { if ( this . readonly && SurveyHelper . getReadonlyRenderAs ( this . question , this . controller ) !== 'acroform' ) { return await this . renderReadOnly ( ) ; } const checkBox = new ( < any > this . controller . doc . AcroFormCheckBox ) ( ) ; const formScale = SurveyHelper . formScale ( this . controller , this ) ; checkBox . maxFontSize = this . height * formScale * CheckItemBrick . FONT_SIZE_SCALE ; checkBox . caption = CheckItemBrick . CHECKMARK_READONLY_SYMBOL ; checkBox . textAlign = 'center' ; checkBox . fieldName = this . fieldName ; checkBox . readOnly = this . readonly ; checkBox . color = this . formBorderColor ; checkBox . value = this . checked ? 'On' : false ; checkBox . AS = this . checked ? '/On' : '/Off' ; checkBox . Rect = SurveyHelper . createAcroformRect ( SurveyHelper . scaleRect ( this , formScale ) ) ; this . controller . doc . addField ( checkBox ) ; SurveyHelper . renderFlatBorders ( this . controller , this ) ; } public async renderReadOnly ( ) { SurveyHelper . renderFlatBorders ( this . controller , this ) ; if ( this . checked ) { const checkmarkPoint = SurveyHelper . createPoint ( this , true , true ) ; const oldFontName = this . controller . fontName ; this . controller . fontName = CheckItemBrick . CHECKMARK_READONLY_FONT ; const oldFontSize = this . controller . fontSize ; this . controller . fontSize = oldFontSize * CheckItemBrick . CHECKMARK_READONLY_FONT_SIZE_SCALE ; const checkmarkSize = this . controller . measureText ( CheckItemBrick . CHECKMARK_READONLY_SYMBOL ) ; checkmarkPoint . xLeft += this . width / 2.0 - checkmarkSize . width / 2.0 ; checkmarkPoint . yTop += this . height / 2.0 - checkmarkSize . height / 2.0 ; const checkmarkFlat = await SurveyHelper . createTextFlat ( checkmarkPoint , this . question , this . controller , CheckItemBrick . CHECKMARK_READONLY_SYMBOL , TextBrick ) ; ( < any > checkmarkFlat . unfold ( ) [ 0 ] ) . textColor = this . textColor ; this . controller . fontSize = oldFontSize ; await checkmarkFlat . render ( ) ; this . controller . fontName = oldFontName ; } } }