You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2017/06/12 16:02:16 UTC
svn commit: r1798485 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
Author: tilman
Date: Mon Jun 12 16:02:16 2017
New Revision: 1798485
URL: http://svn.apache.org/viewvc?rev=1798485&view=rev
Log:
PDFBOX-3828: generate appearance stream for multiselect listboxes, correct vertical size/position of highlighted part, don't have at least one element highlighted
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java?rev=1798485&r1=1798484&r2=1798485&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java Mon Jun 12 16:02:16 2017
@@ -21,6 +21,7 @@ import java.awt.geom.Point2D;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -606,39 +607,39 @@ class AppearanceGeneratorHelper
List<String> values = ((PDListBox) field).getValue();
List<String> options = ((PDListBox) field).getOptionsExportValues();
- // TODO: support highlighting multiple items if multiselect is set
-
- int selectedIndex = 0;
-
if (!values.isEmpty() && !options.isEmpty())
{
- if (!indexEntries.isEmpty())
- {
- selectedIndex = indexEntries.get(0);
- }
- else
+ if (indexEntries.isEmpty())
{
- selectedIndex = options.indexOf(values.get(0));
+ // create indexEntries from options
+ indexEntries = new ArrayList<Integer>();
+ for (String v : values)
+ {
+ indexEntries.add(options.indexOf(v));
+ }
}
}
-
+
// The first entry which shall be presented might be adjusted by the optional TI key
// If this entry is present the first entry to be displayed is the keys value otherwise
// display starts with the first entry in Opt.
int topIndex = ((PDListBox) field).getTopIndex();
- float highlightBoxHeight = font.getBoundingBox().getHeight() * fontSize / FONTSCALE - 2f;
-
+ float highlightBoxHeight = font.getBoundingBox().getHeight() * fontSize / FONTSCALE;
+
// the padding area
PDRectangle paddingEdge = applyPadding(appearanceStream.getBBox(), 1);
-
- contents.setNonStrokingColor(HIGHLIGHT_COLOR[0],HIGHLIGHT_COLOR[1],HIGHLIGHT_COLOR[2]);
-
- contents.addRect(paddingEdge.getLowerLeftX(),
- paddingEdge.getUpperRightY() - highlightBoxHeight * (selectedIndex - topIndex + 1),
- paddingEdge.getWidth(),
- highlightBoxHeight);
- contents.fill();
+
+ for (int selectedIndex : indexEntries)
+ {
+ contents.setNonStrokingColor(HIGHLIGHT_COLOR[0], HIGHLIGHT_COLOR[1], HIGHLIGHT_COLOR[2]);
+
+ contents.addRect(paddingEdge.getLowerLeftX(),
+ paddingEdge.getUpperRightY() - highlightBoxHeight * (selectedIndex - topIndex + 1) + 2,
+ paddingEdge.getWidth(),
+ highlightBoxHeight);
+ contents.fill();
+ }
contents.setNonStrokingColor(0);
}