List of usage examples for com.lowagie.text.pdf BaseFont TIMES_BOLDITALIC
String TIMES_BOLDITALIC
To view the source code for com.lowagie.text.pdf BaseFont TIMES_BOLDITALIC.
Click Source Link
From source file:com.moss.pdf.template.core.Renderer.java
License:Open Source License
public void render(InputStream in, List<? extends PropertyMapping> fields, OutputStream out) throws Exception { PdfReader reader = new PdfReader(in); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfWriter writer = PdfWriter.getInstance(document, out); document.open();//from www . j a va 2s. c o m for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfContentByte cb = writer.getDirectContent(); PdfImportedPage customPage = writer.getImportedPage(reader, i); /* * add the page to our new document, turning this page to its * original rotation */ int pageRotation = reader.getPageRotation(i); if (pageRotation > 0) { System.out.println("page rotation found: " + pageRotation); double angle = -((2 * Math.PI) * pageRotation / 360); // double angle = -(Math.PI / 2); cb.addTemplate(customPage, (float) Math.cos(angle), (float) Math.sin(angle), (float) -Math.sin(angle), (float) Math.cos(angle), 0f, // x document.top() + document.topMargin() // y ); } else { cb.addTemplate(customPage, 0f, 0f); } Map<FontName, BaseFont> fonts = new HashMap<FontName, BaseFont>(); for (PropertyMapping field : fields) { if (field.getPageNumber() != i) { continue; } /* * Only builtin fonts are supported at the moment */ BaseFont font; int fontSize; int alignment; String text; float x, y; float rotation; { font = fonts.get(field.getFontName()); if (font == null) { FontName e = field.getFontName(); String name = null; if (FontName.COURIER == e) { name = BaseFont.COURIER; } else if (FontName.COURIER_BOLD == e) { name = BaseFont.COURIER_BOLD; } else if (FontName.COURIER_BOLD_OBLIQUE == e) { name = BaseFont.COURIER_BOLDOBLIQUE; } else if (FontName.COURIER_OBLIQUE == e) { name = BaseFont.COURIER_OBLIQUE; } else if (FontName.HELVETICA == e) { name = BaseFont.HELVETICA; } else if (FontName.HELVETICA_BOLD == e) { name = BaseFont.HELVETICA_BOLD; } else if (FontName.HELVETICA_BOLD_OBLIQUE == e) { name = BaseFont.HELVETICA_BOLDOBLIQUE; } else if (FontName.HELVETICA_OBLIQUE == e) { name = BaseFont.HELVETICA_OBLIQUE; } else if (FontName.TIMES_BOLD == e) { name = BaseFont.TIMES_BOLD; } else if (FontName.TIMES_BOLD_ITALIC == e) { name = BaseFont.TIMES_BOLDITALIC; } else if (FontName.TIMES_ITALIC == e) { name = BaseFont.TIMES_ITALIC; } else if (FontName.TIMES_ROMAN == e) { name = BaseFont.TIMES_ROMAN; } if (name == null) { throw new RuntimeException("Unknown font type: " + e); } font = BaseFont.createFont(name, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); fonts.put(field.getFontName(), font); } fontSize = field.getFontSize(); if (TextAlignment.LEFT == field.getAlignment()) { alignment = PdfContentByte.ALIGN_LEFT; } else if (TextAlignment.CENTER == field.getAlignment()) { alignment = PdfContentByte.ALIGN_CENTER; } else if (TextAlignment.RIGHT == field.getAlignment()) { alignment = PdfContentByte.ALIGN_RIGHT; } else { alignment = PdfContentByte.ALIGN_LEFT; } Object value = p.eval(field.getExpr()); if (value == null) { text = ""; } else { text = value.toString(); } x = field.getX() * POINTS_IN_A_CM; y = field.getY() * POINTS_IN_A_CM; rotation = 0; } cb.beginText(); cb.setFontAndSize(font, fontSize); cb.showTextAligned(alignment, text, x, y, rotation); cb.endText(); } document.newPage(); } reader.close(); document.close(); }
From source file:org.apache.poi.xwpf.converter.internal.itext.XWPFFontRegistry.java
License:Open Source License
@Override protected String resolveFamilyName(String familyName, int style) { boolean bold = isBold(style); boolean italic = isItalic(style); if (COURRIER_NEW_FONT_FAMILY_NAME.equals(familyName)) { if (bold && italic) { return BaseFont.COURIER_BOLDOBLIQUE; } else if (bold) { return BaseFont.COURIER_BOLD; } else if (italic) { return BaseFont.COURIER_OBLIQUE; }// w ww. j av a 2 s.c o m return BaseFont.COURIER; } if (TIMES_NEW_ROMAN_FONT_FAMILY_NAME.equals(familyName)) { if (bold && italic) { return BaseFont.TIMES_BOLDITALIC; } else if (bold) { return BaseFont.TIMES_BOLD; } else if (italic) { return BaseFont.TIMES_ITALIC; } return BaseFont.TIMES_ROMAN; } return familyName; }
From source file:org.pentaho.reporting.libraries.fonts.itext.ITextBuiltInFontRegistry.java
License:Open Source License
private FontFamily createTimesFamily() { final DefaultFontFamily fontFamily = new DefaultFontFamily("Times"); fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.TIMES_ROMAN, false, false, false)); fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.TIMES_BOLD, true, false, false)); fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.TIMES_ITALIC, false, true, false)); fontFamily.addFontRecord(/*from ww w .ja v a2 s. c o m*/ new ITextBuiltInFontRecord(fontFamily, BaseFont.TIMES_BOLDITALIC, true, true, false)); return fontFamily; }
From source file:org.pz.platypus.plugin.html.HtmlFont.java
License:Open Source License
/** * Get the name by which iText refers to this font. This routine is mostly occupied * with the special handling of the base14 fonts. For all other fonts, this routine * simply returns its existing name.//from ww w . ja v a 2 s . co m * * @param f PdfFont whose iText name we're getting * @return a string containing the iText usable name for this font. */ String createItextFontName(final HtmlFont f) { String iTextFontName; String typefaceName = f.typeface; // handle the different versions of base14 fonts if (typefaceName.equals("COURIER")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.COURIER_BOLDOBLIQUE; else iTextFontName = BaseFont.COURIER_BOLD; } else if (f.italics) iTextFontName = BaseFont.COURIER_OBLIQUE; else iTextFontName = BaseFont.COURIER; } else if (typefaceName.equals("HELVETICA")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE; else iTextFontName = BaseFont.HELVETICA_BOLD; } else if (f.italics) iTextFontName = BaseFont.HELVETICA_OBLIQUE; else iTextFontName = BaseFont.HELVETICA; } else if (typefaceName.equals("TIMES_ROMAN")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.TIMES_BOLDITALIC; else iTextFontName = BaseFont.TIMES_BOLD; } else if (f.italics) iTextFontName = BaseFont.TIMES_ITALIC; else iTextFontName = BaseFont.TIMES_ROMAN; } else if (typefaceName.equals("SYMBOL")) { iTextFontName = BaseFont.SYMBOL; } else if (typefaceName.equals("DINGBATS")) { iTextFontName = BaseFont.ZAPFDINGBATS; } else // not a base14 font. So make sure we've loaded the font files for Platypus // then look up this font among them. If it's still not there, then return // a TIMES_ROMAN and note the error. { // if( htmlData.getTypefaceMap() == null ) { // TypefaceMap typefaceMap = new TypefaceMap( htmlData.getGdd() ); // typefaceMap.loadFamilies(); // htmlData.setTypefaceMap( typefaceMap ); // } // if the font files for this typeface/font family have not been previously registered, // then get the filenames from the typefaceMap and register them in iText's FontFactory if (!FontFactory.isRegistered(typefaceName)) { String[] fontFiles = pdfData.getTypefaceMap().getFamilyFilenames(typefaceName); for (String fontFile : fontFiles) { FontFactory.register(fontFile); } gdd.log("Registered fonts for " + typefaceName + " in iText"); } if (FontFactory.isRegistered(typefaceName)) { iTextFontName = typefaceName; } else { // the filename does not exist on the system, so substitute TIMES_ROMAN iTextFontName = BaseFont.TIMES_ROMAN; } // } // else { // gdd.logInfo( // gdd.getLit( "FILE#" ) + " " + source.getFileNumber() + " " + // gdd.getLit( "LINE#" ) + " " + source.getLineNumber() + ": " + // gdd.getLit( "ERROR.INVALID_FONT_TYPEFACE" ) + " " + // f.typeface + " " + // gdd.getLit( "IGNORED" )); // iTextFontName = typeface; } return (iTextFontName); }
From source file:org.pz.platypus.plugin.pdf.PdfFontFactory.java
License:Open Source License
/** * Gets the iText font name for any of the Base14 fonts. * * @param font the PdfFont whose name we're looking up. * @return the iText name or null if an error has occured *//* ww w .j av a 2 s . c om*/ String computeBase14ItextFontName(final PdfFont font) { final String typefaceName; String iTextFontName = null; PdfFont f; // in the impossible event this gets passed a null, then // replace it with the default font. It might be better // to just throw an exception. Should revisit this later. if (font == null) { f = new PdfFont(pdfData); } else { f = font; } typefaceName = f.getFace(); if (typefaceName.equals("COURIER")) { if (f.getBold()) { if (f.getItalics()) { iTextFontName = BaseFont.COURIER_BOLDOBLIQUE; } else { iTextFontName = BaseFont.COURIER_BOLD; } } else if (f.getItalics()) { iTextFontName = BaseFont.COURIER_OBLIQUE; } else iTextFontName = BaseFont.COURIER; return (iTextFontName); } if (typefaceName.equals("HELVETICA")) { if (f.getBold()) { if (f.getItalics()) { iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE; } else { iTextFontName = BaseFont.HELVETICA_BOLD; } } else if (f.getItalics()) { iTextFontName = BaseFont.HELVETICA_OBLIQUE; } else { iTextFontName = BaseFont.HELVETICA; } return (iTextFontName); } if (typefaceName.equals("TIMES_ROMAN")) { if (f.getBold()) { if (f.getItalics()) iTextFontName = BaseFont.TIMES_BOLDITALIC; else iTextFontName = BaseFont.TIMES_BOLD; } else if (f.getItalics()) iTextFontName = BaseFont.TIMES_ITALIC; else iTextFontName = BaseFont.TIMES_ROMAN; return (iTextFontName); } if (typefaceName.equals("SYMBOL")) { iTextFontName = BaseFont.SYMBOL; return (iTextFontName); } if (typefaceName.equals("DINGBATS")) { iTextFontName = BaseFont.ZAPFDINGBATS; return (iTextFontName); } // in theory, impossible, since the font is validated before the function is called. return (iTextFontName); }
From source file:org.pz.platypus.plugin.rtf.RtfFont.java
License:Open Source License
/** * Get the name by which iText refers to this font. This routine is mostly occupied * with the special handling of the base14 fonts. * * For all other fonts, this method makes sure the font is registered with iText and * returns its name as registered by iText (which is the family name for the font). * * @param f PdfFont whose iText name we're getting * @return a string containing the iText usable name for this font. *//*from ww w . ja va 2 s.c om*/ String createItextFontName(final RtfFont f) { String iTextFontName; String typefaceName = f.typeface; // handle the different versions of base14 fonts if (typefaceName.equals("COURIER")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.COURIER_BOLDOBLIQUE; else iTextFontName = BaseFont.COURIER_BOLD; } else if (f.italics) iTextFontName = BaseFont.COURIER_OBLIQUE; else iTextFontName = BaseFont.COURIER; } else if (typefaceName.equals("HELVETICA")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE; else iTextFontName = BaseFont.HELVETICA_BOLD; } else if (f.italics) iTextFontName = BaseFont.HELVETICA_OBLIQUE; else iTextFontName = BaseFont.HELVETICA; } else if (typefaceName.equals("TIMES_ROMAN")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.TIMES_BOLDITALIC; else iTextFontName = BaseFont.TIMES_BOLD; } else if (f.italics) iTextFontName = BaseFont.TIMES_ITALIC; else iTextFontName = BaseFont.TIMES_ROMAN; } else if (typefaceName.equals("SYMBOL")) { iTextFontName = BaseFont.SYMBOL; } else if (typefaceName.equals("DINGBATS")) { iTextFontName = BaseFont.ZAPFDINGBATS; } else // It's not a base14 font. So make sure we've loaded the font files for Platypus // then look up this font among them. If it's still not there, then return // a TIMES_ROMAN and note the error. { if (!FontFactory.isRegistered(typefaceName)) { if (!findAndRegisterFont(typefaceName)) { return (null); } } if (FontFactory.isRegistered(typefaceName)) { iTextFontName = typefaceName; } else { // in theory, cannot get here. gdd.logWarning(gdd.getLit("COULD_NOT_FIND") + " " + typefaceName + " " + gdd.getLit("IN_FONT_REGISTER") + ". " + gdd.getLit("USING_TIMES_ROMAN") + "."); iTextFontName = null; } } return (iTextFontName); }
From source file:org.xhtmlrenderer.pdf.ITextFontResolver.java
License:Open Source License
private static void addTimes(HashMap result) throws DocumentException, IOException { FontFamily times = new FontFamily(); times.setName("Times"); times.addFontDescription(//from ww w . j a v a 2s. com new FontDescription(createFont(BaseFont.TIMES_BOLDITALIC), IdentValue.ITALIC, 700)); times.addFontDescription(new FontDescription(createFont(BaseFont.TIMES_ITALIC), IdentValue.ITALIC, 400)); times.addFontDescription(new FontDescription(createFont(BaseFont.TIMES_BOLD), IdentValue.NORMAL, 700)); times.addFontDescription(new FontDescription(createFont(BaseFont.TIMES_ROMAN), IdentValue.NORMAL, 400)); result.put("Serif", times); result.put("TimesRoman", times); }