@@ -102,9 +102,70 @@ class _object:
102102
103103
104104VersionFitz = "1.13.0"
105- VersionBind = "1.13.9"
106- VersionDate = "2018-06-09 15:14:41"
107- version = (VersionBind , VersionFitz , "20180609151441" )
105+ VersionBind = "1.13.10"
106+ VersionDate = "2018-06-14 07:13:02"
107+ version = (VersionBind , VersionFitz , "20180614071302" )
108+
109+
110+ #------------------------------------------------------------------------------
111+ # Class describing a PDF form field ("widget")
112+ #------------------------------------------------------------------------------
113+ class Widget ():
114+ def __init__ (self ):
115+ self .border_color = None # annot value
116+ self .border_style = None # annot value
117+ self .border_width = 0 # annot value
118+ self .list_ismultiselect = False # list- / comboboxes
119+ self .list_values = None # list- / comboboxes
120+ self .field_name = None # field name
121+ self .field_value = None # supports all field types
122+ self .fill_color = None
123+ self .pb_caption = None # pushbutton text
124+ self .rect = None # annot value
125+ self .text_color = None # text fields only
126+ self .text_maxlen = 0 # text fields only
127+ self .text_type = 0 # text fields only
128+ self .field_type = - 1 # valid range 0 through 6
129+ self .field_type_text = None
130+ if str is not bytes :
131+ unicode = str
132+ self ._str_types = (str , unicode ) if str is bytes else (str )
133+
134+ def _validate (self ):
135+ checker = (self ._check0 , self ._check1 , self ._check2 , self ._check3 ,
136+ self ._check4 , self ._check5 )
137+ valid_types = tuple (range (6 ))
138+ if self .field_type not in valid_types :
139+ raise NotImplementedError ("unsupported widget type" )
140+ if type (self .rect ) is not Rect :
141+ raise ValueError ("invalid rect" )
142+ if not self .field_name :
143+ raise ValueError ("field name missing" )
144+ checker [self .type ](self )
145+
146+ def _check0 (self ):
147+ if any ([self .text_color , self .text_maxlen , self .text_type ,
148+ self .list_ismultiselect , self .list_values ]):
149+ raise ValueError ("invalid value(s) for PushButton" )
150+ if type (self .pb_caption ) not in self ._str_types :
151+ raise ValueError ("caption must be a string" )
152+
153+ def _check1 (self ):
154+ return
155+
156+ def _check2 (self ):
157+ return
158+
159+ def _check3 (self ):
160+ if len (self .field_value ) > self .text_maxlen :
161+ raise ValueError ("length of text exceeds maxlwn" )
162+ return
163+
164+ def _check4 (self ):
165+ return
166+
167+ def _check5 (self ):
168+ return
108169
109170
110171#------------------------------------------------------------------------------
@@ -272,13 +333,13 @@ def getPDFstr(x):
272333
273334 return "(" + r + ")"
274335
275- #===============================================================================
336+ #------------------------------------------------------------------------------
276337# Return a PDF string suitable for the TJ operator enclosed in "[]" brackets.
277338# The input string is converted to either 2 or 4 hex digits per character.
278339# If no glyphs are supplied, then a simple font is assumed and each character
279340# taken directly.
280341# Otherwise a char's glyph is taken and 4 hex digits per char are put out.
281- #===============================================================================
342+ #------------------------------------------------------------------------------
282343def getTJstr (text , glyphs ):
283344 if text .startswith ("[<" ) and text .endswith (">]" ): # already done
284345 return text
@@ -479,7 +540,6 @@ def ConversionTrailer(i):
479540
480541 return r
481542
482-
483543class Document (_object ):
484544 """open() - new empty PDF
485545open('type', stream) - from bytes/bytearray
@@ -1178,7 +1238,7 @@ def getSVGimage(self, matrix=None):
11781238
11791239
11801240 def addLineAnnot (self , p1 , p2 ):
1181- """addLineAnnot(self, p1, p2) -> Annot """
1241+ """Add a Line annotation between Points p1, p2"""
11821242 CheckParent (self )
11831243
11841244 val = _fitz .Page_addLineAnnot (self , p1 , p2 )
@@ -1193,7 +1253,7 @@ def addLineAnnot(self, p1, p2):
11931253
11941254
11951255 def addTextAnnot (self , point , text ):
1196- """addTextAnnot(self, point, text) -> Annot """
1256+ """Add a 'sticky note' at Point pos """
11971257 CheckParent (self )
11981258
11991259 val = _fitz .Page_addTextAnnot (self , point , text )
@@ -1208,7 +1268,7 @@ def addTextAnnot(self, point, text):
12081268
12091269
12101270 def addStrikeoutAnnot (self , rect ):
1211- """addStrikeoutAnnot(self, rect) -> Annot """
1271+ """Strike out content in a Rect """
12121272 CheckParent (self )
12131273
12141274 val = _fitz .Page_addStrikeoutAnnot (self , rect )
@@ -1223,7 +1283,7 @@ def addStrikeoutAnnot(self, rect):
12231283
12241284
12251285 def addUnderlineAnnot (self , rect ):
1226- """addUnderlineAnnot(self, rect) -> Annot """
1286+ """Underline content in a Rect """
12271287 CheckParent (self )
12281288
12291289 val = _fitz .Page_addUnderlineAnnot (self , rect )
@@ -1238,7 +1298,7 @@ def addUnderlineAnnot(self, rect):
12381298
12391299
12401300 def addHighlightAnnot (self , rect ):
1241- """addHighlightAnnot(self, rect) -> Annot """
1301+ """Highlight content in a Rect """
12421302 CheckParent (self )
12431303
12441304 val = _fitz .Page_addHighlightAnnot (self , rect )
@@ -1253,7 +1313,7 @@ def addHighlightAnnot(self, rect):
12531313
12541314
12551315 def addRectAnnot (self , rect ):
1256- """addRectAnnot(self, rect) -> Annot """
1316+ """Add a rectangle annotation """
12571317 CheckParent (self )
12581318
12591319 val = _fitz .Page_addRectAnnot (self , rect )
@@ -1268,7 +1328,7 @@ def addRectAnnot(self, rect):
12681328
12691329
12701330 def addCircleAnnot (self , rect ):
1271- """addCircleAnnot(self, rect) -> Annot """
1331+ """Add a circle annotation """
12721332 CheckParent (self )
12731333
12741334 val = _fitz .Page_addCircleAnnot (self , rect )
@@ -1283,7 +1343,7 @@ def addCircleAnnot(self, rect):
12831343
12841344
12851345 def addPolylineAnnot (self , points ):
1286- """addPolylineAnnot(self, points) -> Annot """
1346+ """Add a polyline annotation for a sequence of Points """
12871347 CheckParent (self )
12881348
12891349 val = _fitz .Page_addPolylineAnnot (self , points )
@@ -1298,7 +1358,7 @@ def addPolylineAnnot(self, points):
12981358
12991359
13001360 def addPolygonAnnot (self , points ):
1301- """addPolygonAnnot(self, points) -> Annot """
1361+ """Add a polygon annotation for a sequence of Points """
13021362 CheckParent (self )
13031363
13041364 val = _fitz .Page_addPolygonAnnot (self , points )
@@ -1313,7 +1373,7 @@ def addPolygonAnnot(self, points):
13131373
13141374
13151375 def addFreetextAnnot (self , pos , text , fontsize = 11 , color = None ):
1316- """addFreetextAnnot(self, pos, text, fontsize=11, color=None) -> Annot """
1376+ """Add a FreeText annotation at Point pos """
13171377 CheckParent (self )
13181378
13191379 val = _fitz .Page_addFreetextAnnot (self , pos , text , fontsize , color )
@@ -2443,6 +2503,19 @@ def __repr__(self):
24432503ANNOT_LE_ROpenArrow = _fitz .ANNOT_LE_ROpenArrow
24442504ANNOT_LE_RClosedArrow = _fitz .ANNOT_LE_RClosedArrow
24452505ANNOT_LE_Slash = _fitz .ANNOT_LE_Slash
2506+ ANNOT_WG_NOT_WIDGET = _fitz .ANNOT_WG_NOT_WIDGET
2507+ ANNOT_WG_PUSHBUTTON = _fitz .ANNOT_WG_PUSHBUTTON
2508+ ANNOT_WG_CHECKBOX = _fitz .ANNOT_WG_CHECKBOX
2509+ ANNOT_WG_RADIOBUTTON = _fitz .ANNOT_WG_RADIOBUTTON
2510+ ANNOT_WG_TEXT = _fitz .ANNOT_WG_TEXT
2511+ ANNOT_WG_LISTBOX = _fitz .ANNOT_WG_LISTBOX
2512+ ANNOT_WG_COMBOBOX = _fitz .ANNOT_WG_COMBOBOX
2513+ ANNOT_WG_SIGNATURE = _fitz .ANNOT_WG_SIGNATURE
2514+ ANNOT_WG_TEXT_UNRESTRAINED = _fitz .ANNOT_WG_TEXT_UNRESTRAINED
2515+ ANNOT_WG_TEXT_NUMBER = _fitz .ANNOT_WG_TEXT_NUMBER
2516+ ANNOT_WG_TEXT_SPECIAL = _fitz .ANNOT_WG_TEXT_SPECIAL
2517+ ANNOT_WG_TEXT_DATE = _fitz .ANNOT_WG_TEXT_DATE
2518+ ANNOT_WG_TEXT_TIME = _fitz .ANNOT_WG_TEXT_TIME
24462519class Annot (_object ):
24472520 """Proxy of C fz_annot_s struct."""
24482521
@@ -2690,6 +2763,32 @@ def getPixmap(self, matrix=None, colorspace=None, alpha=0):
26902763 return _fitz .Annot_getPixmap (self , matrix , colorspace , alpha )
26912764
26922765
2766+ def _getWidget (self , Widget ):
2767+ """_getWidget(self, Widget) -> PyObject *"""
2768+ CheckParent (self )
2769+
2770+ return _fitz .Annot__getWidget (self , Widget )
2771+
2772+
2773+ @property
2774+ def widget (self ):
2775+ annot_type = self .type [0 ]
2776+ if annot_type != ANNOT_WIDGET :
2777+ return None
2778+ w = Widget ()
2779+ w .field_type = self .widget_type [0 ]
2780+ w .field_type_text = self .widget_type [1 ]
2781+ w .field_value = self .widget_value
2782+ w .field_name = self .widget_name
2783+ w .list_values = self .widget_choices
2784+ w .rect = self .rect
2785+ self ._getWidget (w )
2786+ return w
2787+
2788+ def updateWidget (self , widget ):
2789+ widget ._validate ()
2790+ self ._updateWidget (widget )
2791+
26932792 def _erase (self ):
26942793 try :
26952794 self .parent ._forget_annot (self )
0 commit comments