⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classpathfontpeer.java

📁 gcc的JAVA模块的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ClasspathFontPeer.java -- Font peer used by GNU Classpath.   Copyright (C) 2003 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.java.awt.peer;import java.awt.*;import java.awt.peer.*;import java.awt.font.*;import java.awt.geom.*;import java.text.*;import java.util.*;import gnu.java.awt.*;/** * A peer for fonts that are used inside Classpath. The purpose of * this interface is to abstract from platform-specific font handling * in the Classpath implementation of java.awt.Font and related * classes. * * <p><b>State kept by the peer:</b> a peer is generated for each Font * object in the default implementation. If you wish to share peers between * fonts, you will need to subclass both ClasspathFontPeer and * {@link ClasspathToolKit}. *  * <p><b>Thread Safety:</b> Methods of this interface may be called * from arbitrary threads at any time. Implementations of the * <code>ClasspathFontPeer</code> interface are required to perform * the necessary synchronization. * * @see java.awt.Font#getPeer * @see java.awt.Toolkit#getFontPeer * * @author Sascha Brawer (brawer@dandelis.ch) * @author Graydon Hoare (graydon@redhat.com) */public abstract class ClasspathFontPeer  implements FontPeer{  /*************************************************************************/    /*   * Instance Variables   */    /**   * The 3 names of this font. all fonts have 3 names, some of which   * may be equal:   *   * logical -- name the font was constructed from   * family  -- a designer or brand name (Helvetica)   * face -- specific instance of a design (Helvetica Regular)   *   * @see isLogicalFontName    */    protected String logicalName;  protected String familyName;  protected String faceName;    /**   * The font style, which is a combination (by OR-ing) of the font style   * constants PLAIN, BOLD and ITALIC, in this class.   */  protected int style;    /**   * The font point size. A point is 1/72 of an inch.   */  protected float size;  /**   * The affine transformation the font is currently subject to.   */  protected AffineTransform transform;  protected static ClasspathToolkit tk()  {    return (ClasspathToolkit)(Toolkit.getDefaultToolkit ());  }  /*    * Confusingly, a Logical Font is a concept unrelated to   * a Font's Logical Name.    *   * A Logical Font is one of 6 built-in, abstract font types   * which must be supported by any java environment: SansSerif,   * Serif, Monospaced, Dialog, and DialogInput.    *   * A Font's Logical Name is the name the font was constructed   * from. This might be the name of a Logical Font, or it might   * be the name of a Font Face.   */  protected static boolean isLogicalFontName(String name)  {    String uname = name.toUpperCase ();    return (uname.equals ("SANSSERIF") ||            uname.equals ("SERIF") ||            uname.equals ("MONOSPACED") ||            uname.equals ("DIALOG") ||            uname.equals ("DIALOGINPUT"));  }  protected static String logicalFontNameToFaceName (String name)  {    String uname = name.toUpperCase ();    if (uname.equals("SANSSERIF"))      return "Helvetica";    else if (uname.equals ("SERIF"))      return "Times";    else if (uname.equals ("MONOSPACED"))      return "Courier";    else if (uname.equals ("DIALOG"))      return "Helvetica";    else if (uname.equals ("DIALOGINPUT"))      return "Helvetica";    else      return "Helvetica";  }  protected static String faceNameToFamilyName (String name)  {    return name;  }  protected static void copyStyleToAttrs (int style, Map attrs)  {    if ((style & Font.BOLD) == Font.BOLD)      attrs.put (TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);    else      attrs.put (TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);    if ((style & Font.ITALIC) == Font.ITALIC)      attrs.put (TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);    else      attrs.put (TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);  }  protected static void copyFamilyToAttrs (String fam, Map attrs)  {    if (fam != null)      attrs.put (TextAttribute.FAMILY, fam);  }    protected static void copySizeToAttrs (float size, Map attrs)  {    attrs.put (TextAttribute.SIZE, new Float (size));  }    protected static void copyTransformToAttrs (AffineTransform trans, Map attrs)  {    if (trans != null)      attrs.put(TextAttribute.TRANSFORM, new TransformAttribute (trans));  }  protected void setStandardAttributes (String name, String family, int style,                                         float size, AffineTransform trans)  {    this.logicalName = name;    if (isLogicalFontName (name))      this.faceName = logicalFontNameToFaceName (name);    else      this.faceName = name;    if (family != null)      this.familyName = family;    else      this.familyName = faceNameToFamilyName (faceName);        this.style = style;    this.size = size;    this.transform = trans;  }  protected void setStandardAttributes (String name, Map attribs)  {    String family = this.familyName;    AffineTransform trans = this.transform;    float size = this.size;    int style = this.style;        if (attribs.containsKey (TextAttribute.FAMILY))      family = (String) attribs.get (TextAttribute.FAMILY);    if (name == null)      name = "SansSerif";    if (attribs.containsKey (TextAttribute.WEIGHT))      {        Float weight = (Float) attribs.get (TextAttribute.WEIGHT);        if (weight.floatValue () >= TextAttribute.WEIGHT_BOLD.floatValue ())          style += Font.BOLD;      }    if (attribs.containsKey (TextAttribute.POSTURE))      {        Float posture = (Float) attribs.get (TextAttribute.POSTURE);        if (posture.floatValue () >= TextAttribute.POSTURE_OBLIQUE.floatValue ())          style += Font.ITALIC;      }    if (attribs.containsKey (TextAttribute.SIZE))      {        Float sz = (Float) attribs.get (TextAttribute.SIZE);        size = sz.floatValue ();      }    if (attribs.containsKey (TextAttribute.TRANSFORM))      {        TransformAttribute ta = (TransformAttribute)           attribs.get(TextAttribute.TRANSFORM);        trans = ta.getTransform ();              }    setStandardAttributes (name, family, style, size, trans);  }  protected void getStandardAttributes (Map attrs)  {        copyFamilyToAttrs (this.familyName, attrs);    copySizeToAttrs (this.size, attrs);    copyStyleToAttrs (this.style, attrs);    copyTransformToAttrs (this.transform, attrs);  }  /* Begin public API */  public ClasspathFontPeer (String name, Map attrs)  {    setStandardAttributes (name, attrs);  }  public ClasspathFontPeer (String name, int style, int size)  {    setStandardAttributes (name, (String)null, style,                            (float)size, (AffineTransform)null);  }  /**    * Implementation of {@link Font#getName}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */  public String getName (Font font)   {     return logicalName;   }  /**    * Implementation of {@link Font#getFamily()}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */  public String getFamily (Font font)   {     return familyName;   }  /**    * Implementation of {@link Font#getFamily(Locale)}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */  public String getFamily (Font font, Locale lc)   {     return familyName;   }  /**    * Implementation of {@link Font#getFontName()}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */  public String getFontName (Font font)   {     return faceName;   }  /**    * Implementation of {@link Font#getFontName(Locale)}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */  public String getFontName (Font font, Locale lc)   {     return faceName;   }  /**    * Implementation of {@link Font#getSize}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */  public float getSize (Font font)   {     return size;   }  /**    * Implementation of {@link Font#isPlain}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */    public boolean isPlain (Font font)   {     return style == Font.PLAIN;   }  /**    * Implementation of {@link Font#isBold}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */    public boolean isBold (Font font)   {     return ((style & Font.BOLD) == Font.BOLD);   }  /**    * Implementation of {@link Font#isItalic}   *   * @param font the font this peer is being called from. This may be   * useful if you are sharing peers between Font objects. Otherwise it may   * be ignored.   */  public boolean isItalic (Font font)   {     return ((style & Font.ITALIC) == Font.ITALIC);   }  /**    * Implementation of {@link Font#deriveFont(float)}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -