List of usage examples for com.lowagie.text.pdf BaseFont HELVETICA
String HELVETICA
To view the source code for com.lowagie.text.pdf BaseFont HELVETICA.
Click Source Link
From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java
License:Open Source License
public OscarChartPrinter(HttpServletRequest request, OutputStream os) throws DocumentException, IOException { this.request = request; this.os = os; document = new Document(); writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new EndPage()); document.setPageSize(PageSize.LETTER); document.open();/*w w w . j a v a 2s . c om*/ //Create the font we are going to print to bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); font = new Font(bf, FONTSIZE, Font.NORMAL); boldFont = new Font(bf, FONTSIZE, Font.BOLD); }
From source file:org.oscarehr.casemgmt.service.CaseManagementPrintPdf.java
License:Open Source License
public void printDocHeaderFooter() throws IOException, DocumentException { //Create the document we are going to write to document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new EndPage()); document.setPageSize(PageSize.LETTER); document.open();/*w w w. j a va 2 s .c o m*/ //Create the font we are going to print to bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); font = new Font(bf, FONTSIZE, Font.NORMAL); String title = "", gender = "", dob = "", age = "", mrp = ""; if (this.demoDtl != null) { //set up document title and header ResourceBundle propResource = ResourceBundle.getBundle("oscarResources"); title = propResource.getString("oscarEncounter.pdfPrint.title") + " " + (String) demoDtl.get("demoName") + "\n"; gender = propResource.getString("oscarEncounter.pdfPrint.gender") + " " + (String) demoDtl.get("demoSex") + "\n"; dob = propResource.getString("oscarEncounter.pdfPrint.dob") + " " + (String) demoDtl.get("demoDOB") + "\n"; age = propResource.getString("oscarEncounter.pdfPrint.age") + " " + (String) demoDtl.get("demoAge") + "\n"; mrp = propResource.getString("oscarEncounter.pdfPrint.mrp") + " " + (String) demoDtl.get("mrp") + "\n"; } else { //set up document title and header ResourceBundle propResource = ResourceBundle.getBundle("oscarResources"); title = propResource.getString("oscarEncounter.pdfPrint.title") + " " + (String) request.getAttribute("demoName") + "\n"; gender = propResource.getString("oscarEncounter.pdfPrint.gender") + " " + (String) request.getAttribute("demoSex") + "\n"; dob = propResource.getString("oscarEncounter.pdfPrint.dob") + " " + (String) request.getAttribute("demoDOB") + "\n"; age = propResource.getString("oscarEncounter.pdfPrint.age") + " " + (String) request.getAttribute("demoAge") + "\n"; mrp = propResource.getString("oscarEncounter.pdfPrint.mrp") + " " + (String) request.getAttribute("mrp") + "\n"; } String[] info = new String[] { title, gender, dob, age, mrp }; ClinicData clinicData = new ClinicData(); clinicData.refreshClinicData(); String[] clinic = new String[] { clinicData.getClinicName(), clinicData.getClinicAddress(), clinicData.getClinicCity() + ", " + clinicData.getClinicProvince(), clinicData.getClinicPostal(), clinicData.getClinicPhone(), "Fax: " + clinicData.getClinicFax() }; //Header will be printed at top of every page beginning with p2 Phrase headerPhrase = new Phrase(LEADING, title, font); HeaderFooter header = new HeaderFooter(headerPhrase, false); header.setAlignment(HeaderFooter.ALIGN_CENTER); document.setHeader(header); //Write title with top and bottom borders on p1 cb = writer.getDirectContent(); cb.setColorStroke(new Color(0, 0, 0)); cb.setLineWidth(0.5f); cb.moveTo(document.left(), document.top()); cb.lineTo(document.right(), document.top()); cb.stroke(); //cb.setFontAndSize(bf, FONTSIZE); upperYcoord = document.top() - (font.getCalculatedLeading(LINESPACING) * 2f); ColumnText ct = new ColumnText(cb); Paragraph p = new Paragraph(); p.setAlignment(Paragraph.ALIGN_LEFT); Phrase phrase = new Phrase(); Phrase dummy = new Phrase(); for (int idx = 0; idx < clinic.length; ++idx) { phrase.add(clinic[idx] + "\n"); dummy.add("\n"); upperYcoord -= phrase.getLeading(); } dummy.add("\n"); ct.setSimpleColumn(document.left(), upperYcoord, document.right() / 2f, document.top()); ct.addElement(phrase); ct.go(); p.add(dummy); document.add(p); //add patient info phrase = new Phrase(); p = new Paragraph(); p.setAlignment(Paragraph.ALIGN_RIGHT); for (int idx = 0; idx < info.length; ++idx) { phrase.add(info[idx]); } ct.setSimpleColumn(document.right() / 2f, upperYcoord, document.right(), document.top()); p.add(phrase); ct.addElement(p); ct.go(); cb.moveTo(document.left(), upperYcoord); cb.lineTo(document.right(), upperYcoord); cb.stroke(); upperYcoord -= phrase.getLeading(); if (Boolean.parseBoolean(OscarProperties.getInstance().getProperty("ICFHT_CONVERT_TO_PDF", "false"))) { printPersonalInfo(); } }
From source file:org.oscarehr.casemgmt.service.FooterSupport.java
License:Open Source License
/** * Creates a new instance with as the Helvetica 12pt base font. *//*from w w w .j a v a 2 s.c o m*/ public FooterSupport() { super(); setFontSize(12); setFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); }
From source file:org.oscarehr.common.service.PdfRecordPrinter.java
License:Open Source License
public PdfRecordPrinter(HttpServletRequest request, OutputStream os) throws DocumentException, IOException { this.request = request; this.os = os; formatter = new SimpleDateFormat("dd-MMM-yyyy"); //Create the font we are going to print to bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); font = new Font(bf, FONTSIZE, Font.NORMAL); boldFont = new Font(bf, FONTSIZE, Font.BOLD); //Create the document we are going to write to document = new Document(); writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new EndPage()); writer.setStrictImageSequence(true); document.setPageSize(PageSize.LETTER); /*//from w w w. j a v a2 s .com HeaderFooter footer = new HeaderFooter(new Phrase("-",font),new Phrase("-",font)); footer.setAlignment(HeaderFooter.ALIGN_CENTER); footer.setBorder(0); document.setFooter(footer); */ document.open(); }
From source file:org.oscarehr.phr.web.PHRUserManagementAction.java
License:Open Source License
public ByteArrayOutputStream generateUserRegistrationLetter(String demographicNo, String username, String password) throws Exception { log.debug("Demographic " + demographicNo + " username " + username + " password " + password); DemographicDao demographicDao = (DemographicDao) SpringUtils.getBean("demographicDao"); Demographic demographic = demographicDao.getDemographic(demographicNo); final String PAGESIZE = "printPageSize"; Document document = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter writer = null;/* w w w . ja v a 2s . c o m*/ try { writer = PdfWriter.getInstance(document, baosPDF); String title = "TITLE"; String template = "MyOscarLetterHead.pdf"; Properties printCfg = getCfgProp(); String[] cfgVal = null; StringBuilder tempName = null; // get the print prop values Properties props = new Properties(); props.setProperty("letterDate", UtilDateUtilities.getToday("yyyy-MM-dd")); props.setProperty("name", demographic.getFirstName() + " " + demographic.getLastName()); props.setProperty("dearname", demographic.getFirstName() + " " + demographic.getLastName()); props.setProperty("address", demographic.getAddress()); props.setProperty("city", demographic.getCity() + ", " + demographic.getProvince()); props.setProperty("postalCode", demographic.getPostal()); props.setProperty("credHeading", "MyOscar User Account Details"); props.setProperty("username", "Username: " + username); props.setProperty("password", "Password: " + password); //Temporary - the intro will change to be dynamic props.setProperty("intro", "We are pleased to provide you with a log in and password for your new MyOSCAR Personal Health Record. This account will allow you to connect electronically with our clinic. Please take a few minutes to review the accompanying literature for further information.We look forward to you benefiting from this service."); document.addTitle(title); document.addSubject(""); document.addKeywords("pdf, itext"); document.addCreator("OSCAR"); document.addAuthor(""); document.addHeader("Expires", "0"); Rectangle pageSize = PageSize.LETTER; document.setPageSize(pageSize); document.open(); // create a reader for a certain document String propFilename = oscar.OscarProperties.getInstance().getProperty("pdfFORMDIR", "") + "/" + template; PdfReader reader = null; try { reader = new PdfReader(propFilename); log.debug("Found template at " + propFilename); } catch (Exception dex) { log.debug("change path to inside oscar from :" + propFilename); reader = new PdfReader("/oscar/form/prop/" + template); log.debug("Found template at /oscar/form/prop/" + template); } // retrieve the total number of pages int n = reader.getNumberOfPages(); // retrieve the size of the first page Rectangle pSize = reader.getPageSize(1); float width = pSize.getWidth(); float height = pSize.getHeight(); log.debug("Width :" + width + " Height: " + height); PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); int fontFlags = 0; document.newPage(); PdfImportedPage page1 = writer.getImportedPage(reader, 1); cb.addTemplate(page1, 1, 0, 0, 1, 0, 0); BaseFont bf; // = normFont; String encoding; cb.setRGBColorStroke(0, 0, 255); String[] fontType; for (Enumeration e = printCfg.propertyNames(); e.hasMoreElements();) { tempName = new StringBuilder(e.nextElement().toString()); cfgVal = printCfg.getProperty(tempName.toString()).split(" *, *"); if (cfgVal[4].indexOf(";") > -1) { fontType = cfgVal[4].split(";"); if (fontType[1].trim().equals("italic")) fontFlags = Font.ITALIC; else if (fontType[1].trim().equals("bold")) fontFlags = Font.BOLD; else if (fontType[1].trim().equals("bolditalic")) fontFlags = Font.BOLDITALIC; else fontFlags = Font.NORMAL; } else { fontFlags = Font.NORMAL; fontType = new String[] { cfgVal[4].trim() }; } if (fontType[0].trim().equals("BaseFont.HELVETICA")) { fontType[0] = BaseFont.HELVETICA; encoding = BaseFont.CP1252; //latin1 encoding } else if (fontType[0].trim().equals("BaseFont.HELVETICA_OBLIQUE")) { fontType[0] = BaseFont.HELVETICA_OBLIQUE; encoding = BaseFont.CP1252; } else if (fontType[0].trim().equals("BaseFont.ZAPFDINGBATS")) { fontType[0] = BaseFont.ZAPFDINGBATS; encoding = BaseFont.ZAPFDINGBATS; } else { fontType[0] = BaseFont.COURIER; encoding = BaseFont.CP1252; } bf = BaseFont.createFont(fontType[0], encoding, BaseFont.NOT_EMBEDDED); // write in a rectangle area if (cfgVal.length >= 9) { Font font = new Font(bf, Integer.parseInt(cfgVal[5].trim()), fontFlags); ct.setSimpleColumn(Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), Integer.parseInt(cfgVal[7].trim()), (height - Integer.parseInt(cfgVal[8].trim())), Integer.parseInt(cfgVal[9].trim()), (cfgVal[0].trim().equals("left") ? Element.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? Element.ALIGN_RIGHT : Element.ALIGN_CENTER))); ct.setText(new Phrase(12, props.getProperty(tempName.toString(), ""), font)); ct.go(); continue; } // draw line directly if (tempName.toString().startsWith("__$line")) { cb.setRGBColorStrokeF(0f, 0f, 0f); cb.setLineWidth(Float.parseFloat(cfgVal[4].trim())); cb.moveTo(Float.parseFloat(cfgVal[0].trim()), Float.parseFloat(cfgVal[1].trim())); cb.lineTo(Float.parseFloat(cfgVal[2].trim()), Float.parseFloat(cfgVal[3].trim())); // stroke the lines cb.stroke(); // write text directly } else if (tempName.toString().startsWith("__")) { cb.beginText(); cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim())); cb.showTextAligned( (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER)), (cfgVal.length >= 7 ? (cfgVal[6].trim()) : props.getProperty(tempName.toString(), "")), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } else if (tempName.toString().equals("forms_promotext")) { if (OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null) { cb.beginText(); cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim())); cb.showTextAligned( (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER)), OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } } else { // write prop text cb.beginText(); cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim())); cb.showTextAligned( (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER)), (cfgVal.length >= 7 ? ((props.getProperty(tempName.toString(), "").equals("") ? "" : cfgVal[6].trim())) : props.getProperty(tempName.toString(), "")), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } } } catch (DocumentException dex) { baosPDF.reset(); throw dex; } finally { if (document != null) document.close(); if (writer != null) writer.close(); } return baosPDF; }
From source file:org.pentaho.reporting.libraries.fonts.itext.BaseFontSupport.java
License:Open Source License
/** * Creates a BaseFontRecord for an font. If no basefont could be created, an BaseFontCreateException is thrown. * * @param logicalName the name of the font (null not permitted). * @param bold a flag indicating whether the font is rendered as bold font. * @param italic a flag indicating whether the font is rendered as italic or cursive font. * @param encoding the encoding./*from w w w . j ava 2 s . c om*/ * @param embedded a flag indicating whether to embed the font glyphs in the generated documents. * @return the base font record. * @throws BaseFontCreateException if there was a problem setting the font for the target. */ public BaseFontRecord createBaseFontRecord(final String logicalName, final boolean bold, final boolean italic, String encoding, final boolean embedded) throws BaseFontCreateException { if (logicalName == null) { throw new NullPointerException("Font definition is null."); } if (encoding == null) { encoding = getDefaultEncoding(); } // use the Java logical font name to map to a predefined iText font. final String fontKey; if (FontMappingUtility.isCourier(logicalName)) { fontKey = "Courier"; } else if (FontMappingUtility.isSymbol(logicalName)) { fontKey = "Symbol"; } else if (FontMappingUtility.isSerif(logicalName)) { fontKey = "Times"; } else if (FontMappingUtility.isSansSerif(logicalName)) { // default, this catches Dialog and SansSerif fontKey = "Helvetica"; } else { fontKey = logicalName; } // iText uses some weird mapping between IDENTY-H/V and java supported encoding, IDENTITY-H/V is // used to recognize TrueType fonts, but the real JavaEncoding is used to encode Type1 fonts final String stringEncoding; if ("utf-8".equalsIgnoreCase(encoding)) { stringEncoding = "utf-8"; encoding = BaseFont.IDENTITY_H; } else if ("utf-16".equalsIgnoreCase(encoding)) { stringEncoding = "utf-16"; encoding = BaseFont.IDENTITY_H; } else { // Correct the encoding for truetype fonts // iText will crash if IDENTITY_H is used to create a base font ... if (encoding.equalsIgnoreCase(BaseFont.IDENTITY_H) || encoding.equalsIgnoreCase(BaseFont.IDENTITY_V)) { //changed to UTF to support all unicode characters .. stringEncoding = "utf-8"; } else { stringEncoding = encoding; } } try { final FontFamily registryFontFamily = registry.getFontFamily(fontKey); FontRecord registryFontRecord = null; if (registryFontFamily != null) { registryFontRecord = registryFontFamily.getFontRecord(bold, italic); if (registryFontRecord instanceof CompoundFontRecord) { final CompoundFontRecord cfr = (CompoundFontRecord) registryFontRecord; registryFontRecord = cfr.getBase(); } } if (registryFontRecord != null) { // Check, whether this is an built-in font. If not, then the record points to a file. if ((registryFontRecord instanceof ITextBuiltInFontRecord) == false) { boolean embeddedOverride = embedded; if (embedded == true && registryFontRecord instanceof FontSource) { final FontSource source = (FontSource) registryFontRecord; if (source.isEmbeddable() == false) { logger.warn("License of font forbids embedded usage for font: " + fontKey); // strict mode here? embeddedOverride = false; } } final BaseFontRecord fontRecord = createFontFromTTF(registryFontRecord, bold, italic, encoding, stringEncoding, embeddedOverride); if (fontRecord != null) { return fontRecord; } } else { final ITextBuiltInFontRecord buildInFontRecord = (ITextBuiltInFontRecord) registryFontRecord; // So this is one of the built-in records. final String fontName = buildInFontRecord.getFullName(); // Alternative: No Registered TrueType font was found. OK; don't panic, // we try to create a font anyway.. BaseFontRecord fontRecord = getFromCache(fontName, encoding, embedded); if (fontRecord != null) { return fontRecord; } fontRecord = getFromCache(fontName, stringEncoding, embedded); if (fontRecord != null) { return fontRecord; } // filename is null, so no ttf file registered for the fontname, maybe this is // one of the internal fonts ... final BaseFont f = BaseFont.createFont(fontName, stringEncoding, embedded, useGlobalCache, null, null); if (f != null) { fontRecord = new BaseFontRecord(fontName, false, embedded, f, bold, italic); putToCache(fontRecord); return fontRecord; } } } // If we got to this point, then the font was not recognized as any known font. We will fall back // to Helvetica instead .. } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("BaseFont.createFont failed. Key = " + fontKey + ": " + e.getMessage(), e); } else if (logger.isWarnEnabled()) { logger.warn("BaseFont.createFont failed. Key = " + fontKey + ": " + e.getMessage(), e); } } // fallback .. use BaseFont.HELVETICA as default try { // check, whether HELVETICA is already created - yes, then return cached instance instead BaseFontRecord fontRecord = getFromCache(BaseFont.HELVETICA, stringEncoding, embedded); if (fontRecord != null) { // map all font references of the invalid font to the default font.. // this might be not very nice, but at least the report can go on.. putToCache(new BaseFontRecordKey(fontKey, encoding, embedded), fontRecord); return fontRecord; } // no helvetica created, so do this now ... final BaseFont f = BaseFont.createFont(BaseFont.HELVETICA, stringEncoding, embedded, useGlobalCache, null, null); if (f != null) { fontRecord = new BaseFontRecord(BaseFont.HELVETICA, false, embedded, f, bold, italic); putToCache(fontRecord); putToCache(new BaseFontRecordKey(fontKey, encoding, embedded), fontRecord); return fontRecord; } } catch (Exception e) { logger.warn("BaseFont.createFont for FALLBACK failed.", e); throw new BaseFontCreateException("Null font = " + fontKey); } throw new BaseFontCreateException("BaseFont creation failed, null font: " + fontKey); }
From source file:org.pentaho.reporting.libraries.fonts.itext.ITextBuiltInFontRegistry.java
License:Open Source License
private FontFamily createHelveticaFamily() { final DefaultFontFamily fontFamily = new DefaultFontFamily("Helvetica"); fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA, false, false, false)); fontFamily/*from w w w . ja v a 2 s .c o m*/ .addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_BOLD, true, false, false)); fontFamily.addFontRecord( new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_OBLIQUE, false, true, true)); fontFamily.addFontRecord( new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_BOLDOBLIQUE, true, true, true)); 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 w w w . j a v a 2 s .c om*/ * * @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 *//*from ww w . ja va2 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 w w w. j av a2 s. c o m 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); }