)
{
Document document = field.getDocument();
Widget widget = field.getWidgets().get(0);
Appearance appearance = widget.getAppearance();
if(appearance == null)
{widget.setAppearance(appearance = new Appearance(document));}
{
PdfDictionary widgetDataObject = widget.getBaseDataObject();
widgetDataObject.put(
PdfName.DA,
new PdfString("/Helv " + getFontSize() + " Tf 0 0 0 rg")
);
widgetDataObject.put(
PdfName.MK,
new PdfDictionary(
new PdfName[]
{
PdfName.BG,
PdfName.BC
},
new PdfDirectObject[]
{
new PdfArray(new PdfDirectObject[]{new PdfReal(.9),new PdfReal(.9),new PdfReal(.9)}),
new PdfArray(new PdfDirectObject[]{new PdfInteger(0),new PdfInteger(0),new PdfInteger(0)})
}
)
);
}
FormXObject normalAppearanceState = new FormXObject(document);
{
Rectangle2D widgetBox = widget.getBox();
Dimension2D size = new Dimension(widgetBox.getWidth(),widgetBox.getHeight());
normalAppearanceState.setSize(size);
PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);
composer.beginLocalState();
float lineWidth = 1;
composer.setLineWidth(lineWidth);
composer.setFillColor(getBackColor());
composer.setStrokeColor(getForeColor());
Rectangle2D frame = new Rectangle2D.Double(lineWidth/2,lineWidth/2,size.getWidth()-lineWidth,size.getHeight()-lineWidth);
composer.drawRectangle(frame,5);
composer.fillStroke();
composer.end();
composer.beginLocalState();
composer.drawRectangle(frame,5);
composer.clip(); // Ensures that the visible content is clipped within the rounded frame.
composer.beginMarkedContent(PdfName.Tx);
composer.setFont(
new StandardType1Font(
document,
StandardType1Font.FamilyEnum.Helvetica,
false,
false
),
getFontSize()
);
double y = 3;
for(ChoiceItem item : field.getItems())
{
composer.showText(
item.getText(),
new Point2D.Double(0,y)
);
y += getFontSize() * 1.175;
if(y > size.getHeight())
break;
}
composer.end();
composer.end();
composer.flush();
}
appearance.getNormal().put(null,normalAppearanceState);
}