List of usage examples for com.itextpdf.text Font getSize
public float getSize()
From source file:adams.core.io.PdfFont.java
License:Open Source License
/** * Returns the font as string.//ww w .j ava2s .c om * * @return the string representation */ @Override public String toString() { String result; Font font; font = toFont(); result = font.getFamilyname(); result += "" + SEPARATOR + Utils.flatten(getFontFaces(font), ","); result += "" + SEPARATOR + new Float(font.getSize()).intValue(); return result; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private Phrase processHtmlCodes(String name, Font baseFont, Font symbol) { final Font italicFont = new Font(baseFont); italicFont.setStyle(Font.FontStyle.ITALIC.getValue()); final Font normalFont = new Font(baseFont); Font usedFont = normalFont;/*from www.ja v a 2 s . com*/ final Phrase phrase = new Phrase(); if (!StringUtils.isEmpty(name)) { for (String[] alphabet : GreekAlphabet.getAlphabet()) { name = name.replaceAll(alphabet[0], DELIMETER + alphabet[0] + DELIMETER); } name = name.replaceAll("<sup>|<SUP>", DELIMETER + "<sup>"); name = name.replaceAll("</sup>|</SUP>", DELIMETER); name = name.replaceAll("<i>|<I>|<em>|<EM>", DELIMETER + "<i>"); name = name.replaceAll("</i>|</I>|</em>|</EM>", DELIMETER + "</i>"); final String[] tokens = name.split(DELIMETER); for (String token : tokens) { String text = token; if (text.startsWith("<i>")) { usedFont = italicFont; text = text.substring(3); } else if (text.startsWith("</i>")) { usedFont = normalFont; text = text.substring(4); } usedFont.setSize(baseFont.getSize()); if (text.startsWith("&")) { final char replacement = GreekAlphabet.getReplacement(text); if (!Character.isWhitespace(replacement)) { phrase.add(SpecialSymbol.get(replacement, symbol)); } else { phrase.add(new Chunk(text, usedFont)); } } else if (text.startsWith("<sup>")) { final Font superScriptFont = new Font(usedFont); superScriptFont.setSize(baseFont.getSize() - 1.5f); final Chunk superScript = new Chunk(text.substring(5), superScriptFont); superScript.setTextRise(4f); phrase.add(superScript); } else { phrase.add(new Chunk(text, usedFont)); } } } return phrase; }
From source file:com.chaschev.itext.ColumnTextBuilder.java
License:Apache License
private static float calcApproximateFontHeight(Font font) { final BaseFont baseFont = font.getBaseFont(); return baseFont.getFontDescriptor(BaseFont.ASCENT, font.getSize()) - baseFont.getFontDescriptor(BaseFont.DESCENT, font.getSize()); }
From source file:com.vectorprint.report.itext.style.stylers.Shadow.java
License:Open Source License
protected float calculateShift(float shift, com.itextpdf.text.Font f) { return shift * (f.getSize() / 10); }
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 . jav a2 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:de.knurt.heinzelmann.util.itext.TextBlock.java
License:Creative Commons License
public TextBlock(Font font, String content) { this(font.getSize(), font.getBaseFont(), font, content); }
From source file:es.baudlord.pcpartpicker.model.Build.java
License:Open Source License
public PdfPTable createPdfPTable(Font font) throws DocumentException { List<PdfPCell> cellList = new ArrayList<>(); cellList.addAll(Arrays.asList(new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Name"), font)), new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.UnitPrice"), font)), new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Amount"), font)), new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("column.Price"), font)))); for (Product.Category c : Product.Category.values()) { ArrayList<Part> parts = getParts(c); if (parts.isEmpty()) continue; parts.forEach(product -> cellList .addAll(Arrays.asList(new PdfPCell(new Phrase(product.getDescription(), font)), new PdfPCell(new Phrase(Coin.formatNet(product.getPrice()), font)), new PdfPCell(new Phrase(String.valueOf(product.getAmount()), font)), new PdfPCell(new Phrase(Coin.formatNet(product.getTotalPrice()), font))))); }//from w w w. j ava2s . c o m PdfPCell line = new PdfPCell(new Phrase("")); line.setColspan(4); cellList.add(line); double totalPrice = this.getTotalPrice(); font.setSize(font.getSize() + 2); PdfPCell total = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.price").toUpperCase(), font)); total.setColspan(3); cellList.addAll(Arrays.asList(total, new PdfPCell(new Phrase(Coin.formatNet(totalPrice), font)))); PdfPCell totalTax = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.tax").toUpperCase(), font)); totalTax.setColspan(3); cellList.addAll(Arrays.asList(totalTax, new PdfPCell(new Phrase(Coin.formatTax(totalPrice), font)))); PdfPCell totalPvp = new PdfPCell(new Phrase(GENERAL_BUNDLE.getString("total.pvp").toUpperCase(), font)); totalPvp.setColspan(3); cellList.addAll(Arrays.asList(totalPvp, new PdfPCell(new Phrase(Coin.formatGross(totalPrice), font)))); PdfPTable table = new PdfPTable(4); table.setWidths(new int[] { 50, 10, 5, 10 }); table.setHeaderRows(1); for (int i = 0; i < table.getNumberOfColumns(); i++) { cellList.get(i).setBorder(Rectangle.BOTTOM); table.addCell(cellList.get(i)); } for (int i = table.getNumberOfColumns(); i < cellList.size() - 6; i++) { cellList.get(i).setBorder(0); table.addCell(cellList.get(i)); } for (int i = cellList.size() - 6; i < cellList.size() - 4; i++) { cellList.get(i).setBorder(Rectangle.TOP); table.addCell(cellList.get(i)); } for (int i = cellList.size() - 4; i < cellList.size(); i++) { cellList.get(i).setBorder(0); table.addCell(cellList.get(i)); } return table; }
From source file:net.digitstar.vanadio.AbstractReportPdf.java
License:Apache License
private float computeHeight(Font f) { return f.getSize() + 4.0f; }
From source file:org.javad.pdf.PageTitle.java
License:Apache License
@Override public OutputBounds generate(PdfContentByte content) { int maxWidth = 0; content.setColorStroke(BaseColor.BLACK); Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.Title); content.setFontAndSize(f.getBaseFont(), f.getSize()); float top = getY(); content.setHorizontalScaling(110.0f); if (getTitle() != null && !getTitle().isEmpty()) { maxWidth = (int) f.getBaseFont().getWidthPoint(getTitle().toUpperCase(), f.getSize()); PdfUtil.renderConstrainedText(content, getTitle().toUpperCase(), f, getX(), top, (int) (maxWidth * 1.1)); }/*w w w .jav a 2 s . c o m*/ if (getSubTitle() != null && !getSubTitle().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Subtitle); top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); maxWidth = Math.max(maxWidth, (int) subFont.getBaseFont().getWidthPoint(getSubTitle().toUpperCase(), subFont.getSize())); PdfUtil.renderConstrainedText(content, getSubTitle().toUpperCase(), subFont, getX(), top, (int) (maxWidth * 1.10)); } content.setHorizontalScaling(100.0f); if (getClassifier() != null && !getClassifier().isEmpty()) { Font classFont = FontRegistry.getInstance().getFont(PdfFontDefinition.Classifier); content.setFontAndSize(classFont.getBaseFont(), classFont.getSize()); top -= classFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); float width = classFont.getBaseFont().getWidthPoint(getClassifier(), classFont.getCalculatedSize()) + 4; maxWidth = Math.max(maxWidth, (int) width + (2 * DASH_LENGTH)); content.setLineWidth(0.8f); float lineTop = top + ((int) classFont.getSize() / 2 - 1); content.moveTo(getX() - (width / 2) - DASH_LENGTH, lineTop); content.lineTo(getX() - (width / 2), lineTop); content.moveTo(getX() + (width / 2), lineTop); content.lineTo(getX() + (width / 2) + DASH_LENGTH, lineTop); content.stroke(); PdfUtil.renderConstrainedText(content, getClassifier(), classFont, getX(), top, (int) (maxWidth * 1.10)); } OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top); return rect; }
From source file:org.javad.pdf.TitlePageContent.java
License:Apache License
@Override public OutputBounds generate(PdfContentByte content) { if (isSkipped()) { return new OutputBounds(getX(), getY(), 0, 0); }//from w w w .j a va 2 s . c o m int maxWidth = 0; float top = getY() - PdfUtil.convertFromMillimeters( (configuration.getHeight() - configuration.getMarginBottom() - configuration.getMarginTop()) / 2); if (getImage() != null) { try { com.itextpdf.text.Image img = determineScaledImage(getImage()); if (img != null) { content.addImage(img); top = img.getAbsoluteY() - PdfUtil.convertFromMillimeters(25.0f); } } catch (Exception e) { logger.log(Level.FINER, "An error occured scaling the image. ", e); } } content.setColorStroke(BaseColor.BLACK); Font f = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumTitle); content.setFontAndSize(f.getBaseFont(), f.getSize()); content.setHorizontalScaling(110.0f); if (getTitle() != null && !getTitle().isEmpty()) { maxWidth = (int) f.getBaseFont().getWidthPoint(getTitle().toUpperCase(), f.getSize()); PdfUtil.renderConstrainedText(content, getTitle().toUpperCase(), f, getX(), top, maxWidth); } if (getSubTitle() != null && !getSubTitle().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumSubtitle); top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(3.0f); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); maxWidth = Math.max(maxWidth, (int) content.getEffectiveStringWidth(getSubTitle().toUpperCase(), false)); PdfUtil.renderConstrainedText(content, getSubTitle().toUpperCase(), subFont, getX(), top, maxWidth); } if (getDescription() != null && !getDescription().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumDescription); top -= PdfUtil.convertFromMillimeters(15.0f); float width = PdfUtil.convertFromMillimeters( (configuration.getWidth() - configuration.getMarginLeft() - configuration.getMarginRight()) / 2); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); top += PdfUtil.renderConstrainedText(content, getDescription(), subFont, width + PdfUtil.convertFromMillimeters(configuration.getMarginLeft()), top, (int) (width * 0.7f)); } if (!getItems().isEmpty()) { Font subFont = FontRegistry.getInstance().getFont(PdfFontDefinition.AlbumContents); top -= subFont.getCalculatedSize() + PdfUtil.convertFromMillimeters(6.0f); content.setFontAndSize(subFont.getBaseFont(), subFont.getSize()); for (String s : getItems()) { maxWidth = Math.max(maxWidth, (int) subFont.getBaseFont().getWidthPoint(s, subFont.getSize())); PdfUtil.renderConstrainedText(content, s, subFont, getX(), top, maxWidth); top -= PdfUtil.convertFromMillimeters(3.0f); } } content.setHorizontalScaling(100.0f); OutputBounds rect = new OutputBounds(getX() - maxWidth / 2, getY(), maxWidth, getY() - top); return rect; }