ByteArrayOutputStream output = new ByteArrayOutputStream();
// BJL 9/25/2004 Must prepend existing stream
// because it might have operators to draw things like
// rectangles and such
ContentStreamWriter writer = new ContentStreamWriter(output);
writer.writeTokens(tokens);
output.write(" /Tx BMC\n".getBytes("ISO-8859-1"));
insertGeneratedListboxAppearance(fieldWidget, output, pdFont, tokens, appearanceStream);
output.write(" EMC".getBytes("ISO-8859-1"));
writeToStream(output.toByteArray(), appearanceStream);
}
else
{
if (tokens != null)
{
if (daTokens != null)
{
int bmcIndex = tokens.indexOf(PDFOperator.getOperator("BMC"));
int emcIndex = tokens.indexOf(PDFOperator.getOperator("EMC"));
if (bmcIndex != -1 && emcIndex != -1 && emcIndex == bmcIndex + 1)
{
// if the EMC immediately follows the BMC index then should
// insert the daTokens inbetween the two markers.
tokens.addAll(emcIndex, daTokens);
}
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
ContentStreamWriter writer = new ContentStreamWriter(output);
float fontSize = calculateListboxFontSize(pdFont, appearanceStream.getBoundingBox(), tokens, daTokens);
boolean foundString = false;
int setFontIndex = tokens.indexOf(PDFOperator.getOperator("Tf"));
tokens.set(setFontIndex - 1, new COSFloat(fontSize));
int bmcIndex = tokens.indexOf(PDFOperator.getOperator("BMC"));
/*
* Get the contentArea.
*
* There might be an inner box defined which defines the area where the text is printed. This typically
* looks like ... q 1 1 98 70 re W ...
*/
{
int beginTextIndex = tokens.indexOf(PDFOperator.getOperator("BT"));
if (beginTextIndex != -1)
{
ListIterator innerTokens = tokens.listIterator(bmcIndex);
while (innerTokens.hasNext())
{
if (innerTokens.next() == PDFOperator.getOperator("re")
&& innerTokens.next() == PDFOperator.getOperator("W"))
{
COSArray array = new COSArray();
array.add((COSNumber) tokens.get(innerTokens.previousIndex() - 5));
array.add((COSNumber) tokens.get(innerTokens.previousIndex() - 4));
array.add((COSNumber) tokens.get(innerTokens.previousIndex() - 3));
array.add((COSNumber) tokens.get(innerTokens.previousIndex() - 2));
paddingEdge = new PDRectangle(array);
// as the re operator is using start and width/height adjust the generated
// dimensions
paddingEdge.setUpperRightX(paddingEdge.getLowerLeftX() + paddingEdge.getUpperRightX());
paddingEdge.setUpperRightY(paddingEdge.getLowerLeftY() + paddingEdge.getUpperRightY());
contentArea = applyPadding(paddingEdge, paddingEdge.getLowerLeftX()
- appearanceStream.getBoundingBox().getLowerLeftX());
break;
}
}
}
}
int emcIndex = tokens.indexOf(PDFOperator.getOperator("EMC"));
if (bmcIndex != -1)
{
writer.writeTokens(tokens, 0, bmcIndex + 1);
}
else
{
writer.writeTokens(tokens);
}
output.write("\n".getBytes("ISO-8859-1"));
insertGeneratedListboxAppearance(fieldWidget, output, pdFont, tokens, appearanceStream);
if (emcIndex != -1)
{
writer.writeTokens(tokens, emcIndex, tokens.size());
}
writeToStream(output.toByteArray(), appearanceStream);
}
else