Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ public boolean isRadiosInUnison()
return getCOSObject().getFlag(COSName.FF, FLAG_RADIOS_IN_UNISON);
}

/**
* From the PDF Spec <br>
* If set, exactly one radio button shall be selected at all times; clicking the currently
* selected button has no effect. If clear, clicking the selected button deselects it,
* leaving no button selected. This flag is meaningful only if the radio buttons are
* mutually exclusive, i.e. {@link #isRadiosInUnison()} is false.
*
* @param noToggleToOff The new flag for noToggleToOff.
*/
public void setNoToggleToOff(boolean noToggleToOff)
{
getCOSObject().setFlag(COSName.FF, FLAG_NO_TOGGLE_TO_OFF, noToggleToOff);
}

/**
*
* @return true if the flag is set preventing a radio button from being toggled to off.
*/
public boolean isNoToggleToOff()
{
return getCOSObject().getFlag(COSName.FF, FLAG_NO_TOGGLE_TO_OFF);
}

/**
* This will get the selected index.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,34 @@ void testRadioButtonPDModel() throws IOException
}
}

/**
* Test getting/setting the NoToggleToOff flag (PDF spec Ff bit 15).
*
* @throws IOException If there is an error creating the field.
*/
@Test
void testNoToggleToOff() throws IOException
{
try (PDDocument doc = new PDDocument())
{
PDAcroForm form = new PDAcroForm(doc);
PDRadioButton radioButton = new PDRadioButton(form);

// default shall be false/unset
assertFalse(radioButton.isNoToggleToOff());

radioButton.setNoToggleToOff(true);
assertTrue(radioButton.isNoToggleToOff());
// spec bit 15 -> mask 1 << 14
assertEquals(1 << 14,
radioButton.getCOSObject().getInt(COSName.FF) & (1 << 14));

radioButton.setNoToggleToOff(false);
assertFalse(radioButton.isNoToggleToOff());
assertEquals(0, radioButton.getCOSObject().getInt(COSName.FF) & (1 << 14));
}
}

/**
* PDFBOX-3656 Radio button field with FLAG_RADIOS_IN_UNISON false
*
Expand Down