summaryrefslogtreecommitdiff
path: root/gnu/java
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-11-02 11:02:28 +0000
committerRoman Kennke <roman@kennke.org>2006-11-02 11:02:28 +0000
commit0d7fffc71e6cf17f24cf6002269c377c2c7d5549 (patch)
tree6fd9f2c0f35d0eda13666d1d7f48c314fec0483d /gnu/java
parentfe40b87113d40295ea260ec276bb0fcb7a1890bc (diff)
downloadclasspath-0d7fffc71e6cf17f24cf6002269c377c2c7d5549.tar.gz
2006-11-02 Roman Kennke <kennke@aicas.com>
PR 29644 * gnu/java/awt/peer/ClasspathFontPeer.java (getStringBounds): Removed abstract method. This is replaced in java.awt.Font to use a TextLayout. * gnu/java/awt/peer/gtk/GtkWindowPeer.java (GtkWindowPeer): Set a font on the window object. * gnu/java/awt/peer/gtk/FreetypeGlyphVector.java (FreetypeGlyphVector(Font,String,FontRenderContext,int)): Changed to take char,int,int instead of String. Filter control characters. (FreetypeGlyphVector(Font,String,FontRenderContext)): Create char array out of string. (getLogicalBounds): Don't translate bounds. They already are translated. * gnu/java/awt/peer/gtk/GdkFontMetrics.java (stringWidth): Filter out control characters. * gnu/java/awt/peer/gtk/GdkFontPeer.java (getStringBounds): Removed unneeded method. (layoutGlyphVector): Pass char array directly to FreetypeGlyphVector constructor. * gnu/java/awt/peer/qt/QtFontPeer.java (getStringBounds): Removed unneeded method. * gnu/java/awt/peer/x/XFontPeer.java (getStringBounds): Removed unneeded method. * gnu/java/awt/peer/x/XFontPeer2.java (getStringBounds): Removed unneeded method. * java/awt/Font.java (getStringBounds(char[],int,int,FontRenderContext)): Use TextLayout to determine the bounds. (getStringBounds(CharacterIterator,int,int,FontRenderContext)): Delegate to the char[] version of this method. (getStringBounds(String,FontRenderContext)): Delegate to the char[] version of this method. (getStringBounds(String,int,int,FontRenderContext)): Delegate to the String version of this method.
Diffstat (limited to 'gnu/java')
-rw-r--r--gnu/java/awt/peer/gtk/FreetypeGlyphVector.java21
-rw-r--r--gnu/java/awt/peer/gtk/GdkFontMetrics.java16
-rw-r--r--gnu/java/awt/peer/gtk/GdkFontPeer.java12
-rw-r--r--gnu/java/awt/peer/gtk/GtkWindowPeer.java3
-rw-r--r--gnu/java/awt/peer/qt/QtFontPeer.java11
-rw-r--r--gnu/java/awt/peer/x/XFontPeer.java7
-rw-r--r--gnu/java/awt/peer/x/XFontPeer2.java6
7 files changed, 30 insertions, 46 deletions
diff --git a/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java b/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
index 1449cdf61..98f1bd69b 100644
--- a/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
+++ b/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
@@ -92,16 +92,23 @@ public class FreetypeGlyphVector extends GlyphVector
*/
public FreetypeGlyphVector(Font f, String s, FontRenderContext frc)
{
- this(f, s, frc, Font.LAYOUT_LEFT_TO_RIGHT);
+ this(f, s.toCharArray(), 0, s.length(), frc, Font.LAYOUT_LEFT_TO_RIGHT);
}
/**
* Create a glyphvector from a given (Freetype) font and a String.
*/
- public FreetypeGlyphVector(Font f, String s, FontRenderContext frc,
- int flags)
+ public FreetypeGlyphVector(Font f, char[] chars, int start, int len,
+ FontRenderContext frc, int flags)
{
- this.s = s;
+ // We need to filter out control characters (and possibly other
+ // non-renderable characters here).
+ StringBuilder b = new StringBuilder(chars.length);
+ for (int i = start; i < start + len; i++)
+ if (!Character.isISOControl(chars[i]))
+ b.append(chars[i]);
+ this.s = b.toString();
+
this.font = f;
this.frc = frc;
if( !(font.getPeer() instanceof GdkFontPeer ) )
@@ -429,12 +436,6 @@ public class FreetypeGlyphVector extends GlyphVector
{
Rectangle2D r2 = (Rectangle2D)getGlyphLogicalBounds( i );
- // Translate to the glyph's position
- tx.setToTranslation(glyphPositions[i*2], glyphPositions[i*2+1]);
- Point2D pt = new Point2D.Double(r2.getMinX(), r2.getMinY());
- tx.transform(pt, pt);
- r2.setRect(pt.getX(), pt.getY(), r2.getWidth(), r2.getHeight());
-
rect = rect.createUnion( r2 );
}
diff --git a/gnu/java/awt/peer/gtk/GdkFontMetrics.java b/gnu/java/awt/peer/gtk/GdkFontMetrics.java
index b2ffed10e..30b1ff15e 100644
--- a/gnu/java/awt/peer/gtk/GdkFontMetrics.java
+++ b/gnu/java/awt/peer/gtk/GdkFontMetrics.java
@@ -95,8 +95,22 @@ public class GdkFontMetrics extends FontMetrics
public int stringWidth (String str)
{
+
+// TextLayout layout = new TextLayout(str, getFont(), null);
+// return (int) layout.getAdvance();
+ // We need to filter control chars, because they are never displayed
+ // in Java and thus also have no metrics.
+ int len = str.length();
+ StringBuilder b = new StringBuilder(len);
+ for (int i = 0; i < len; i++)
+ {
+ char ch = str.charAt(i);
+ if (! Character.isISOControl(ch))
+ b.append(ch);
+ }
double [] hires = new double[6];
- peer.getTextMetrics(str, hires);
+ String string = b.toString();
+ peer.getTextMetrics(string, hires);
return (int) hires [TEXT_METRICS_WIDTH];
}
diff --git a/gnu/java/awt/peer/gtk/GdkFontPeer.java b/gnu/java/awt/peer/gtk/GdkFontPeer.java
index 11635c354..40b234984 100644
--- a/gnu/java/awt/peer/gtk/GdkFontPeer.java
+++ b/gnu/java/awt/peer/gtk/GdkFontPeer.java
@@ -345,15 +345,6 @@ public class GdkFontPeer extends ClasspathFontPeer
return buf.getShort(4);
}
- public Rectangle2D getStringBounds (Font font, CharacterIterator ci,
- int begin, int limit, FontRenderContext frc)
- {
- GlyphVector gv = new FreetypeGlyphVector( font,
- buildString(ci, begin, limit),
- frc);
- return gv.getVisualBounds();
- }
-
public boolean hasUniformLineMetrics (Font font)
{
return true;
@@ -363,8 +354,7 @@ public class GdkFontPeer extends ClasspathFontPeer
char[] chars, int start, int limit,
int flags)
{
- return new FreetypeGlyphVector( font, new String( chars, start,
- limit - start),
+ return new FreetypeGlyphVector( font, chars, start, limit - start,
frc, flags);
}
diff --git a/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/gnu/java/awt/peer/gtk/GtkWindowPeer.java
index 1abc5ca84..8d49719b1 100644
--- a/gnu/java/awt/peer/gtk/GtkWindowPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkWindowPeer.java
@@ -41,6 +41,7 @@ package gnu.java.awt.peer.gtk;
import gnu.java.awt.ComponentReshapeEvent;
import java.awt.Component;
+import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.KeyboardFocusManager;
@@ -151,6 +152,8 @@ public class GtkWindowPeer extends GtkContainerPeer
public GtkWindowPeer (Window window)
{
super (window);
+ // Set reasonable font for the window.
+ window.setFont(new Font("Dialog", Font.PLAIN, 12));
}
public native void toBack();
diff --git a/gnu/java/awt/peer/qt/QtFontPeer.java b/gnu/java/awt/peer/qt/QtFontPeer.java
index d847a8053..6ffe3f691 100644
--- a/gnu/java/awt/peer/qt/QtFontPeer.java
+++ b/gnu/java/awt/peer/qt/QtFontPeer.java
@@ -194,15 +194,4 @@ public class QtFontPeer extends ClasspathFontPeer
throw new UnsupportedOperationException();
}
- public Rectangle2D getStringBounds (Font font,
- CharacterIterator ci,
- int begin, int limit,
- FontRenderContext frc)
- {
- int index = begin;
- String s = "" + ci.setIndex( index );
- while( index++ <= limit )
- s = s + ci.next();
- return metrics.getStringBounds(s);
- }
}
diff --git a/gnu/java/awt/peer/x/XFontPeer.java b/gnu/java/awt/peer/x/XFontPeer.java
index fd293d8dd..8183fed0c 100644
--- a/gnu/java/awt/peer/x/XFontPeer.java
+++ b/gnu/java/awt/peer/x/XFontPeer.java
@@ -608,13 +608,6 @@ public class XFontPeer
throw new UnsupportedOperationException("Not yet implemented.");
}
- public Rectangle2D getStringBounds(Font font, CharacterIterator ci,
- int begin, int limit, FontRenderContext frc)
- {
- // TODO: Implement this.
- throw new UnsupportedOperationException("Not yet implemented.");
- }
-
/**
* Encodes a font name + style + size specification into a X logical font
* description (XLFD) as described here:
diff --git a/gnu/java/awt/peer/x/XFontPeer2.java b/gnu/java/awt/peer/x/XFontPeer2.java
index 25371de1a..ef9507f30 100644
--- a/gnu/java/awt/peer/x/XFontPeer2.java
+++ b/gnu/java/awt/peer/x/XFontPeer2.java
@@ -326,10 +326,4 @@ public class XFontPeer2
throw new UnsupportedOperationException("Not yet implemented");
}
- public Rectangle2D getStringBounds(Font font, CharacterIterator ci, int begin, int limit, FontRenderContext frc)
- {
- // FIXME: Implement this.
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
}