List of usage examples for com.lowagie.text.pdf BaseFont IDENTITY_H
String IDENTITY_H
To view the source code for com.lowagie.text.pdf BaseFont IDENTITY_H.
Click Source Link
From source file:org.opentaps.common.reporting.jasper.JasperReportsViewHandler.java
License:Apache License
/** * TODO: oandreyev: This hack must be removed. JasperReports must find and load fonts w/o assistance. * @return Map/* w w w . j ava 2 s . c o m*/ */ Map<FontKey, PdfFont> getPdfFontMap() { String fontPath = context .getRealPath(JRProperties.getProperty("net.sf.jasperreports.export.pdf.fontdir.jasper")); HashMap<FontKey, PdfFont> fontMap = new HashMap<FontKey, PdfFont>(); FontKey key = null; PdfFont font = null; key = new FontKey("SansSerif", false, false); font = new PdfFont(fontPath + "/" + "DejaVuSans.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("SansSerif", true, false); font = new PdfFont(fontPath + "/" + "DejaVuSans-Bold.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("SansSerif", false, true); font = new PdfFont(fontPath + "/" + "DejaVuSans-Oblique.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("SansSerif", true, true); font = new PdfFont(fontPath + "/" + "DejaVuSans-BoldOblique.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("Serif", false, false); font = new PdfFont(fontPath + "/" + "DejaVuSerif.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("Serif", true, false); font = new PdfFont(fontPath + "/" + "DejaVuSerif-Bold.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("Serif", false, true); font = new PdfFont(fontPath + "/" + "DejaVuSerif-Italic.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("Serif", true, true); font = new PdfFont(fontPath + "/" + "DejaVuSerif-BoldItalic.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans", false, false); font = new PdfFont(fontPath + "/" + "DejaVuSans.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans", true, false); font = new PdfFont(fontPath + "/" + "DejaVuSans-Bold.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans", false, true); font = new PdfFont(fontPath + "/" + "DejaVuSans-Oblique.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans", true, true); font = new PdfFont(fontPath + "/" + "DejaVuSans-BoldOblique.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Serif", false, false); font = new PdfFont(fontPath + "/" + "DejaVuSerif.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Serif", true, false); font = new PdfFont(fontPath + "/" + "DejaVuSerif-Bold.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Serif", false, true); font = new PdfFont(fontPath + "/" + "DejaVuSerif-Italic.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Serif", true, true); font = new PdfFont(fontPath + "/" + "DejaVuSerif-BoldItalic.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Condensed", false, false); font = new PdfFont(fontPath + "/" + "DejaVuSansCondensed.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Condensed", true, false); font = new PdfFont(fontPath + "/" + "DejaVuSansCondensed-Bold.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Condensed", false, true); font = new PdfFont(fontPath + "/" + "DejaVuSansCondensed-Oblique.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Condensed", true, true); font = new PdfFont(fontPath + "/" + "DejaVuSansCondensed-BoldOblique.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Mono", false, false); font = new PdfFont(fontPath + "/" + "DejaVuSansMono.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Mono", true, false); font = new PdfFont(fontPath + "/" + "DejaVuSansMono-Bold.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Mono", false, true); font = new PdfFont(fontPath + "/" + "DejaVuSansMono-Oblique.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Mono", true, true); font = new PdfFont(fontPath + "/" + "DejaVuSansMono-BoldOblique.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); key = new FontKey("DejaVu Sans Light", true, true); font = new PdfFont(fontPath + "/" + "DejaVuSans-ExtraLight.ttf", BaseFont.IDENTITY_H, true); fontMap.put(key, font); return fontMap; }
From source file:org.orbeon.oxf.processor.pdf.XHTMLToPDFProcessor.java
License:Open Source License
public static void embedFonts(ITextRenderer renderer) { final PropertySet propertySet = Properties.instance().getPropertySet(); for (final String propertyName : propertySet.getPropertiesStartsWith("oxf.fr.pdf.font.path")) { final String path = StringUtils.trimToNull(propertySet.getString(propertyName)); if (path != null) { try { // Overriding the font family is optional final String family; {//from w ww. j a v a 2 s .c om final String[] tokens = StringUtils.split(propertyName, '.'); if (tokens.length >= 6) { final String id = tokens[5]; family = StringUtils .trimToNull(propertySet.getString("oxf.fr.pdf.font.family" + '.' + id)); } else { family = null; } } // Add the font renderer.getFontResolver().addFont(path, family, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null); } catch (Exception e) { logger.warn("Failed to load font by path: '" + path + "' specified with property '" + propertyName + "'"); } } } }
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./* w ww. j a v a 2 s . co m*/ * @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.pz.platypus.plugin.pdf.PdfFontFactory.java
License:Open Source License
/** * Opens a font using the IDENTITY-H encoding. * * @param fontName the name assigned to the font in the font list * @param size the size in points//from ww w . j a va 2 s. c om * @param style bold, italic, etc. * @param color font color (RGB 0-255) * @return the Font if opened; null if the file could not be opened or an error occurred. */ Font getIdentityHFont(final String fontName, float size, int style, Color color) { Font font; try { font = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, size, style, color); } catch (Exception ex) { font = null; } return (font); }
From source file:org.pz.platypus.plugin.rtf.RtfFont.java
License:Open Source License
/** * Opens a font using the IDENTITY-H encoding. * * @param fontName the name assigned to the font in the font list * @param size the size in points/* w w w . ja v a2 s . co m*/ * @param style bold, italic, etc. * @return the Font if opened; null if the file could not be opened or an error occurred. */ Font getIdentityHFont(final String fontName, float size, int style) { // for the time being, if the font is an .otf font, don't open it with IDENTITY-H. Symbola is an // exception that seems to work. // need to explore the problem further in iText. It's recorded as PLATYPUS-32 in JIRA at Codehaus. // returning null forces the calling routine to open the font with CP1252 encoding, which is // fine for .otf fonts if (isFileOtf(fontName) && (!fontName.toLowerCase().equals("symbola"))) { return (null); } Font font; try { font = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, size, style); } catch (Exception ex) { font = null; } return (font); }
From source file:org.sakaiproject.tool.assessment.pdf.itext.HTMLWorker.java
License:Mozilla Public License
/** Creates a new instance of HTMLWorker */ public HTMLWorker(DocListener document) { this.document = document; cprops = new ChainedProperties(); String fontName = ServerConfigurationService.getString("pdf.default.font"); if (StringUtils.isNotBlank(fontName)) { FontFactory.registerDirectories(); if (FontFactory.isRegistered(fontName)) { HashMap fontProps = new HashMap(); fontProps.put(ElementTags.FACE, fontName); fontProps.put("encoding", BaseFont.IDENTITY_H); cprops.addToChain("face", fontProps); }/*w w w. j av a 2 s. c o m*/ } }
From source file:org.unitime.timetable.util.PdfFont.java
License:Open Source License
private static Font createFont(float size, boolean fixed, boolean bold, boolean italic) { String font = null;/*ww w .j a v a2s .co m*/ if (fixed) font = ApplicationProperty.PdfFontFixed.value(); else if (bold) { if (italic) font = ApplicationProperty.PdfFontBoldItalic.value(); else font = ApplicationProperty.PdfFontBold.value(); } else if (italic) font = ApplicationProperty.PdfFontItalic.value(); else font = ApplicationProperty.PdfFontNormal.value(); if (font != null && !font.isEmpty()) { try { BaseFont base = BaseFont.createFont(font, BaseFont.IDENTITY_H, true); if (base != null) return new Font(base, size); } catch (Throwable t) { } } font = (fixed ? ApplicationProperty.PdfFontFixed.value() : ApplicationProperty.PdfFontNormal.value()); if (font != null && !font.isEmpty()) { try { BaseFont base = BaseFont.createFont(font, BaseFont.IDENTITY_H, true); if (base != null) return new Font(base, size, italic && bold ? Font.BOLDITALIC : italic ? Font.ITALIC : bold ? Font.BOLD : Font.NORMAL); } catch (Throwable t) { } } if (fixed) return FontFactory.getFont(bold ? italic ? FontFactory.COURIER_BOLDOBLIQUE : FontFactory.COURIER_BOLD : italic ? FontFactory.COURIER_OBLIQUE : FontFactory.COURIER, size); else return FontFactory .getFont(bold ? italic ? FontFactory.HELVETICA_BOLDOBLIQUE : FontFactory.HELVETICA_BOLD : italic ? FontFactory.HELVETICA_OBLIQUE : FontFactory.HELVETICA, size); }
From source file:org.vulpe.commons.util.Html2PdfUtil.java
License:Open Source License
public static void convert(InputStream input, OutputStream out) throws DocumentException { try {/* w w w.ja v a 2 s.co m*/ final Tidy tidy = new Tidy(); final Document doc = tidy.parseDOM(input, null); final ITextRenderer renderer = new ITextRenderer(); final File liberationSansRegular = new File( getRealPath("/reports/fonts/liberation_sans/LiberationSans-Regular.ttf")); final File liberationSansBold = new File( getRealPath("/reports/fonts/liberation_sans/LiberationSans-Bold.ttf")); final File liberationSansBoldItalic = new File( getRealPath("/reports/fonts/liberation_sans/LiberationSans-BoldItalic.ttf")); final File liberationSansItalic = new File( getRealPath("/reports/fonts/liberation_sans/LiberationSans-Italic.ttf")); renderer.getFontResolver().addFont(liberationSansRegular.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.getFontResolver().addFont(liberationSansBold.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.getFontResolver().addFont(liberationSansBoldItalic.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.getFontResolver().addFont(liberationSansItalic.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // final BaseFont font = BaseFont.createFont(file.getAbsolutePath(), // BaseFont.IDENTITY_H, // BaseFont.NOT_EMBEDDED); // final String fontFamilyName = TrueTypeUtil.getFamilyName(font); renderer.setDocument(doc, null); renderer.layout(); renderer.createPDF(out); } catch (Exception e) { LOG.error(e.getMessage()); } }
From source file:pt.ist.fenix.jasper.reports.JasperReportPrinter.java
License:Open Source License
private Map<FontKey, PdfFont> createFontMap() { final Map<FontKey, PdfFont> result = new HashMap<FontKey, PdfFont>(4); addFont(result, "Quadraat-Regular", "QUAD____.ttf", BaseFont.CP1252); addFont(result, "Quadraat-Bold", "QUADBD__.ttf", BaseFont.CP1252); addFont(result, "Quadraat-Italic", "QUADI___.ttf", BaseFont.CP1252); addFont(result, "Quadraat-BoldItalic", "QUADBDI_.ttf", BaseFont.CP1252); addFont(result, "Arial", "Arial.ttf", BaseFont.CP1252); addFont(result, "Arial Black", "Arial_Black.ttf", BaseFont.CP1252); addFont(result, "Lucida Handwriting", "LucidaHandwriting.ttf", BaseFont.CP1252); addFont(result, "Garamond", "AdobeGaramondPro.ttf", BaseFont.CP1252); addFont(result, "Garamond Bold", "AdobeGaramondBold.ttf", BaseFont.CP1252); addFont(result, "Arial Unicode MS", "arialuni.ttf", BaseFont.IDENTITY_H); addFont(result, "DejaVu Serif Bold", "DejaVuSerif-Bold.ttf", BaseFont.IDENTITY_H); addFont(result, "Times New Roman", "tnr.ttf", BaseFont.CP1252); return result; }
From source file:questions.graphics2D.ArabicText.java
public static void main(String[] args) { Document document = new Document(PageSize.A4); try {//from w w w. j av a 2 s . c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); String text1 = "\u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631"; String text2 = "\u0634"; java.awt.Font font = new java.awt.Font("arial", 0, 12); PdfContentByte cb = writer.getDirectContent(); java.awt.Graphics2D g2Shapes = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight()); g2Shapes.setFont(font); g2Shapes.drawString("text1, expected to render RTL", 50, 100); g2Shapes.drawString(text1, 50, 120); g2Shapes.drawString("text2, expected to match right-most glyph above", 50, 140); g2Shapes.drawString(text2, 50, 160); g2Shapes.dispose(); ColumnText text = new ColumnText(cb); Font f = new Font( BaseFont.createFont("c://windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 12); text.setSimpleColumn(50, 620, 545, 50); text.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); text.setText(new Phrase(text1, f)); text.go(); text.setText(new Phrase(text2, f)); text.go(); FontMapper arialuni = new FontMapper() { public BaseFont awtToPdf(java.awt.Font font) { try { return BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } public java.awt.Font pdfToAwt(BaseFont font, int size) { return null; } }; java.awt.Graphics2D g = cb.createGraphics(PageSize.A4.getWidth(), PageSize.A4.getHeight(), arialuni); g.setFont(null); g.drawString("text1, not expected to render RTL", 50, 180); g.drawString(text1, 50, 200); g.drawString("text2, not expected to match right-most glyph above", 50, 220); g.drawString(text2, 50, 240); g.drawString("to your right you see what it SHOULD look like:", 50, 260); g.drawString("If it doesn't, the problem is in the JDK, it's not an iText problem.", 50, 280); g.dispose(); document.close(); } catch (Exception de) { de.printStackTrace(); } }