Java Code Examples for com.lowagie.text.FontFactory#registerDirectory()

The following examples show how to use com.lowagie.text.FontFactory#registerDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RtfDestinationFontTable.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Load system fonts into the static <code>FontFactory</code> object
 * 
 * @since 2.0.8
 */
private void importSystemFonts() {
	try {
		Properties pr = getEnvironmentVariables();
		String systemRoot = pr.getProperty("SystemRoot");
		String fileSeperator = System.getProperty("file.separator");
		FontFactory.registerDirectory(systemRoot + fileSeperator + "fonts");
	} catch (Throwable e) {
		// Ignore
	}

}
 
Example 2
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static synchronized void registerFonts ()
{
	if (!fontsRegistered)
	{
		List<PropertySuffix> fontFiles = JRPropertiesUtil.getInstance(DefaultJasperReportsContext.getInstance()).getProperties(PDF_FONT_FILES_PREFIX);//FIXMECONTEXT no default here and below
		if (!fontFiles.isEmpty())
		{
			for (Iterator<PropertySuffix> i = fontFiles.iterator(); i.hasNext();)
			{
				JRPropertiesUtil.PropertySuffix font = i.next();
				String file = font.getValue();
				if (file.toLowerCase().endsWith(".ttc"))
				{
					FontFactory.register(file);
				}
				else
				{
					String alias = font.getSuffix();
					FontFactory.register(file, alias);
				}
			}
		}

		List<PropertySuffix> fontDirs = JRPropertiesUtil.getInstance(DefaultJasperReportsContext.getInstance()).getProperties(PDF_FONT_DIRS_PREFIX);
		if (!fontDirs.isEmpty())
		{
			for (Iterator<PropertySuffix> i = fontDirs.iterator(); i.hasNext();)
			{
				JRPropertiesUtil.PropertySuffix dir = i.next();
				FontFactory.registerDirectory(dir.getValue());
			}
		}

		fontsRegistered = true;
	}
}
 
Example 3
Source File: cfDOCUMENT.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public static void init( xmlCFML configFile ) {
	String fontDirs = cfEngine.getConfig().getString( "server.fonts.dirs", "" );
	
	if ( fontDirs.length() == 0 ) { // no fonts configured, set defaults
		StringBuilder defaultFontDirsList = new StringBuilder();
		if ( cfEngine.WINDOWS ) {
			for ( int i = 0; i < defaultWindowsFontDirs.length; i++ ) {
				if ( FileUtils.exists( defaultWindowsFontDirs[ i ] ) ) {
					if ( defaultFontDirsList.length() > 0 ) { // not the first
						defaultFontDirsList.append( ',' );
					}
					defaultFontDirsList.append( defaultWindowsFontDirs[ i ] );
				}
			}
		} else {
			for ( int i = 0; i < defaultOtherFontDirs.length; i++ ) {
				if ( FileUtils.exists( defaultOtherFontDirs[ i ] ) ) {
					if ( defaultFontDirsList.length() > 0 ) { // not the first
						defaultFontDirsList.append( ',' );
					}
					defaultFontDirsList.append( defaultOtherFontDirs[ i ] );
				}
			}
		}
		
		if ( defaultFontDirsList.length() > 0 ) {
			cfEngine.getConfig().setData( "server.fonts.dirs", defaultFontDirsList.toString() );
		}
		fontDirs = defaultFontDirsList.toString();
	}
	
	
	defaultFontDirs = fontDirs.split(",");
	for ( int i = 0; i < defaultFontDirs.length; i++ ){
		FontFactory.registerDirectory( defaultFontDirs[i].toString() );
	}
	
}
 
Example 4
Source File: RegisterFontFactorytListener.java    From xdocreport.samples with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void contextInitialized(ServletContextEvent event) {
	LOGGER.debug(FontFactory.getRegisteredFonts().toString());

	String fontFolder = event.getServletContext().getRealPath("font");
	LOGGER.debug("fontFolder  {}", fontFolder);
	FontFactory.registerDirectory(fontFolder);

	LOGGER.info(FontFactory.getRegisteredFonts().toString());
}
 
Example 5
Source File: RegisterFontFactorytListener.java    From xdocreport.samples with GNU Lesser General Public License v3.0 3 votes vote down vote up
public void contextInitialized(ServletContextEvent event) {
	LOGGER.info(FontFactory.getRegisteredFonts().toString());
	

	String fontFolder = event.getServletContext().getRealPath("font");
	FontFactory.registerDirectory(fontFolder);

	System.out.println(FontFactory.getRegisteredFonts());

}