def addWidget(self, widget):
CheckParent(self)<EOL>doc = self.parent<EOL>if not doc.isPDF:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>widget._validate()<EOL>eck if PDF already has our fonts.<EOL><INDENT>none insert all of them in a new object and store the xref.<EOL><DEDENT>se only add any missing fonts.<EOL><INDENT>determine the situation, /DR object is checked.<EOL><DEDENT>xref = <NUM_LIT:0><EOL>ff = doc.FormFonts               <EOL>if not widget.text_font:         <EOL><INDENT>widget.text_font = "<STR_LIT>"<EOL><DEDENT>if not widget.text_font in ff:   <EOL><INDENT>if not doc.isFormPDF or not ff:   <EOL><INDENT>xref = doc._getNewXref()      <EOL>doc._updateObject(xref, Widget_fontobjects)<EOL><DEDENT>else:                        <EOL><INDENT>for k in Widget_fontdict.keys():<EOL><INDENT>if not k in ff:      <EOL><INDENT>doc._addFormFont(k, Widget_fontdict[k])<EOL><DEDENT><DEDENT><DEDENT>widget._adjust_font()        <EOL><DEDENT>widget._dr_xref = xref           <EOL>w create the /DA string<EOL>if   len(widget.text_color) == <NUM_LIT:3>:<EOL><INDENT>fmt = "<STR_LIT>" + widget._text_da<EOL><DEDENT>elif len(widget.text_color) == <NUM_LIT:1>:<EOL><INDENT>fmt = "<STR_LIT>" + widget._text_da<EOL><DEDENT>elif len(widget.text_color) == <NUM_LIT:4>:<EOL><INDENT>fmt = "<STR_LIT>" + widget._text_da<EOL><DEDENT>widget._text_da = fmt.format(*widget.text_color, f=widget.text_font,<EOL>s=widget.text_fontsize)<EOL>eate the widget at last<EOL>annot = self._addWidget(widget)<EOL>if annot:<EOL><INDENT>annot.thisown = True<EOL>annot.parent = weakref.proxy(self) <EOL>self._annot_refs[id(annot)] = annot<EOL><DEDENT>return annot<EOL>
Add a form field.