Skip to content

Commit

Permalink
Fixes issue #177
Browse files Browse the repository at this point in the history
  • Loading branch information
JorjMcKie committed Jun 14, 2018
1 parent 75c7a6a commit fd8c27b
Show file tree
Hide file tree
Showing 11 changed files with 512 additions and 197 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# PyMuPDF 1.13.9 [![Build Status](https://travis-ci.org/rk700/PyMuPDF.svg?branch=master)](https://travis-ci.org/rk700/PyMuPDF)
# PyMuPDF 1.13.10 [![Build Status](https://travis-ci.org/rk700/PyMuPDF.svg?branch=master)](https://travis-ci.org/rk700/PyMuPDF)

![logo](https://github.com/rk700/PyMuPDF/blob/master/demo/pymupdf.jpg)

Release date: June 7, 2018
Release date: June 14, 2018

# Authors
* [Ruikai Liu](mailto:[email protected])
* [Jorj X. McKie](mailto:[email protected])

# Introduction

This is **version 1.13.9 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.13.0](http://mupdf.com/) - "a lightweight PDF and XPS viewer".
This is **version 1.13.10 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.13.0](http://mupdf.com/) - "a lightweight PDF and XPS viewer".

MuPDF can access files in PDF, XPS, OpenXPS, CBZ, EPUB and FB2 (e-books) formats, and it is known for its top performance and high rendering quality.

Expand Down
219 changes: 153 additions & 66 deletions fitz/fitz.i

Large diffs are not rendered by default.

131 changes: 115 additions & 16 deletions fitz/fitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,70 @@ class _object:


VersionFitz = "1.13.0"
VersionBind = "1.13.9"
VersionDate = "2018-06-09 15:14:41"
version = (VersionBind, VersionFitz, "20180609151441")
VersionBind = "1.13.10"
VersionDate = "2018-06-14 07:13:02"
version = (VersionBind, VersionFitz, "20180614071302")


#------------------------------------------------------------------------------
# Class describing a PDF form field ("widget")
#------------------------------------------------------------------------------
class Widget():
def __init__(self):
self.border_color = None # annot value
self.border_style = None # annot value
self.border_width = 0 # annot value
self.list_ismultiselect = False # list- / comboboxes
self.list_values = None # list- / comboboxes
self.field_name = None # field name
self.field_value = None # supports all field types
self.fill_color = None
self.pb_caption = None # pushbutton text
self.rect = None # annot value
self.text_color = None # text fields only
self.text_maxlen = 0 # text fields only
self.text_type = 0 # text fields only
self.field_type = -1 # valid range 0 through 6
self.field_type_text = None
if str is not bytes:
unicode = str
self._str_types = (str, unicode) if str is bytes else (str)

def _validate(self):
checker = (self._check0, self._check1, self._check2, self._check3,
self._check4, self._check5)
valid_types = tuple(range(6))
if self.field_type not in valid_types:
raise NotImplementedError("unsupported widget type")
if type(self.rect) is not Rect:
raise ValueError("invalid rect")
if not self.field_name:
raise ValueError("field name missing")
checker[self.type](self)

def _check0(self):
if any([self.text_color, self.text_maxlen, self.text_type,
self.list_ismultiselect, self.list_values]):
raise ValueError("invalid value(s) for PushButton")
if type(self.pb_caption) not in self._str_types:
raise ValueError("caption must be a string")

def _check1(self):
return

def _check2(self):
return

def _check3(self):
if len(self.field_value) > self.text_maxlen:
raise ValueError("length of text exceeds maxlwn")
return

def _check4(self):
return

def _check5(self):
return


#------------------------------------------------------------------------------
Expand Down Expand Up @@ -272,13 +333,13 @@ def getPDFstr(x):

return "(" + r + ")"

#===============================================================================
#------------------------------------------------------------------------------
# Return a PDF string suitable for the TJ operator enclosed in "[]" brackets.
# The input string is converted to either 2 or 4 hex digits per character.
# If no glyphs are supplied, then a simple font is assumed and each character
# taken directly.
# Otherwise a char's glyph is taken and 4 hex digits per char are put out.
#===============================================================================
#------------------------------------------------------------------------------
def getTJstr(text, glyphs):
if text.startswith("[<") and text.endswith(">]"): # already done
return text
Expand Down Expand Up @@ -479,7 +540,6 @@ def ConversionTrailer(i):

return r


class Document(_object):
"""open() - new empty PDF
open('type', stream) - from bytes/bytearray
Expand Down Expand Up @@ -1178,7 +1238,7 @@ def getSVGimage(self, matrix=None):


def addLineAnnot(self, p1, p2):
"""addLineAnnot(self, p1, p2) -> Annot"""
"""Add a Line annotation between Points p1, p2"""
CheckParent(self)

val = _fitz.Page_addLineAnnot(self, p1, p2)
Expand All @@ -1193,7 +1253,7 @@ def addLineAnnot(self, p1, p2):


def addTextAnnot(self, point, text):
"""addTextAnnot(self, point, text) -> Annot"""
"""Add a 'sticky note' at Point pos"""
CheckParent(self)

val = _fitz.Page_addTextAnnot(self, point, text)
Expand All @@ -1208,7 +1268,7 @@ def addTextAnnot(self, point, text):


def addStrikeoutAnnot(self, rect):
"""addStrikeoutAnnot(self, rect) -> Annot"""
"""Strike out content in a Rect"""
CheckParent(self)

val = _fitz.Page_addStrikeoutAnnot(self, rect)
Expand All @@ -1223,7 +1283,7 @@ def addStrikeoutAnnot(self, rect):


def addUnderlineAnnot(self, rect):
"""addUnderlineAnnot(self, rect) -> Annot"""
"""Underline content in a Rect"""
CheckParent(self)

val = _fitz.Page_addUnderlineAnnot(self, rect)
Expand All @@ -1238,7 +1298,7 @@ def addUnderlineAnnot(self, rect):


def addHighlightAnnot(self, rect):
"""addHighlightAnnot(self, rect) -> Annot"""
"""Highlight content in a Rect"""
CheckParent(self)

val = _fitz.Page_addHighlightAnnot(self, rect)
Expand All @@ -1253,7 +1313,7 @@ def addHighlightAnnot(self, rect):


def addRectAnnot(self, rect):
"""addRectAnnot(self, rect) -> Annot"""
"""Add a rectangle annotation"""
CheckParent(self)

val = _fitz.Page_addRectAnnot(self, rect)
Expand All @@ -1268,7 +1328,7 @@ def addRectAnnot(self, rect):


def addCircleAnnot(self, rect):
"""addCircleAnnot(self, rect) -> Annot"""
"""Add a circle annotation"""
CheckParent(self)

val = _fitz.Page_addCircleAnnot(self, rect)
Expand All @@ -1283,7 +1343,7 @@ def addCircleAnnot(self, rect):


def addPolylineAnnot(self, points):
"""addPolylineAnnot(self, points) -> Annot"""
"""Add a polyline annotation for a sequence of Points"""
CheckParent(self)

val = _fitz.Page_addPolylineAnnot(self, points)
Expand All @@ -1298,7 +1358,7 @@ def addPolylineAnnot(self, points):


def addPolygonAnnot(self, points):
"""addPolygonAnnot(self, points) -> Annot"""
"""Add a polygon annotation for a sequence of Points"""
CheckParent(self)

val = _fitz.Page_addPolygonAnnot(self, points)
Expand All @@ -1313,7 +1373,7 @@ def addPolygonAnnot(self, points):


def addFreetextAnnot(self, pos, text, fontsize=11, color=None):
"""addFreetextAnnot(self, pos, text, fontsize=11, color=None) -> Annot"""
"""Add a FreeText annotation at Point pos"""
CheckParent(self)

val = _fitz.Page_addFreetextAnnot(self, pos, text, fontsize, color)
Expand Down Expand Up @@ -2443,6 +2503,19 @@ def __repr__(self):
ANNOT_LE_ROpenArrow = _fitz.ANNOT_LE_ROpenArrow
ANNOT_LE_RClosedArrow = _fitz.ANNOT_LE_RClosedArrow
ANNOT_LE_Slash = _fitz.ANNOT_LE_Slash
ANNOT_WG_NOT_WIDGET = _fitz.ANNOT_WG_NOT_WIDGET
ANNOT_WG_PUSHBUTTON = _fitz.ANNOT_WG_PUSHBUTTON
ANNOT_WG_CHECKBOX = _fitz.ANNOT_WG_CHECKBOX
ANNOT_WG_RADIOBUTTON = _fitz.ANNOT_WG_RADIOBUTTON
ANNOT_WG_TEXT = _fitz.ANNOT_WG_TEXT
ANNOT_WG_LISTBOX = _fitz.ANNOT_WG_LISTBOX
ANNOT_WG_COMBOBOX = _fitz.ANNOT_WG_COMBOBOX
ANNOT_WG_SIGNATURE = _fitz.ANNOT_WG_SIGNATURE
ANNOT_WG_TEXT_UNRESTRAINED = _fitz.ANNOT_WG_TEXT_UNRESTRAINED
ANNOT_WG_TEXT_NUMBER = _fitz.ANNOT_WG_TEXT_NUMBER
ANNOT_WG_TEXT_SPECIAL = _fitz.ANNOT_WG_TEXT_SPECIAL
ANNOT_WG_TEXT_DATE = _fitz.ANNOT_WG_TEXT_DATE
ANNOT_WG_TEXT_TIME = _fitz.ANNOT_WG_TEXT_TIME
class Annot(_object):
"""Proxy of C fz_annot_s struct."""

Expand Down Expand Up @@ -2690,6 +2763,32 @@ def getPixmap(self, matrix=None, colorspace=None, alpha=0):
return _fitz.Annot_getPixmap(self, matrix, colorspace, alpha)


def _getWidget(self, Widget):
"""_getWidget(self, Widget) -> PyObject *"""
CheckParent(self)

return _fitz.Annot__getWidget(self, Widget)


@property
def widget(self):
annot_type = self.type[0]
if annot_type != ANNOT_WIDGET:
return None
w = Widget()
w.field_type = self.widget_type[0]
w.field_type_text = self.widget_type[1]
w.field_value = self.widget_value
w.field_name = self.widget_name
w.list_values = self.widget_choices
w.rect = self.rect
self._getWidget(w)
return w

def updateWidget(self, widget):
widget._validate()
self._updateWidget(widget)

def _erase(self):
try:
self.parent._forget_annot(self)
Expand Down
Loading

0 comments on commit fd8c27b

Please sign in to comment.