diff options
Diffstat (limited to 'java/awt/font/GlyphVector.java')
-rw-r--r-- | java/awt/font/GlyphVector.java | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/java/awt/font/GlyphVector.java b/java/awt/font/GlyphVector.java index 8d8a51d68..f4cb01b95 100644 --- a/java/awt/font/GlyphVector.java +++ b/java/awt/font/GlyphVector.java @@ -38,8 +38,6 @@ exception statement from your version. */ package java.awt.font; -import gnu.classpath.NotImplementedException; - import java.awt.Font; import java.awt.Rectangle; import java.awt.Shape; @@ -48,6 +46,7 @@ import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; /** + * @author Lillian Angel (langel at redhat dot com) * @author Michael Koch */ public abstract class GlyphVector implements Cloneable @@ -72,16 +71,22 @@ public abstract class GlyphVector implements Cloneable public abstract FontRenderContext getFontRenderContext (); public int getGlyphCharIndex (int glyphIndex) - throws NotImplementedException { - throw new Error ("not implemented"); + return glyphIndex; } - public int[] getGlyphCharIndices (int beginGlyphIndex, int numEntries, - int[] codeReturn) - throws NotImplementedException + public int[] getGlyphCharIndices(int beginGlyphIndex, int numEntries, + int[] codeReturn) { - throw new Error ("not implemented"); + if (codeReturn == null) + codeReturn = new int[numEntries]; + + int i = 0; + int j = beginGlyphIndex; + while (j < numEntries) + codeReturn[i++] = getGlyphCharIndex(j++); + + return codeReturn; } public abstract int getGlyphCode (int glyphIndex); @@ -98,17 +103,27 @@ public abstract class GlyphVector implements Cloneable public abstract Shape getGlyphOutline (int glyphIndex); - public Shape getGlyphOutline (int glyphIndex, float x, float y) - throws NotImplementedException + public Shape getGlyphOutline(int glyphIndex, float x, float y) { - throw new Error ("not implemented"); + Shape s = getGlyphOutline(glyphIndex); + + // This is the only way to translate the origin of a shape + AffineTransform at = AffineTransform.getTranslateInstance(x, y); + return at.createTransformedShape(s); } - public Rectangle getGlyphPixelBounds (int index, FontRenderContext renderFRC, - float x, float y) - throws NotImplementedException + public Rectangle getGlyphPixelBounds(int index, FontRenderContext renderFRC, + float x, float y) { - throw new Error ("not implemented"); + Rectangle bounds = new Rectangle(); + Rectangle2D rect = getGlyphVisualBounds(index).getBounds2D(); + + bounds.x = (int) (rect.getX() + x); + bounds.y = (int) (rect.getY() + y); + bounds.width = (int) rect.getMaxX() - bounds.x; + bounds.height = (int) rect.getMaxY() - bounds.y; + + return bounds; } public abstract Point2D getGlyphPosition (int glyphIndex); @@ -121,10 +136,9 @@ public abstract class GlyphVector implements Cloneable public abstract Shape getGlyphVisualBounds (int glyphIndex); - public int getLayoutFlags () - throws NotImplementedException + public int getLayoutFlags() { - throw new Error ("not implemented"); + return 0; } public abstract Rectangle2D getLogicalBounds (); @@ -137,9 +151,16 @@ public abstract class GlyphVector implements Cloneable public Rectangle getPixelBounds (FontRenderContext renderFRC, float x, float y) - throws NotImplementedException { - throw new Error ("not implemented"); + Rectangle bounds = new Rectangle(); + Rectangle2D rect = getVisualBounds(); + + bounds.x = (int) (rect.getX() + x); + bounds.y = (int) (rect.getY() + y); + bounds.width = (int) rect.getMaxX() - bounds.x; + bounds.height = (int) rect.getMaxY() - bounds.y; + + return bounds; } public abstract Rectangle2D getVisualBounds (); |