Index: common/java/awt/Font.java =================================================================== --- common/java/awt/Font.java (revision 442249) +++ common/java/awt/Font.java (working copy) @@ -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; } Index: common/java/awt/font/TextLayout.java =================================================================== --- common/java/awt/font/TextLayout.java (revision 442249) +++ common/java/awt/font/TextLayout.java (working copy) @@ -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); @@ -77,6 +90,18 @@ } public TextLayout(String string, Map attributes, FontRenderContext frc) { + if (string == null){ + throw new IllegalArgumentException(Messages.getString("awt.01", "string")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + if (attributes == null){ + throw new IllegalArgumentException(Messages.getString("awt.01", "attributes")); //$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.addAttributes(attributes, 0, string.length()); this.breaker = new TextRunBreaker(as.getIterator(), frc); @@ -84,6 +109,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); } Index: common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java =================================================================== --- common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java (revision 442249) +++ common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java (working copy) @@ -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(); Index: common/org/apache/harmony/awt/internal/nls/messages.properties =================================================================== --- common/org/apache/harmony/awt/internal/nls/messages.properties (revision 442249) +++ common/org/apache/harmony/awt/internal/nls/messages.properties (working copy) @@ -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