List of usage examples for com.itextpdf.text Chunk getAttributes
public HashMap<String, Object> getAttributes()
Chunk
. From source file:com.vectorprint.report.itext.EventHelper.java
License:Open Source License
/** * Calls the super and {@link Advanced#draw(com.itextpdf.text.Rectangle, java.lang.String) } for each Advanced styler * registered. Adds a debugging link for images when in debug mode. * * @param writer//from w w w . j av a 2 s.c o m * @param document * @param rect * @param genericTag * @see #addDelayedStyler(java.lang.String, java.util.Collection, com.itextpdf.text.Chunk) * @see Advanced#addDelayedData(java.lang.String, com.itextpdf.text.Chunk) * @see VectorPrintDocument */ @Override public final void onGenericTag(PdfWriter writer, Document document, final Rectangle rect, String genericTag) { // if (log.isLoggable(Level.FINE)) { // Collection<Advanced> av = doOnGenericTag.get(genericTag); // String data = null; // if (av!=null) { // for (Advanced a : av) { // data += a.getDelayed(genericTag).getDataPart(); // break; // } // } // System.out.println("wrapped: " + carriageReturns.toString() + ", " + genericTag + " " + data + " " + rect.toString() + ", x=" + rect.getLeft()); // } if (doOnGenericTag.get(genericTag) != null && !genericTag.startsWith(VectorPrintDocument.DRAWNEAR) && !genericTag.startsWith(VectorPrintDocument.DRAWSHADOW)) { int i = -1; for (Advanced a : doOnGenericTag.get(genericTag)) { ++i; if (genericTag.startsWith(DefaultElementProducer.ADV) && Integer .parseInt(genericTag.replace(DefaultElementProducer.ADV, "")) > maxTagForGenericTagOnPage) { continue; } try { if (a.shouldDraw(a.getDelayed(genericTag).getData())) { if (a instanceof DebugStyler && imageChunks.containsKey(genericTag)) { Chunk wrapper = imageChunks.get(genericTag); Object[] atts = (Object[]) wrapper.getAttributes().get(Chunk.IMAGE); Rectangle shifted = new Rectangle(rect); shifted.setLeft(shifted.getLeft() + (Float) atts[1]); shifted.setRight(shifted.getRight() + (Float) atts[1]); shifted.setTop(shifted.getTop() + (Float) atts[2]); shifted.setBottom(shifted.getBottom() + (Float) atts[2]); a.draw(shifted, genericTag); } else if (!genericTag.startsWith(VectorPrintDocument.IMG_DEBUG)) { a.draw(rect, genericTag); } } } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } } } // images if (genericTag.startsWith(VectorPrintDocument.IMG_DEBUG) && getSettings().getBooleanProperty(false, DEBUG)) { // only now we can define a goto action, we know the position of the image if (rectangles.containsKey(genericTag)) { Rectangle rectangle = imageRectFromChunk(genericTag, rect); DebugHelper.debugAnnotation(rectangle, genericTag.replaceFirst(VectorPrintDocument.IMG_DEBUG, ""), writer); } else { DebugHelper.debugAnnotation(rect, genericTag.replaceFirst(VectorPrintDocument.IMG_DEBUG, ""), writer); } } if (genericTag.startsWith(VectorPrintDocument.DRAWNEAR)) { Rectangle rectangle = imageRectFromChunk(genericTag, rect); com.vectorprint.report.itext.style.stylers.Image image = (com.vectorprint.report.itext.style.stylers.Image) doOnGenericTag .get(genericTag).iterator().next(); short i = -1; for (Advanced a : doOnGenericTag.get(genericTag)) { try { if (++i > 0 && a.shouldDraw(a.getDelayed(genericTag).getData())) { if (getSettings().getBooleanProperty(false, DEBUG)) { DebugHelper.styleLink(writer.getDirectContent(), a.getStyleClass(), "draw near", rectangle.getLeft(), rectangle.getTop(), getSettings(), elementProducer); } a.draw(rectangle, genericTag); } } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } } } if (genericTag.startsWith(VectorPrintDocument.DRAWSHADOW)) { // we know the position of the image Rectangle r = imageRectFromChunk(genericTag, rect); com.vectorprint.report.itext.style.stylers.Image image = (com.vectorprint.report.itext.style.stylers.Image) doOnGenericTag .get(genericTag).iterator().next(); try { image.drawShadow(r.getLeft(), r.getBottom(), r.getWidth(), r.getHeight(), genericTag.replaceFirst(VectorPrintDocument.DRAWSHADOW, "")); } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } } }