Skip to content

Commit

Permalink
Fixing #2350
Browse files Browse the repository at this point in the history
Previously, we ignored widget field flags changes for all button types (in an effort to fight potential user errors). This however prevented "legal" flags modifications for these widget types.

This fix now simply relies on correct valus provided by the user and puts the provided field flags value to the PDF.

Also make sure we are keeping the right widget type. When setting field flags, we must ensure to re-check the field type and set those flag bits that PDF uses to differentiate between the three button types and the two choice type.

Also removed unnecessary use of fitz.PDF_WIDGET_TYPE_COMBOBOX flag in
tests/test_widgets.py:test_combobox().
  • Loading branch information
JorjMcKie authored and julian-smith-artifex-com committed Apr 18, 2023
1 parent a4cfd1d commit 5877f59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
22 changes: 11 additions & 11 deletions fitz/helper-fields.i
Original file line number Diff line number Diff line change
Expand Up @@ -730,18 +730,18 @@ void JM_set_widget_properties(fz_context *ctx, pdf_annot *annot, PyObject *Widge
pdf_dict_del(ctx, annot_obj, PDF_NAME(RC)); /* not supported by MuPDF */

// field flags ------------------------------------------------------------
int field_flags = 0, Ff = 0;
if (field_type != PDF_WIDGET_TYPE_CHECKBOX &&
field_type != PDF_WIDGET_TYPE_BUTTON &&
field_type != PDF_WIDGET_TYPE_RADIOBUTTON) {
value = GETATTR("field_flags");
field_flags = (int) PyInt_AsLong(value);
if (!PyErr_Occurred()) {
Ff = pdf_field_flags(ctx, annot_obj);
Ff |= field_flags;
value = GETATTR("field_flags");
int field_flags = (int) PyInt_AsLong(value);
Py_XDECREF(value);
if (!PyErr_Occurred()) {
if (field_type == PDF_WIDGET_TYPE_COMBOBOX) {
field_flags |= PDF_CH_FIELD_IS_COMBO;
} else if (field_type == PDF_WIDGET_TYPE_RADIOBUTTON) {
field_flags |= PDF_BTN_FIELD_IS_RADIO;
} else if (field_type == PDF_WIDGET_TYPE_BUTTON) {
field_flags |= PDF_BTN_FIELD_IS_PUSHBUTTON;
}
Py_XDECREF(value);
pdf_dict_put_int(ctx, annot_obj, PDF_NAME(Ff), Ff);
pdf_dict_put_int(ctx, annot_obj, PDF_NAME(Ff), field_flags);
}

// button caption ---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def test_combobox():
widget.field_flags = (
fitz.PDF_CH_FIELD_IS_COMMIT_ON_SEL_CHANGE
| fitz.PDF_CH_FIELD_IS_EDIT
| fitz.PDF_WIDGET_TYPE_COMBOBOX
)
widget.fill_color = gold
widget.choice_values = (
Expand Down

0 comments on commit 5877f59

Please sign in to comment.