List of usage examples for com.lowagie.text Font getBaseFont
public BaseFont getBaseFont()
BaseFont
inside this object. From source file:org.unitime.timetable.export.PDFPrinter.java
License:Open Source License
@Override public void printHeader(String... fields) { iTable = new PdfPTable(fields.length - iHiddenColumns.size()); iMaxWidth = new float[fields.length]; iTable.setHeaderRows(1);//from w w w. j a v a2 s . c o m iTable.setWidthPercentage(100); for (int idx = 0; idx < fields.length; idx++) { if (iHiddenColumns.contains(idx)) continue; String f = fields[idx]; PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.BOTTOM); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); Font font = PdfFont.getFont(true); cell.addElement(new Chunk(f, font)); iTable.addCell(cell); float width = 0; if (f.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize())); iMaxWidth[idx] = width; } }
From source file:org.unitime.timetable.export.PDFPrinter.java
License:Open Source License
@Override public void printLine(String... fields) { PdfPCellEvent setLineDashEvent = new PdfPCellEvent() { @Override/* ww w. j ava 2 s.c o m*/ public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) { PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; cb.setLineDash(new float[] { 2, 2 }, 0); } }; for (int idx = 0; idx < fields.length; idx++) { if (iHiddenColumns.contains(idx)) continue; String f = fields[idx]; if (f == null || f.isEmpty() || (iCheckLast && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx]))) f = ""; boolean number = sNumber.matcher(f).matches(); Font font = PdfFont.getFont(); Phrase p = new Phrase(f, PdfFont.getSmallFont()); PdfPCell cell = new PdfPCell(p); cell.setBorder(iLastLine == null ? Rectangle.TOP : Rectangle.NO_BORDER); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(number ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT); cell.setPaddingBottom(4f); cell.setCellEvent(setLineDashEvent); if (number) cell.setPaddingRight(10f); iTable.addCell(cell); float width = 0; if (f.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(f, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width, font.getBaseFont().getWidthPoint(f, font.getSize())); iMaxWidth[idx] = Math.max(iMaxWidth[idx], width + (number ? 10 : 0)); } iLastLine = fields; }
From source file:org.unitime.timetable.export.rooms.RoomFeaturesExportPDF.java
License:Apache License
protected A rooms(FeatureInterface feature) { A ret = new A(); if (feature.hasRooms()) { Font font = PdfFont.getFont(true); String rooms = ""; for (Iterator<Entity> i = feature.getRooms().iterator(); i.hasNext();) { String chip = name(i.next()) + (i.hasNext() ? ", " : ""); if (font.getBaseFont().getWidthPoint(rooms + chip, font.getSize()) < 500f) rooms += chip;//from w w w . j av a 2 s .c om else { ret.add(new A(rooms)); rooms = chip; } } if (!rooms.isEmpty()) ret.add(new A(rooms)); } return ret; }
From source file:org.unitime.timetable.export.rooms.RoomGroupsExportPDF.java
License:Apache License
protected A rooms(GroupInterface group) { A ret = new A(); if (group.hasRooms()) { Font font = PdfFont.getFont(true); String rooms = ""; for (Iterator<Entity> i = group.getRooms().iterator(); i.hasNext();) { String chip = name(i.next()) + (i.hasNext() ? ", " : ""); if (font.getBaseFont().getWidthPoint(rooms + chip, font.getSize()) < 500f) rooms += chip;/* www .ja v a 2 s.co m*/ else { ret.add(new A(rooms)); rooms = chip; } } if (!rooms.isEmpty()) ret.add(new A(rooms)); } return ret; }
From source file:org.unitime.timetable.export.solver.ExportTimetablePDF.java
License:Apache License
protected static float textWidth(Font font, TimetableGridCell cell, boolean showRoom, boolean showInstructor, boolean showTime, boolean showPreference, boolean showDate) { float width = 0; if (cell.getNrNames() > 0) { for (String name : cell.getNames()) width = Math.max(width, font.getBaseFont().getWidthPoint(name, font.getSize())); }// w ww.j av a 2 s . c o m if (showTime && cell.hasTime()) width = Math.max(width, font.getBaseFont().getWidthPoint(cell.getTime(), font.getSize())); if (showDate && cell.hasDate()) width = Math.max(width, font.getBaseFont().getWidthPoint(cell.getDate(), font.getSize())); if (showRoom && cell.getNrRooms() > 0) for (String room : cell.getRooms()) width = Math.max(width, font.getBaseFont().getWidthPoint(room, font.getSize())); if (showInstructor && cell.getNrInstructors() > 0) for (String instructor : cell.getInstructors()) width = Math.max(width, font.getBaseFont().getWidthPoint(instructor, font.getSize())); if (showPreference && cell.hasPreference()) width = Math.max(width, font.getBaseFont() .getWidthPoint(cell.getPreference().replaceAll("\\<[^>]*>", ""), font.getSize())); return width; }
From source file:org.unitime.timetable.util.PdfEventHandler.java
License:Open Source License
/** * Constructor for PdfEventHandler// ww w .ja va 2 s . com * */ public PdfEventHandler() throws DocumentException, IOException { super(); Font font = PdfFont.getSmallFont(); setBaseFont(font.getBaseFont()); setFontSize(font.getSize()); return; }
From source file:org.unitime.timetable.webutil.PdfWebTable.java
License:Open Source License
public static float getWidth(String text, boolean bold, boolean italic) { Font font = PdfFont.getFont(bold, italic); float width = 0; if (text.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(text, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else/*from w w w .j a v a 2 s . c o m*/ width = Math.max(width, font.getBaseFont().getWidthPoint(text, font.getSize())); return width; }
From source file:org.unitime.timetable.webutil.PdfWebTable.java
License:Open Source License
public static float getWidthOfLastLine(String text, boolean bold, boolean italic) { Font font = PdfFont.getFont(bold, italic); float width = 0; if (text.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(text, "\n"); s.hasMoreTokens();) width = font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()); } else/*from w w w. ja va 2s . co m*/ width = Math.max(width, font.getBaseFont().getWidthPoint(text, font.getSize())); return width; }
From source file:org.unitime.timetable.webutil.PdfWebTable.java
License:Open Source License
private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color, Color bgColor) {/*from ww w . ja v a 2 s . c om*/ Font font = PdfFont.getFont(bold, italic, underline, color); Chunk chunk = new Chunk(text, font); if (bgColor != null) chunk.setBackground(bgColor); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(chunk)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(chunk); } float width = 0; if (text.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(text, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width, font.getBaseFont().getWidthPoint(text, font.getSize())); return width; }
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;// w ww .j a v a 2s . c o m 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); } }