Package org.jfree.fonts.merge

Source Code of org.jfree.fonts.merge.CompoundFontRegistry

/**
* ===========================================
* LibFonts : a free Java font reading library
* ===========================================
*
* Project Info:  http://reporting.pentaho.org/libfonts/
*
* (C) Copyright 2006-2007, by Pentaho Corporation and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------
* $Id: CompoundFontRegistry.java 3523 2007-10-16 11:03:09Z tmorgner $
* ------------
* (C) Copyright 2006-2007, by Pentaho Corporation.
*/

package org.jfree.fonts.merge;

import java.util.ArrayList;
import java.util.HashSet;

import org.jfree.fonts.registry.FontRegistry;
import org.jfree.fonts.registry.FontFamily;
import org.jfree.fonts.registry.FontMetricsFactory;

/**
* Creation-Date: 20.07.2007, 18:46:04
*
* @author Thomas Morgner
*/
public class CompoundFontRegistry implements FontRegistry
{
  private ArrayList registries;

  public CompoundFontRegistry()
  {
    this.registries = new ArrayList();
  }

  public void addRegistry (final FontRegistry registry)
  {
    if (registry == null)
    {
      throw new NullPointerException();
    }
    this.registries.add(registry);
  }

  public void initialize()
  {
    for (int i = 0; i < registries.size(); i++)
    {
      final FontRegistry fontRegistry = (FontRegistry) registries.get(i);
      fontRegistry.initialize();
    }
  }

  public FontFamily getFontFamily(final String name)
  {
    for (int i = 0; i < registries.size(); i++)
    {
      final FontRegistry fontRegistry = (FontRegistry) registries.get(i);
      final FontFamily fontFamily = fontRegistry.getFontFamily(name);
      if (fontFamily != null)
      {
        return new CompoundFontFamily(fontFamily, fontRegistry);
      }
    }
    return null;
  }

  public String[] getRegisteredFamilies()
  {
    final HashSet registeredFamilies = new HashSet();

    for (int i = 0; i < registries.size(); i++)
    {
      final FontRegistry fontRegistry = (FontRegistry) registries.get(i);
      final String[] fontFamilies = fontRegistry.getRegisteredFamilies();
      for (int j = 0; j < fontFamilies.length; j++)
      {
        final String fontFamily = fontFamilies[j];
        registeredFamilies.add(fontFamily);
      }
    }
    return (String[]) registeredFamilies.toArray(new String[registeredFamilies.size()]);
  }

  public String[] getAllRegisteredFamilies()
  {
    final HashSet registeredFamilies = new HashSet();

    for (int i = 0; i < registries.size(); i++)
    {
      final FontRegistry fontRegistry = (FontRegistry) registries.get(i);
      final String[] fontFamilies = fontRegistry.getAllRegisteredFamilies();
      for (int j = 0; j < fontFamilies.length; j++)
      {
        final String fontFamily = fontFamilies[j];
        registeredFamilies.add(fontFamily);
      }
    }
    return (String[]) registeredFamilies.toArray(new String[registeredFamilies.size()]);
  }

  public FontMetricsFactory createMetricsFactory()
  {
    throw new UnsupportedOperationException("The CompoundFontRegistry cannot provide font-metrics directly.");
  }
}
TOP

Related Classes of org.jfree.fonts.merge.CompoundFontRegistry

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.