Populate a Python Widget object with the values from a PDF form field. Called by "Page.first_widget" and "Widget.next".
(annot, Widget)
| 19857 | |
| 19858 | |
| 19859 | def JM_get_widget_properties(annot, Widget): |
| 19860 | ''' |
| 19861 | Populate a Python Widget object with the values from a PDF form field. |
| 19862 | Called by "Page.first_widget" and "Widget.next". |
| 19863 | ''' |
| 19864 | #log( '{type(annot)=}') |
| 19865 | annot_obj = mupdf.pdf_annot_obj(annot.this) |
| 19866 | #log( 'Have called mupdf.pdf_annot_obj()') |
| 19867 | page = _pdf_annot_page(annot.this) |
| 19868 | pdf = page.doc() |
| 19869 | tw = annot |
| 19870 | |
| 19871 | def SETATTR(key, value): |
| 19872 | setattr(Widget, key, value) |
| 19873 | |
| 19874 | def SETATTR_DROP(mod, key, value): |
| 19875 | # Original C code for this function deletes if PyObject* is NULL. We |
| 19876 | # don't have a representation for that in Python - e.g. None is not |
| 19877 | # represented by NULL. |
| 19878 | setattr(mod, key, value) |
| 19879 | |
| 19880 | #log( '=== + mupdf.pdf_widget_type(tw)') |
| 19881 | field_type = mupdf.pdf_widget_type(tw.this) |
| 19882 | #log( '=== - mupdf.pdf_widget_type(tw)') |
| 19883 | Widget.field_type = field_type |
| 19884 | if field_type == mupdf.PDF_WIDGET_TYPE_SIGNATURE: |
| 19885 | if mupdf.pdf_signature_is_signed(pdf, annot_obj): |
| 19886 | SETATTR("is_signed", True) |
| 19887 | else: |
| 19888 | SETATTR("is_signed",False) |
| 19889 | else: |
| 19890 | SETATTR("is_signed", None) |
| 19891 | SETATTR_DROP(Widget, "border_style", JM_UnicodeFromStr(mupdf.pdf_field_border_style(annot_obj))) |
| 19892 | SETATTR_DROP(Widget, "field_type_string", JM_UnicodeFromStr(JM_field_type_text(field_type))) |
| 19893 | |
| 19894 | field_name = mupdf.pdf_load_field_name(annot_obj) |
| 19895 | SETATTR_DROP(Widget, "field_name", field_name) |
| 19896 | |
| 19897 | def pdf_dict_get_inheritable_nonempty_label(node, key): |
| 19898 | ''' |
| 19899 | This is a modified version of MuPDF's pdf_dict_get_inheritable(), with |
| 19900 | some changes: |
| 19901 | * Returns string from pdf_to_text_string() or None if not found. |
| 19902 | * Recurses to parent if current node exists but with empty string |
| 19903 | value. |
| 19904 | ''' |
| 19905 | slow = node |
| 19906 | halfbeat = 11 # Don't start moving slow pointer for a while. |
| 19907 | while 1: |
| 19908 | if not node.m_internal: |
| 19909 | return |
| 19910 | val = mupdf.pdf_dict_get(node, key) |
| 19911 | if val.m_internal: |
| 19912 | label = mupdf.pdf_to_text_string(val) |
| 19913 | if label: |
| 19914 | return label |
| 19915 | node = mupdf.pdf_dict_get(node, PDF_NAME('Parent')) |
| 19916 | if node.m_internal == slow.m_internal: |
no test coverage detected
searching dependent graphs…