1 /*
   2  * Copyright (c) 2011, 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.webkit.graphics;
  27 
  28 public abstract class WCFont extends Ref {
  29 
  30     public abstract Object getPlatformFont();
  31 
  32     public abstract WCFont deriveFont(float size);
  33 
  34     public abstract int getOffsetForPosition(String str, float x);
  35 
  36     public abstract int[] getGlyphCodes(char[] chars);
  37 
  38     public abstract float getXHeight();
  39 
  40     public abstract double getGlyphWidth(int glyph);
  41 
  42     public abstract double[] getStringBounds(String str, int from, int to,
  43                                              boolean rtl);
  44 
  45     public abstract double getStringWidth(String str);
  46 
  47     /**
  48      * Returns a hash code value for the object.
  49      * NB: This method is called from native code!
  50      *
  51      * @return a hash code value for this object.
  52      * @see     java.lang.Object#equals(java.lang.Object)
  53      * @see     java.util.Hashtable
  54      */
  55     @Override
  56     public int hashCode() {
  57         Object font = getPlatformFont();
  58         return (font != null)
  59                 ? font.hashCode()
  60                 : 0;
  61     }
  62 
  63     /**
  64      * Indicates whether some other object is "equal to" this one.
  65      * NB: This method is called from native code!
  66      *
  67      * @param object  the reference object with which to compare
  68      * @return        {@code true} if this object is the same as the object argument;
  69      *  {@code false} otherwise.
  70      */
  71     @Override
  72     public boolean equals(Object object) {
  73         if (object instanceof WCFont) {
  74             Object font1 = getPlatformFont();
  75             Object font2 = ((WCFont) object).getPlatformFont();
  76             return font1 == null ? font2 == null : font1.equals(font2);
  77         }
  78         return false;
  79     }
  80 
  81     // Font metrics
  82 
  83     public abstract float getAscent();
  84 
  85     public abstract float getDescent();
  86 
  87     public abstract float getLineSpacing();
  88 
  89     public abstract float getLineGap();
  90 
  91     public abstract boolean hasUniformLineMetrics();
  92 
  93     public abstract float getCapHeight();
  94 }