You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2006/09/18 11:19:02 UTC
svn commit: r447336 - in
/incubator/harmony/enhanced/classlib/trunk/modules/awt/src:
main/java/common/java/awt/ main/java/common/java/awt/font/
main/java/common/org/apache/harmony/awt/gl/font/
main/java/common/org/apache/harmony/awt/internal/nls/ test/...
Author: hindessm
Date: Mon Sep 18 02:19:01 2006
New Revision: 447336
URL: http://svn.apache.org/viewvc?view=rev&rev=447336
Log:
Applying patches from "[#HARMONY-1464] [classlib][awt]compatibility:
awt.font.TextLayout() constructors with null parameters have behavior that
differs from RI" and "[#HARMONY-1465] [classlib][awt]compatibility:
awt.Font.getLineMetrics() for null FontRenderContext returns LineMetrics
instanse on Harmony and throws NPE on RI".
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/TextLayout.java
incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java
incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/font/TextLayoutTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java?view=diff&rev=447336&r1=447335&r2=447336
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java Mon Sep 18 02:19:01 2006
@@ -41,6 +41,7 @@
import org.apache.harmony.awt.gl.font.CommonGlyphVector;
import org.apache.harmony.awt.gl.font.FontPeerImpl;
+import org.apache.harmony.awt.internal.nls.Messages;
import org.apache.harmony.misc.HashCode;
@@ -131,7 +132,7 @@
// Default values are taken from the documentation of the Font class.
// See Font constructor, decode and getFont sections.
- this.name = "default";
+ this.name = "default"; //$NON-NLS-1$
this.size = 12;
this.pointSize = 12;
this.style = Font.PLAIN;
@@ -197,7 +198,7 @@
}
public Font(String name, int style, int size) {
- this.name = (name != null) ? name : "Default";
+ this.name = (name != null) ? name : "Default"; //$NON-NLS-1$
this.size = (size >= 0) ? size : 0;
this.style = (style & ~0x03) == 0 ? style : Font.PLAIN;
this.pointSize = this.size;
@@ -330,11 +331,11 @@
private static int getFontStyle(String fontStyleName){
int result = Font.PLAIN;
- if (fontStyleName.toUpperCase().equals("BOLDITALIC")) {
+ if (fontStyleName.toUpperCase().equals("BOLDITALIC")) { //$NON-NLS-1$
result = Font.BOLD | Font.ITALIC;
- } else if (fontStyleName.toUpperCase().equals("BOLD")) {
+ } else if (fontStyleName.toUpperCase().equals("BOLD")) { //$NON-NLS-1$
result = Font.BOLD;
- } else if (fontStyleName.toUpperCase().equals("ITALIC")) {
+ } else if (fontStyleName.toUpperCase().equals("ITALIC")) { //$NON-NLS-1$
result = Font.ITALIC;
}
@@ -349,12 +350,12 @@
// with spaces.
StringTokenizer strTokens;
- String delim = "-";
+ String delim = "-"; //$NON-NLS-1$
String substr;
int fontSize = 12;
int fontStyle = Font.PLAIN;
- String fontName = "dialog";
+ String fontName = "dialog"; //$NON-NLS-1$
if (str == null) {
return new Font(fontName, fontStyle, fontSize);
@@ -596,6 +597,10 @@
public LineMetrics getLineMetrics(char[] chars, int start,
int end, FontRenderContext frc) {
+ if (frc == null){
+ throw new NullPointerException(Messages.getString("awt.00")); //$NON-NLS-1$
+ }
+
FontPeerImpl peer = (FontPeerImpl)this.getPeer();
return peer.getLineMetrics((new String(chars)).substring(start, end),
@@ -604,12 +609,17 @@
public LineMetrics getLineMetrics(CharacterIterator iter, int start,
int end, FontRenderContext frc) {
+
+ if (frc == null){
+ throw new NullPointerException(Messages.getString("awt.00")); //$NON-NLS-1$
+ }
+
String resultString;
int iterCount;
iterCount = end - start;
if (iterCount < 0){
- resultString = "";
+ resultString = ""; //$NON-NLS-1$
} else{
char[] chars = new char[iterCount];
int i = 0;
@@ -625,6 +635,11 @@
}
public LineMetrics getLineMetrics(String str, FontRenderContext frc) {
+
+ if (frc == null){
+ throw new NullPointerException(Messages.getString("awt.00")); //$NON-NLS-1$
+ }
+
FontPeerImpl peer = (FontPeerImpl)this.getPeer();
return peer.getLineMetrics(str, frc, getTransform());
}
@@ -771,25 +786,25 @@
@Override
public String toString() {
- String stl = "plain";
+ String stl = "plain"; //$NON-NLS-1$
String result;
if (this.isBold() && this.isItalic()){
- stl = "bolditalic";
+ stl = "bolditalic"; //$NON-NLS-1$
}
if (this.isBold() && !this.isItalic()){
- stl = "bold";
+ stl = "bold"; //$NON-NLS-1$
}
if (!this.isBold() && this.isItalic()){
- stl = "italic";
+ stl = "italic"; //$NON-NLS-1$
}
result = this.getClass().getName() +
- "[family=" + this.getFamily() +
- ",name="+ this.name +
- ",style=" + stl +
- ",size=" + this.size + "]";
+ "[family=" + this.getFamily() + //$NON-NLS-1$
+ ",name="+ this.name + //$NON-NLS-1$
+ ",style=" + stl + //$NON-NLS-1$
+ ",size=" + this.size + "]"; //$NON-NLS-1$ //$NON-NLS-2$
return result;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/TextLayout.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/TextLayout.java?view=diff&rev=447336&r1=447335&r2=447336
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/TextLayout.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/font/TextLayout.java Mon Sep 18 02:19:01 2006
@@ -35,6 +35,7 @@
import org.apache.harmony.awt.gl.font.CaretManager;
import org.apache.harmony.awt.gl.font.TextMetricsCalculator;
import org.apache.harmony.awt.gl.font.TextRunBreaker;
+import org.apache.harmony.awt.internal.nls.Messages;
public final class TextLayout implements Cloneable {
@@ -70,6 +71,18 @@
float justificationWidth = -1;
public TextLayout(String string, Font font, FontRenderContext frc) {
+ if (string == null){
+ throw new IllegalArgumentException(Messages.getString("awt.01", "string")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (font == null){
+ throw new IllegalArgumentException(Messages.getString("awt.01", "font")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (string.length() == 0){
+ throw new IllegalArgumentException(Messages.getString("awt.02", "string")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
AttributedString as = new AttributedString(string);
as.addAttribute(TextAttribute.FONT, font);
this.breaker = new TextRunBreaker(as.getIterator(), frc);
@@ -88,6 +101,14 @@
}
public TextLayout(AttributedCharacterIterator text, FontRenderContext frc) {
+ if (text == null){
+ throw new IllegalArgumentException(Messages.getString("awt.03", "text")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (text.getBeginIndex() == text.getEndIndex()){
+ throw new IllegalArgumentException(Messages.getString("awt.04", "text")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
this.breaker = new TextRunBreaker(text, frc);
caretManager = new CaretManager(breaker);
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java?view=diff&rev=447336&r1=447335&r2=447336
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java Mon Sep 18 02:19:01 2006
@@ -76,7 +76,8 @@
}
- LineMetricsImpl lm = (LineMetricsImpl)font.getLineMetrics("", null);
+ LineMetricsImpl lm = (LineMetricsImpl)peer.getLineMetrics("", null, at);
+
this.ascent = lm.getLogicalAscent();
this.descent = lm.getLogicalDescent();
this.leading = lm.getLogicalLeading();
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties?view=diff&rev=447336&r1=447335&r2=447336
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties Mon Sep 18 02:19:01 2006
@@ -14,3 +14,8 @@
#
# messages for EN locale
+awt.00=FontRenderContext is null
+awt.01='{0}' parameter is null
+awt.02='{0}' parameter has zero length
+awt.03='{0}' iterator parameter is null
+awt.04='{0}' iterator parameter has zero length
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/font/TextLayoutTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/font/TextLayoutTest.java?view=diff&rev=447336&r1=447335&r2=447336
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/font/TextLayoutTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/font/TextLayoutTest.java Mon Sep 18 02:19:01 2006
@@ -29,6 +29,9 @@
import java.awt.geom.*;
import java.text.AttributedString;
import java.text.AttributedCharacterIterator;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.util.HashMap;
+import java.util.Map;
public class TextLayoutTest extends TestCase
{
@@ -640,6 +643,76 @@
{
TextHitInfo i = TextLayout.DEFAULT_CARET_POLICY.getStrongCaret(TextHitInfo.trailing(4), TextHitInfo.leading(5), tl);
assertEquals(TextHitInfo.leading(5), i);
+ }
+
+ public void testTextLayoutConstructorConstraints() throws Exception{
+ // regression test for Harmony-1464
+ try{
+ new TextLayout(null, (Font)null, null);
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try{
+ new TextLayout(null, f, null);
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try{
+ new TextLayout("", f, null);
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try{
+ new TextLayout("aa", f, null);
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try{
+ new TextLayout(null, null);
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ AttributedString as = new AttributedString("test");
+ as.addAttribute(TextAttribute.FONT, f, 0, 2 );
+
+ try{
+ new TextLayout(as.getIterator(), null);
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ new TextLayout(null, (Map<? extends Attribute,?>)null, (FontRenderContext) null);
+ } catch (IllegalArgumentException e) {
+ System.out.println("success: " + e.getMessage());
+ // as expected
+ }
+
+ try {
+ new TextLayout(null, (Map<? extends Attribute,?>)new HashMap(), (FontRenderContext) null);
+ } catch (IllegalArgumentException e) {
+ // as expected
+ }
+
+ try {
+ new TextLayout("aa", (Map<? extends Attribute,?>)new HashMap(), (FontRenderContext) null);
+ } catch (NullPointerException e) {
+ // as expected
+ }
+
+
+ try{
+ new TextLayout("", (Map<? extends Attribute,?>)new HashMap(), (FontRenderContext) null);
+ } catch (IllegalArgumentException e) {
+ // as expected
+ System.out.println("success: " + e.getMessage());
+ }
+
}
public static Test suite()