1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Android: Fixed an issue where getting the metrics of a string on android could crash if the string can't be represented as a UTF-16 string

This commit is contained in:
hogliux 2018-04-11 10:47:05 +01:00
parent 16935088e1
commit a7b5c1f77f

View file

@ -199,7 +199,7 @@ public:
float getStringWidth (const String& text) override
{
JNIEnv* env = getEnv();
const int numChars = text.length();
const int numChars = CharPointer_UTF16::getBytesRequiredFor (text.getCharPointer());
jfloatArray widths = env->NewFloatArray (numChars);
const int numDone = paint.callIntMethod (AndroidPaint.getTextWidths, javaString (text).get(), widths);
@ -218,12 +218,10 @@ public:
void getGlyphPositions (const String& text, Array<int>& glyphs, Array<float>& xOffsets) override
{
JNIEnv* env = getEnv();
auto jtext = javaString (text);
const int numChars = env->GetStringLength (jtext.get());
const int numChars = CharPointer_UTF16::getBytesRequiredFor (text.getCharPointer());
jfloatArray widths = env->NewFloatArray (numChars);
const int numDone = paint.callIntMethod (AndroidPaint.getTextWidths, jtext.get(), widths);
const int numDone = paint.callIntMethod (AndroidPaint.getTextWidths, javaString (text).get(), widths);
HeapBlock<jfloat> localWidths (static_cast<size_t> (numDone));
env->GetFloatArrayRegion (widths, 0, numDone, localWidths);