Update the PDF form field with the properties from a Python Widget object. Called by "Page.add_widget" and "Annot.update_widget".
(annot, Widget)
| 21665 | |
| 21666 | |
| 21667 | def JM_set_widget_properties(annot, Widget): |
| 21668 | ''' |
| 21669 | Update the PDF form field with the properties from a Python Widget object. |
| 21670 | Called by "Page.add_widget" and "Annot.update_widget". |
| 21671 | ''' |
| 21672 | if isinstance( annot, Annot): |
| 21673 | annot = annot.this |
| 21674 | assert isinstance( annot, mupdf.PdfAnnot), f'{type(annot)=} {type=}' |
| 21675 | page = _pdf_annot_page(annot) |
| 21676 | assert page.m_internal, 'Annot is not bound to a page' |
| 21677 | annot_obj = mupdf.pdf_annot_obj(annot) |
| 21678 | pdf = page.doc() |
| 21679 | def GETATTR(name): |
| 21680 | return getattr(Widget, name, None) |
| 21681 | |
| 21682 | value = GETATTR("field_type") |
| 21683 | field_type = value |
| 21684 | |
| 21685 | # rectangle -------------------------------------------------------------- |
| 21686 | value = GETATTR("rect") |
| 21687 | rect = JM_rect_from_py(value) |
| 21688 | rot_mat = JM_rotate_page_matrix(page) |
| 21689 | rect = mupdf.fz_transform_rect(rect, rot_mat) |
| 21690 | mupdf.pdf_set_annot_rect(annot, rect) |
| 21691 | |
| 21692 | # fill color ------------------------------------------------------------- |
| 21693 | value = GETATTR("fill_color") |
| 21694 | if value and PySequence_Check(value): |
| 21695 | n = len(value) |
| 21696 | fill_col = mupdf.pdf_new_array(pdf, n) |
| 21697 | col = 0 |
| 21698 | for i in range(n): |
| 21699 | col = value[i] |
| 21700 | mupdf.pdf_array_push_real(fill_col, col) |
| 21701 | mupdf.pdf_field_set_fill_color(annot_obj, fill_col) |
| 21702 | |
| 21703 | # dashes ----------------------------------------------------------------- |
| 21704 | value = GETATTR("border_dashes") |
| 21705 | if value and PySequence_Check(value): |
| 21706 | n = len(value) |
| 21707 | dashes = mupdf.pdf_new_array(pdf, n) |
| 21708 | for i in range(n): |
| 21709 | mupdf.pdf_array_push_int(dashes, value[i]) |
| 21710 | mupdf.pdf_dict_putl(annot_obj, dashes, PDF_NAME('BS'), PDF_NAME('D')) |
| 21711 | |
| 21712 | # border color ----------------------------------------------------------- |
| 21713 | value = GETATTR("border_color") |
| 21714 | if value and PySequence_Check(value): |
| 21715 | n = len(value) |
| 21716 | border_col = mupdf.pdf_new_array(pdf, n) |
| 21717 | col = 0 |
| 21718 | for i in range(n): |
| 21719 | col = value[i] |
| 21720 | mupdf.pdf_array_push_real(border_col, col) |
| 21721 | mupdf.pdf_dict_putl(annot_obj, border_col, PDF_NAME('MK'), PDF_NAME('BC')) |
| 21722 | |
| 21723 | # entry ignored - may be used later |
| 21724 | # |
no test coverage detected
searching dependent graphs…