List of usage examples for com.itextpdf.text Font getColor
public BaseColor getColor()
From source file:com.vectorprint.report.itext.style.stylers.Shadow.java
License:Open Source License
@Override public void draw(Rectangle rect, String genericTag) throws VectorPrintException { if (genericTag == null) { if (log.isLoggable(Level.FINE)) { log.fine("not drawing shadow because genericTag is null (no data for shadow)"); }/*from w ww . ja v a 2 s .c o m*/ return; } DelayedData delayed = getDelayed(genericTag); PdfContentByte canvas = getPreparedCanvas(); try { com.itextpdf.text.Font f = delayed.getChunk().getFont(); if (f.getBaseFont() == null) { throw new VectorPrintRuntimeException( "font " + f.getFamilyname() + " does not have a basefont, check your fontloading"); } /* * print as much of the text as fits in the width of the rectangle */ String toPrint = delayed.getStringData(); int i = toPrint.length() + 1; do { toPrint = toPrint.substring(0, --i); } while (ItextHelper.getTextWidth(toPrint, f.getBaseFont(), f.getSize()) > rect.getWidth() + 1); if (i < delayed.getStringData().length()) { String nextPart = delayed.getStringData().substring(i).replaceFirst(" *", ""); if (log.isLoggable(Level.FINE)) { log.fine(String.format("event %s, printed shadow %s of %s, left %s for next event", genericTag, toPrint, delayed.getData(), nextPart)); } delayed.setData(nextPart); } canvas.setFontAndSize(f.getBaseFont(), f.getSize()); canvas.setColorFill((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor())); canvas.setColorStroke((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor())); canvas.beginText(); HashMap<String, Object> attributes = delayed.getChunk().getAttributes(); if (attributes != null && attributes.containsKey(Chunk.SKEW)) { float[] skew = (float[]) attributes.get(Chunk.SKEW); canvas.setTextMatrix(1, skew[0], skew[1], 1, rect.getLeft() + calculateShift(getShiftx(), f), rect.getBottom() - calculateShift(getShifty(), f)); } else { canvas.setTextMatrix(1, 0, 0, 1, rect.getLeft() + calculateShift(getShiftx(), f), rect.getBottom() - calculateShift(getShifty(), f)); } canvas.setTextRise(delayed.getChunk().getTextRise()); canvas.showText(toPrint); canvas.endText(); } catch (Exception ex) { resetCanvas(canvas); throw new VectorPrintException(ex); } resetCanvas(canvas); }
From source file:com.vectorprint.report.itext.style.stylers.Underline.java
License:Open Source License
@Override public void draw(Rectangle rect, String genericTag) throws VectorPrintException { if (genericTag == null) { if (log.isLoggable(Level.FINE)) { log.fine("not drawing underline because genericTag is null (no data for underline)"); }/*from w w w . j a v a 2s . com*/ return; } DelayedData delayed = getDelayed(genericTag); PdfContentByte canvas = getPreparedCanvas(); try { com.itextpdf.text.Font f = delayed.getChunk().getFont(); canvas.setColorStroke((getColor() == null) ? f.getColor() : itextHelper.fromColor(getColor())); canvas.setLineWidth(getLineWidth()); if (delayed.getChunk().getTextRise() != 0) { canvas.transform(AffineTransform.getTranslateInstance(0, delayed.getChunk().getTextRise())); } HashMap<String, Object> attributes = delayed.getChunk().getAttributes(); if (attributes != null && attributes.containsKey(Chunk.SKEW)) { log.warning("lines under skewed text may not be at the correct position"); } canvas.moveTo(rect.getLeft(), rect.getBottom()); canvas.lineTo(rect.getLeft() + rect.getWidth(), rect.getBottom()); canvas.stroke(); } catch (Exception ex) { resetCanvas(canvas); throw new VectorPrintException(ex); } resetCanvas(canvas); }