List of usage examples for com.itextpdf.text Element type
public int type();
From source file:com.vectorprint.report.itext.VectorPrintDocument.java
License:Open Source License
/** * If there is a hook for the element it will be processed, For all hooks except {@link INTENTION stylelater} * {@link StyleHelper#delayedStyle(com.itextpdf.text.Chunk, java.lang.String, java.util.Collection, com.vectorprint.report.itext.EventHelper, com.itextpdf.text.Image) * }//from ww w .j av a 2 s .co m * (variant without image when there is none) will be called. When element is a Section the pagenumber and the * Section are remembered, see {@link #getToc() }. * * @param element * @return * @throws DocumentException * @see EventHelper#onGenericTag(com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document, * com.itextpdf.text.Rectangle, java.lang.String) */ @Override public boolean add(Element element) throws DocumentException { boolean rv = false; AddElementHook hook = null; if (element instanceof Image) { Image image = (Image) element; // see if we should style after adding hook = find(element, AddElementHook.INTENTION.PRINTIMAGESHADOW); /* we want to draw a shadow, write a chunk to get the position of the image later */ if (hook != null) { String gt = DRAWSHADOW + hook.styleClass; Chunk chunk = positionChunk(); styleHelper.delayedStyle(chunk, gt, StyleHelper.toCollection((Advanced) hook.bs), eventHelper, image); super.add(chunk); } hook = find(element, AddElementHook.INTENTION.DEBUGIMAGE); if (hook != null && ((EnhancedMap) factory.getSettings()).getBooleanProperty(false, ReportConstants.DEBUG)) { rv = tracePosition(image, hook, IMG_DEBUG, true); } hook = find(element, AddElementHook.INTENTION.DRAWNEARIMAGE); if (hook != null) { if (rv) { tracePosition(image, hook, DRAWNEAR, false); } else { rv = tracePosition(image, hook, DRAWNEAR, true); } } if (!rv) { rv = super.add(element); } } else if (element instanceof Section) { rv = super.add(element); if (!toc.containsKey(writer.getCurrentPageNumber())) { toc.put(writer.getCurrentPageNumber(), new ArrayList<>(3)); } toc.get(writer.getCurrentPageNumber()).add((Section) element); } else { rv = super.add(element); } // see if we should style after adding Iterator<AddElementHook> it = hooks.iterator(); while (it.hasNext() && (hook = it.next()) != null) { if (hook.intention == AddElementHook.INTENTION.STYLELATER && hook.e.type() == element.type() && hook.e.equals(element) && hook.bs.canStyle(element) && hook.bs.shouldStyle(null, element)) { it.remove(); try { hook.bs.style(element, null); } catch (VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } } } return rv; }
From source file:com.vectorprint.report.itext.VectorPrintDocument.java
License:Open Source License
private AddElementHook find(Element element, AddElementHook.INTENTION intention) { AddElementHook hook = null;/*from w w w .j a va 2 s. co m*/ Iterator<AddElementHook> it = hooks.iterator(); while (it.hasNext() && (hook = it.next()) != null) { if (hook.intention == intention && hook.e.type() == element.type() && hook.e.equals(element)) { it.remove(); if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "found {0}", new Object[] { hook }); } return hook; } } return null; }