001    /* GlyphVector.java
002       Copyright (C) 2002 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package java.awt.font;
040    
041    import java.awt.Font;
042    import java.awt.Rectangle;
043    import java.awt.Shape;
044    import java.awt.geom.AffineTransform;
045    import java.awt.geom.Point2D;
046    import java.awt.geom.Rectangle2D;
047    
048    /**
049     * @author Lillian Angel (langel at redhat dot com)
050     * @author Michael Koch
051     */
052    public abstract class GlyphVector implements Cloneable
053    {
054      public static final int FLAG_COMPLEX_GLYPHS = 8;
055      public static final int FLAG_HAS_POSITION_ADJUSTMENTS = 2;
056      public static final int FLAG_HAS_TRANSFORMS = 1;
057      public static final int FLAG_MASK = 15;
058      public static final int FLAG_RUN_RTL = 4;
059    
060      /**
061       * Constructs a <code>GlyphVector</code> object.
062       */
063      public GlyphVector ()
064      {
065      }
066    
067      public abstract boolean equals (GlyphVector set);
068    
069      public abstract Font getFont ();
070    
071      public abstract FontRenderContext getFontRenderContext ();
072    
073      public int getGlyphCharIndex (int glyphIndex)
074      {
075        return glyphIndex;
076      }
077    
078      public int[] getGlyphCharIndices(int beginGlyphIndex, int numEntries,
079                                       int[] codeReturn)
080      {
081        if (codeReturn == null)
082          codeReturn = new int[numEntries];
083    
084        int i = 0;
085        int j = beginGlyphIndex;
086        while (j < numEntries)
087          codeReturn[i++] = getGlyphCharIndex(j++);
088    
089        return codeReturn;
090      }
091    
092      public abstract int getGlyphCode (int glyphIndex);
093    
094      public abstract int[] getGlyphCodes (int beginGlyphIndex, int numEntries,
095                                           int[] codeReturn);
096    
097      public abstract GlyphJustificationInfo getGlyphJustificationInfo
098        (int glyphIndex);
099    
100      public abstract Shape getGlyphLogicalBounds (int glyphIndex);
101    
102      public abstract GlyphMetrics getGlyphMetrics (int glyphIndex);
103    
104      public abstract Shape getGlyphOutline (int glyphIndex);
105    
106      public Shape getGlyphOutline(int glyphIndex, float x, float y)
107      {
108        Shape s = getGlyphOutline(glyphIndex);
109    
110        // This is the only way to translate the origin of a shape
111        AffineTransform at = AffineTransform.getTranslateInstance(x, y);
112        return at.createTransformedShape(s);
113      }
114    
115      public Rectangle getGlyphPixelBounds(int index, FontRenderContext renderFRC,
116                                           float x, float y)
117      {
118        Rectangle bounds = new Rectangle();
119        Rectangle2D rect = getGlyphVisualBounds(index).getBounds2D();
120    
121        bounds.x = (int) (rect.getX() + x);
122        bounds.y = (int) (rect.getY() + y);
123        bounds.width = (int) rect.getMaxX() - bounds.x;
124        bounds.height = (int) rect.getMaxY() - bounds.y;
125    
126        return bounds;
127      }
128    
129      public abstract Point2D getGlyphPosition (int glyphIndex);
130    
131      public abstract float[] getGlyphPositions (int beginGlyphIndex,
132                                                 int numEntries,
133                                                 float[] positionReturn);
134    
135      public abstract AffineTransform getGlyphTransform (int glyphIndex);
136    
137      public abstract Shape getGlyphVisualBounds (int glyphIndex);
138    
139      public int getLayoutFlags()
140      {
141        return 0;
142      }
143    
144      public abstract Rectangle2D getLogicalBounds ();
145    
146      public abstract int getNumGlyphs ();
147    
148      public abstract Shape getOutline ();
149    
150      public abstract Shape getOutline (float x, float y);
151    
152      public Rectangle getPixelBounds (FontRenderContext renderFRC,
153                                       float x, float y)
154      {
155        Rectangle bounds = new Rectangle();
156        Rectangle2D rect = getVisualBounds();
157    
158        bounds.x = (int) (rect.getX() + x);
159        bounds.y = (int) (rect.getY() + y);
160        bounds.width = (int) rect.getMaxX() - bounds.x;
161        bounds.height = (int) rect.getMaxY() - bounds.y;
162    
163        return bounds;
164      }
165    
166      public abstract Rectangle2D getVisualBounds ();
167    
168      public abstract void performDefaultLayout ();
169    
170      public abstract void setGlyphPosition (int glyphIndex, Point2D newPos);
171    
172      public abstract void setGlyphTransform (int glyphIndex,
173                                              AffineTransform newTX);
174    }