Example usage for com.lowagie.text.pdf BaseFont getResourceStream

List of usage examples for com.lowagie.text.pdf BaseFont getResourceStream

Introduction

In this page you can find the example usage for com.lowagie.text.pdf BaseFont getResourceStream.

Prototype

public static InputStream getResourceStream(String key) 

Source Link

Document

Gets the font resources.

Usage

From source file:net.bull.javamelody.internal.web.pdf.PdfFonts.java

License:Apache License

/**
 * Chargement des cjkfonts et cjkencodings. <br/>
 * Les fichiers cjkfonts.properties et cjkencoding.properties ont t renomms <br/>
 * pour que FlyingSaucer ne croit pas qu'iTextAsian.jar est prsent (issue 258). <br/>
 * Cette mthode se charge de charger quand mme les fichiers renomms pour la fonte en langue chinoise.
 *///from  w  w w  .  j  a  v a 2  s .  c  o m
private static void loadCJKFonts() {
    try {
        final Class<?> cjkFontClass = Class.forName("com.lowagie.text.pdf.CJKFont");
        final Field cjkFontsField = cjkFontClass.getDeclaredField("cjkFonts");
        final Field cjkEncodingsField = cjkFontClass.getDeclaredField("cjkEncodings");
        cjkFontsField.setAccessible(true);
        cjkEncodingsField.setAccessible(true);
        final Properties cjkFonts = (Properties) cjkFontsField.get(null);
        final Properties cjkEncodings = (Properties) cjkEncodingsField.get(null);

        if (cjkFonts.isEmpty()) {
            final InputStream is = BaseFont
                    .getResourceStream(BaseFont.RESOURCE_PATH + "cjkfonts.properties.renamedForIssue258");
            try {
                cjkFonts.load(is);
            } finally {
                is.close();
            }
        }
        if (cjkEncodings.isEmpty()) {
            final InputStream is = BaseFont
                    .getResourceStream(BaseFont.RESOURCE_PATH + "cjkencodings.properties.renamedForIssue258");
            try {
                cjkEncodings.load(is);
            } finally {
                is.close();
            }
        }
    } catch (final Exception e) {
        throw new IllegalStateException(e);
    }
}