Propagate the field flags. If this widget has a "/Parent", set its field flags and that of all its /Kids widgets to the value of the current widget. Only possible for widgets existing in the PDF. Returns True or False.
(self)
| 9181 | self._checker() # any field_type specific checks |
| 9182 | |
| 9183 | def _sync_flags(self): |
| 9184 | """Propagate the field flags. |
| 9185 | |
| 9186 | If this widget has a "/Parent", set its field flags and that of all |
| 9187 | its /Kids widgets to the value of the current widget. |
| 9188 | Only possible for widgets existing in the PDF. |
| 9189 | |
| 9190 | Returns True or False. |
| 9191 | """ |
| 9192 | if not self.xref: |
| 9193 | return False # no xref: widget not in the PDF |
| 9194 | doc = self.parent.parent # the owning document |
| 9195 | assert doc |
| 9196 | pdf = _as_pdf_document(doc) |
| 9197 | # load underlying PDF object |
| 9198 | pdf_widget = mupdf.pdf_load_object(pdf, self.xref) |
| 9199 | Parent = mupdf.pdf_dict_get(pdf_widget, PDF_NAME("Parent")) |
| 9200 | if not Parent.pdf_is_dict(): |
| 9201 | return False # no /Parent: nothing to do |
| 9202 | |
| 9203 | # put the field flags value into the parent field flags: |
| 9204 | Parent.pdf_dict_put_int(PDF_NAME("Ff"), self.field_flags) |
| 9205 | |
| 9206 | # also put that value into all kids of the Parent |
| 9207 | kids = Parent.pdf_dict_get(PDF_NAME("Kids")) |
| 9208 | if not kids.pdf_is_array(): |
| 9209 | message("warning: malformed PDF, Parent has no Kids array") |
| 9210 | return False # no /Kids: should never happen! |
| 9211 | |
| 9212 | for i in range(kids.pdf_array_len()): # walk through all kids |
| 9213 | # access kid widget, and do some precautionary checks |
| 9214 | kid = kids.pdf_array_get(i) |
| 9215 | if not kid.pdf_is_dict(): |
| 9216 | continue |
| 9217 | xref = kid.pdf_to_num() # get xref of the kid |
| 9218 | if xref == self.xref: # skip self widget |
| 9219 | continue |
| 9220 | subtype = kid.pdf_dict_get(PDF_NAME("Subtype")) |
| 9221 | if not subtype.pdf_to_name() == "Widget": |
| 9222 | continue |
| 9223 | # put the field flags value into the kid field flags: |
| 9224 | kid.pdf_dict_put_int(PDF_NAME("Ff"), self.field_flags) |
| 9225 | |
| 9226 | return True # all done |
| 9227 | |
| 9228 | def button_states(self): |
| 9229 | """Return the on/off state names for button widgets. |
no test coverage detected