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      * @return the Font, or null if the font cannot be created.
  93      */
  94     public PGFont loadEmbeddedFont(String name, InputStream stream,
  95                                    float size, boolean register);
  96 
  97     /**
  98      * Loads a font from the specified path. If the load is successful
  99      * such that the location is readable, and it represents a supported
 100      * font format then a <code>PGFont</code> object will be returned.
 101      * <p>
 102      * Any failure such as a file being unable to locate or read
 103      * from the resource, or if it doesn't represent a font, will result in
 104      * a <code>null</code> return. It is the application's responsibility
 105      * to check this before use.
 106      * <p>
 107      * If the <code>register</code> flag is true, and the loading operation
 108      * completes successfully, then the returned font is registered
 109      * with the FX graphics system for creation by available constructors
 110      * and factory methods, and the application should use it in this
 111      * manner rather than calling this method again, which would
 112      * repeat the overhead of re-reading and installing the font.
 113      * <p>
 114      * When the font is registered, an alternative <code>name</code> can be
 115      * supplied. This name can be used for creation by available constructors
 116      * and factory methods.
 117      * <p>
 118      * The font <code>size</code> parameter is a convenience so that in
 119      * typical usage the application can directly use the returned (non-null)
 120      * font rather than needing to create one via a constructor. Invalid sizes
 121      * are those <=0 and will result in a default size.
 122      *
 123      * @param name the name for font, it can be <code>null</code>.
 124      * @param path the path from which to load the font.
 125      * @param size the size for the font.
 126      * @param register whether the font should be register.
 127      * @return the Font, or null if the font cannot be created.
 128      */
 129     public PGFont loadEmbeddedFont(String name, String path,
 130                                    float size, boolean register);
 131 
 132     public boolean isPlatformFont(String name);
 133 }