List of usage examples for com.lowagie.text.pdf BaseFont getWidthPoint
public float getWidthPoint(int char1, float fontSize)
char
in points. From source file:org.flightgear.clgen.backend.PdfVisitor.java
License:Open Source License
private int normalTextWidth() { BaseFont b = PdfVisitor.P.getCalculatedBaseFont(false); float w = b.getWidthPoint(".", PdfVisitor.P.getSize()); return (int) Math.floor((document.getPageSize().getWidth() - MARGIN * 2) / w); }
From source file:org.mapfish.print.scalebar.Label.java
License:Open Source License
public Label(float paperOffset, String label, BaseFont font, double fontSize, boolean rotated) { this.paperOffset = paperOffset; this.label = label; final float textWidth = font.getWidthPoint(label, (float) fontSize); final float textHeight = font.getAscentPoint(label, (float) fontSize) - font.getDescentPoint(label, (float) fontSize); if (rotated) { this.height = textWidth; this.width = textHeight; } else {// w ww .j a v a2s .c o m this.width = textWidth; this.height = textHeight; } }
From source file:org.posterita.core.PDFReportGenerator.java
License:Open Source License
protected Image getTextAsImage(String text) throws OperationException { try {/*from w w w . j av a2 s .co m*/ PdfTemplate template = writer.getDirectContent().createTemplate(20, 20); //BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false); BaseFont bf = HEADER_FONT.getBaseFont(); float size = 10; float width = bf.getWidthPoint(text, size); template.beginText(); //template.setRGBColorFillF(1, 1, 1); template.setFontAndSize(bf, size); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(size + 2); // make an Image object from the template Image img = Image.getInstance(template); img.setAlignment(Image.RIGHT | Image.TEXTWRAP); return img; } catch (Exception e) { throw new OperationException(e); } }
From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java
License:Open Source License
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception { if (text == null) return;// ww w. j a v a2 s . c om if (text.indexOf("<span") >= 0) text = text.replaceAll("</span>", "").replaceAll("<span .*>", ""); Font font = PdfFont.getFont(bold); BaseFont bf = font.getBaseFont(); float width = bf.getWidthPoint(text, font.getSize()); PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width); template.beginText(); template.setColorFill(Color.BLACK); template.setFontAndSize(bf, font.getSize()); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(font.getSize() + 2); //make an Image object from the template Image img = Image.getInstance(template); img.setRotationDegrees(270); //embed the image in a Chunk Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell.getPhrase().add(ck); } }
From source file:org.xhtmlrenderer.pdf.ITextTextRenderer.java
License:Open Source License
public int getWidth(FontContext context, FSFont font, String string) { BaseFont bf = ((ITextFSFont) font).getFontDescription().getFont(); float result = bf.getWidthPoint(string, font.getSize2D()); if (result - Math.floor(result) < TEXT_MEASURING_DELTA) { return (int) result; } else {// ww w .ja v a 2 s .co m return (int) Math.ceil(result); } }