1 /*
   2  * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.font;
  27 
  28 import java.io.InputStream;
  29 
  30 public interface FontFactory {
  31     public static final String DEFAULT_FULLNAME = "System Regular";
  32 
  33     public PGFont createFont(String name, float size);
  34     public PGFont createFont(String family,
  35                              boolean bold, boolean italic, float size);
  36 
  37     /**
  38      * Creates a new Font object by replicating the current Font object
  39      * and applying a new bold style, italic style, and size to it.
  40      * <p>
  41      * NOTE: bold and italic are hints.
  42      *
  43      * @param font the original font.
  44      * @param bold the bold style for the new font.
  45      * @param italic the italic style fort the new font.
  46      * @param size the size for the new font.
  47      * @return the new font.
  48      */
  49     public PGFont deriveFont(PGFont font,
  50                              boolean bold, boolean italic, float size);
  51     public String[] getFontFamilyNames();
  52     public String[] getFontFullNames();
  53     public String[] getFontFullNames(String family);
  54 
  55     /*
  56      * Indicates permission to load an embedded font
  57      */
  58     public boolean hasPermission();
  59 
  60     /**
  61      * Loads a font from the specified input stream.
  62      * If the load is successful such that the stream can be
  63      * fully read, and it represents a supported font format then a
  64      * <code>PGFont</code> object will be returned.
  65      * <p>
  66      * Any failure such as abbreviated input, or an unsupported font format
  67      * will result in a <code>null</code> return. It is the application's
  68      * responsibility to check this before use.
  69      * <p>
  70      * If the <code>register</code> flag is true, and the loading operation
  71      * completes successfully, then the returned font is registered
  72      * with the FX graphics system for creation by available constructors
  73      * and factory methods, and the application should use it in this
  74      * manner rather than calling this method again, which would
  75      * repeat the overhead of re-reading and installing the font.
  76      * <p>
  77      * When the font is registered, an alternative <code>name</code> can be
  78      * supplied. This name can be used for creation by available constructors
  79      * and factory methods.
  80      * <p>
  81      * The font <code>size</code> parameter is a convenience so that in
  82      * typical usage the application can directly use the returned (non-null)
  83      * font rather than needing to create one via a constructor. Invalid sizes
  84      * are those <=0 and will result in a default size.
  85      * <p>
  86      * This method does not close the input stream.
  87      *
  88      * @param name the name for font, it can be <code>null</code>.
  89      * @param stream the stream from which to load the font.
  90      * @param size the size for the font.
  91      * @param register whether the font should be register.
  92      * @param all whether to load all fonts from a TTC
  93      * @return the Font, or null if the font cannot be created.
  94      */
  95     public PGFont[] loadEmbeddedFont(String name, InputStream stream,
  96                                    float size, boolean register, boolean all);
  97 
  98     /**
  99      * Loads a font from the specified path. If the load is successful
 100      * such that the location is readable, and it represents a supported
 101      * font format then a <code>PGFont</code> object will be returned.
 102      * <p>
 103      * Any failure such as a file being unable to locate or read
 104      * from the resource, or if it doesn't represent a font, will result in
 105      * a <code>null</code> return. It is the application's responsibility
 106      * to check this before use.
 107      * <p>
 108      * If the <code>register</code> flag is true, and the loading operation
 109      * completes successfully, then the returned font is registered
 110      * with the FX graphics system for creation by available constructors
 111      * and factory methods, and the application should use it in this
 112      * manner rather than calling this method again, which would
 113      * repeat the overhead of re-reading and installing the font.
 114      * <p>
 115      * When the font is registered, an alternative <code>name</code> can be
 116      * supplied. This name can be used for creation by available constructors
 117      * and factory methods.
 118      * <p>
 119      * The font <code>size</code> parameter is a convenience so that in
 120      * typical usage the application can directly use the returned (non-null)
 121      * font rather than needing to create one via a constructor. Invalid sizes
 122      * are those <=0 and will result in a default size.
 123      *
 124      * @param name the name for font, it can be <code>null</code>.
 125      * @param path the path from which to load the font.
 126      * @param size the size for the font.
 127      * @param register whether the font should be register.
 128      * @param all whether to load all fonts from a TTC
 129      * @return the Font, or null if the font cannot be created.
 130      */
 131     public PGFont[] loadEmbeddedFont(String name, String path,
 132                                    float size, boolean register, boolean all);
 133 
 134     public boolean isPlatformFont(String name);
 135 }