diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/Paint.java | 176 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RSTextureView.java | 4 |
2 files changed, 156 insertions, 24 deletions
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 1df8143..fe4b082 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -1179,13 +1179,26 @@ public class Paint { /** * Return the width of the text. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @param index The index of the first character to start measuring * @param count THe number of characters to measure, beginning with start * @return The width of the text */ public float measureText(char[] text, int index, int count) { - if (!mHasCompatScaling) return native_measureText(text, index, count); + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if ((index | count) < 0 || index + count > text.length) { + throw new ArrayIndexOutOfBoundsException(); + } + + if (text.length == 0 || count == 0) { + return 0f; + } + if (!mHasCompatScaling) { + return native_measureText(text, index, count); + } + final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); float w = native_measureText(text, index, count); @@ -1198,13 +1211,26 @@ public class Paint { /** * Return the width of the text. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @param start The index of the first character to start measuring * @param end 1 beyond the index of the last character to measure * @return The width of the text */ public float measureText(String text, int start, int end) { - if (!mHasCompatScaling) return native_measureText(text, start, end); + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if ((start | end | (end - start) | (text.length() - end)) < 0) { + throw new IndexOutOfBoundsException(); + } + + if (text.length() == 0 || start == end) { + return 0f; + } + if (!mHasCompatScaling) { + return native_measureText(text, start, end); + } + final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); float w = native_measureText(text, start, end); @@ -1217,10 +1243,18 @@ public class Paint { /** * Return the width of the text. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @return The width of the text */ public float measureText(String text) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + + if (text.length() == 0) { + return 0f; + } + if (!mHasCompatScaling) return native_measureText(text); final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); @@ -1240,6 +1274,16 @@ public class Paint { * @return The width of the text */ public float measureText(CharSequence text, int start, int end) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if ((start | end | (end - start) | (text.length() - end)) < 0) { + throw new IndexOutOfBoundsException(); + } + + if (text.length() == 0 || start == end) { + return 0f; + } if (text instanceof String) { return measureText((String)text, start, end); } @@ -1263,7 +1307,7 @@ public class Paint { * Return the number of chars that were measured, and if measuredWidth is * not null, return in it the actual width measured. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @param index The offset into text to begin measuring at * @param count The number of maximum number of entries to measure. If count * is negative, then the characters are measured in reverse order. @@ -1275,9 +1319,20 @@ public class Paint { */ public int breakText(char[] text, int index, int count, float maxWidth, float[] measuredWidth) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if ((index | count) < 0 || index + count > text.length) { + throw new ArrayIndexOutOfBoundsException(); + } + + if (text.length == 0 || count == 0) { + return 0; + } if (!mHasCompatScaling) { return native_breakText(text, index, count, maxWidth, measuredWidth); } + final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); int res = native_breakText(text, index, count, maxWidth*mCompatScaling, @@ -1295,7 +1350,7 @@ public class Paint { * Return the number of chars that were measured, and if measuredWidth is * not null, return in it the actual width measured. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @param start The offset into text to begin measuring at * @param end The end of the text slice to measure. * @param measureForwards If true, measure forwards, starting at start. @@ -1309,6 +1364,16 @@ public class Paint { public int breakText(CharSequence text, int start, int end, boolean measureForwards, float maxWidth, float[] measuredWidth) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if ((start | end | (end - start) | (text.length() - end)) < 0) { + throw new IndexOutOfBoundsException(); + } + + if (text.length() == 0 || start == end) { + return 0; + } if (start == 0 && text instanceof String && end == text.length()) { return breakText((String) text, measureForwards, maxWidth, measuredWidth); @@ -1334,7 +1399,7 @@ public class Paint { * Return the number of chars that were measured, and if measuredWidth is * not null, return in it the actual width measured. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @param measureForwards If true, measure forwards, starting with the * first character in the string. Otherwise, * measure backwards, starting with the @@ -1347,9 +1412,17 @@ public class Paint { */ public int breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + + if (text.length() == 0) { + return 0; + } if (!mHasCompatScaling) { return native_breakText(text, measureForwards, maxWidth, measuredWidth); } + final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); int res = native_breakText(text, measureForwards, maxWidth*mCompatScaling, @@ -1365,7 +1438,7 @@ public class Paint { /** * Return the advance widths for the characters in the string. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @param index The index of the first char to to measure * @param count The number of chars starting with index to measure * @param widths array to receive the advance widths of the characters. @@ -1374,14 +1447,21 @@ public class Paint { */ public int getTextWidths(char[] text, int index, int count, float[] widths) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } if ((index | count) < 0 || index + count > text.length || count > widths.length) { throw new ArrayIndexOutOfBoundsException(); } - + + if (text.length == 0 || count == 0) { + return 0; + } if (!mHasCompatScaling) { return native_getTextWidths(mNativePaint, text, index, count, widths); } + final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); int res = native_getTextWidths(mNativePaint, text, index, count, widths); @@ -1395,7 +1475,7 @@ public class Paint { /** * Return the advance widths for the characters in the string. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @param start The index of the first char to to measure * @param end The end of the text slice to measure * @param widths array to receive the advance widths of the characters. @@ -1404,6 +1484,19 @@ public class Paint { */ public int getTextWidths(CharSequence text, int start, int end, float[] widths) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if ((start | end | (end - start) | (text.length() - end)) < 0) { + throw new IndexOutOfBoundsException(); + } + if (end - start > widths.length) { + throw new ArrayIndexOutOfBoundsException(); + } + + if (text.length() == 0 || start == end) { + return 0; + } if (text instanceof String) { return getTextWidths((String) text, start, end, widths); } @@ -1426,7 +1519,7 @@ public class Paint { /** * Return the advance widths for the characters in the string. * - * @param text The text to measure + * @param text The text to measure. Cannot be null. * @param start The index of the first char to to measure * @param end The end of the text slice to measure * @param widths array to receive the advance widths of the characters. @@ -1434,6 +1527,9 @@ public class Paint { * @return the number of unichars in the specified text. */ public int getTextWidths(String text, int start, int end, float[] widths) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } if ((start | end | (end - start) | (text.length() - end)) < 0) { throw new IndexOutOfBoundsException(); } @@ -1441,9 +1537,13 @@ public class Paint { throw new ArrayIndexOutOfBoundsException(); } + if (text.length() == 0 || start == end) { + return 0; + } if (!mHasCompatScaling) { return native_getTextWidths(mNativePaint, text, start, end, widths); } + final float oldSize = getTextSize(); setTextSize(oldSize*mCompatScaling); int res = native_getTextWidths(mNativePaint, text, start, end, widths); @@ -1488,6 +1588,12 @@ public class Paint { */ public int getTextGlypths(String text, int start, int end, int contextStart, int contextEnd, int flags, char[] glyphs) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { + throw new IllegalArgumentException("unknown flags value: " + flags); + } if ((start | end | contextStart | contextEnd | (end - start) | (start - contextStart) | (contextEnd - end) | (text.length() - end) | (text.length() - contextEnd)) < 0) { @@ -1496,9 +1602,6 @@ public class Paint { if (end - start > glyphs.length) { throw new ArrayIndexOutOfBoundsException(); } - if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { - throw new IllegalArgumentException("unknown flags value: " + flags); - } return native_getTextGlyphs(mNativePaint, text, start, end, contextStart, contextEnd, flags, glyphs); } @@ -1528,18 +1631,24 @@ public class Paint { int contextIndex, int contextCount, int flags, float[] advances, int advancesIndex, int reserved) { + if (chars == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { + throw new IllegalArgumentException("unknown flags value: " + flags); + } if ((index | count | contextIndex | contextCount | advancesIndex - | (index - contextIndex) + | (index - contextIndex) | (contextCount - count) | ((contextIndex + contextCount) - (index + count)) | (chars.length - (contextIndex + contextCount)) | (advances == null ? 0 : (advances.length - (advancesIndex + count)))) < 0) { throw new IndexOutOfBoundsException(); } - if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { - throw new IllegalArgumentException("unknown flags value: " + flags); - } + if (chars.length == 0 || count == 0){ + return 0f; + } if (!mHasCompatScaling) { return native_getTextRunAdvances(mNativePaint, chars, index, count, contextIndex, contextCount, flags, advances, advancesIndex, reserved); @@ -1584,6 +1693,17 @@ public class Paint { int contextStart, int contextEnd, int flags, float[] advances, int advancesIndex, int reserved) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if ((start | end | contextStart | contextEnd | advancesIndex | (end - start) + | (start - contextStart) | (contextEnd - end) + | (text.length() - contextEnd) + | (advances == null ? 0 : + (advances.length - advancesIndex - (end - start)))) < 0) { + throw new IndexOutOfBoundsException(); + } + if (text instanceof String) { return getTextRunAdvances((String) text, start, end, contextStart, contextEnd, flags, advances, advancesIndex, reserved); @@ -1597,6 +1717,9 @@ public class Paint { return ((GraphicsOperations) text).getTextRunAdvances(start, end, contextStart, contextEnd, flags, advances, advancesIndex, this); } + if (text.length() == 0 || end == start) { + return 0f; + } int contextLen = contextEnd - contextStart; int len = end - start; @@ -1633,7 +1756,7 @@ public class Paint { * These bounds typically reflect changes in bidi level or font * metrics across which shaping does not occur. * - * @param text the text to measure + * @param text the text to measure. Cannot be null. * @param start the index of the first character to measure * @param end the index past the last character to measure * @param contextStart the index of the first character to use for shaping context, @@ -1681,7 +1804,7 @@ public class Paint { * These bounds typically reflect changes in bidi level or font * metrics across which shaping does not occur. * - * @param text the text to measure + * @param text the text to measure. Cannot be null. * @param start the index of the first character to measure * @param end the index past the last character to measure * @param contextStart the index of the first character to use for shaping context, @@ -1702,6 +1825,12 @@ public class Paint { public float getTextRunAdvances(String text, int start, int end, int contextStart, int contextEnd, int flags, float[] advances, int advancesIndex, int reserved) { + if (text == null) { + throw new IllegalArgumentException("text cannot be null"); + } + if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { + throw new IllegalArgumentException("unknown flags value: " + flags); + } if ((start | end | contextStart | contextEnd | advancesIndex | (end - start) | (start - contextStart) | (contextEnd - end) | (text.length() - contextEnd) @@ -1709,8 +1838,9 @@ public class Paint { (advances.length - advancesIndex - (end - start)))) < 0) { throw new IndexOutOfBoundsException(); } - if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) { - throw new IllegalArgumentException("unknown flags value: " + flags); + + if (text.length() == 0 || start == end) { + return 0f; } if (!mHasCompatScaling) { diff --git a/graphics/java/android/renderscript/RSTextureView.java b/graphics/java/android/renderscript/RSTextureView.java index b8dd577..30b2f99 100644 --- a/graphics/java/android/renderscript/RSTextureView.java +++ b/graphics/java/android/renderscript/RSTextureView.java @@ -85,13 +85,15 @@ public class RSTextureView extends TextureView implements TextureView.SurfaceTex } @Override - public void onSurfaceTextureDestroyed(SurfaceTexture surface) { + public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed"); mSurfaceTexture = surface; if (mRS != null) { mRS.setSurfaceTexture(null, 0, 0); } + + return true; } @Override |