upgrade to JUCE 5.4.3. Remove (probably) unused JUCE modules. Remove VST2 target (it's been end-of-life'd by Steinberg and by JUCE)
This commit is contained in:
@ -94,11 +94,37 @@ bool TextLayout::createNativeLayout (const AttributedString&)
|
||||
#else
|
||||
|
||||
//==============================================================================
|
||||
#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \
|
||||
#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
|
||||
STATICMETHOD (create, "create", "(Ljava/lang/String;I)Landroid/graphics/Typeface;") \
|
||||
STATICMETHOD (createFromFile, "createFromFile", "(Ljava/lang/String;)Landroid/graphics/Typeface;") \
|
||||
STATICMETHOD (createFromAsset, "createFromAsset", "(Landroid/content/res/AssetManager;Ljava/lang/String;)Landroid/graphics/Typeface;")
|
||||
|
||||
DECLARE_JNI_CLASS (TypefaceClass, "android/graphics/Typeface");
|
||||
DECLARE_JNI_CLASS (TypefaceClass, "android/graphics/Typeface")
|
||||
#undef JNI_CLASS_MEMBERS
|
||||
|
||||
#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
|
||||
METHOD (constructor, "<init>", "()V") \
|
||||
METHOD (computeBounds, "computeBounds", "(Landroid/graphics/RectF;Z)V")
|
||||
|
||||
DECLARE_JNI_CLASS (AndroidPath, "android/graphics/Path")
|
||||
#undef JNI_CLASS_MEMBERS
|
||||
|
||||
#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
|
||||
METHOD (constructor, "<init>", "()V") \
|
||||
FIELD (left, "left", "F") \
|
||||
FIELD (right, "right", "F") \
|
||||
FIELD (top, "top", "F") \
|
||||
FIELD (bottom, "bottom", "F") \
|
||||
METHOD (roundOut, "roundOut", "(Landroid/graphics/Rect;)V")
|
||||
|
||||
DECLARE_JNI_CLASS (AndroidRectF, "android/graphics/RectF")
|
||||
#undef JNI_CLASS_MEMBERS
|
||||
|
||||
#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
|
||||
STATICMETHOD (getInstance, "getInstance", "(Ljava/lang/String;)Ljava/security/MessageDigest;") \
|
||||
METHOD (update, "update", "([B)V") \
|
||||
METHOD (digest, "digest", "()[B")
|
||||
DECLARE_JNI_CLASS (JavaMessageDigest, "java/security/MessageDigest")
|
||||
#undef JNI_CLASS_MEMBERS
|
||||
|
||||
//==============================================================================
|
||||
@ -136,8 +162,7 @@ public:
|
||||
JNIEnv* const env = getEnv();
|
||||
|
||||
// First check whether there's an embedded asset with this font name:
|
||||
typeface = GlobalRef (android.activity.callObjectMethod (JuceAppActivity.getTypeFaceFromAsset,
|
||||
javaString ("fonts/" + name).get()));
|
||||
typeface = GlobalRef (getTypefaceFromAsset (name));
|
||||
|
||||
if (typeface.get() == nullptr)
|
||||
{
|
||||
@ -150,12 +175,12 @@ public:
|
||||
fontFile = findFontFile (name, isBold, isItalic);
|
||||
|
||||
if (fontFile.exists())
|
||||
typeface = GlobalRef (env->CallStaticObjectMethod (TypefaceClass, TypefaceClass.createFromFile,
|
||||
javaString (fontFile.getFullPathName()).get()));
|
||||
typeface = GlobalRef (LocalRef<jobject>(env->CallStaticObjectMethod (TypefaceClass, TypefaceClass.createFromFile,
|
||||
javaString (fontFile.getFullPathName()).get())));
|
||||
else
|
||||
typeface = GlobalRef (env->CallStaticObjectMethod (TypefaceClass, TypefaceClass.create,
|
||||
javaString (getName()).get(),
|
||||
(isBold ? 1 : 0) + (isItalic ? 2 : 0)));
|
||||
typeface = GlobalRef (LocalRef<jobject>(env->CallStaticObjectMethod (TypefaceClass, TypefaceClass.create,
|
||||
javaString (getName()).get(),
|
||||
(isBold ? 1 : 0) + (isItalic ? 2 : 0))));
|
||||
}
|
||||
|
||||
initialise (env);
|
||||
@ -164,23 +189,24 @@ public:
|
||||
AndroidTypeface (const void* data, size_t size)
|
||||
: Typeface (String (static_cast<uint64> (reinterpret_cast<uintptr_t> (data))), String())
|
||||
{
|
||||
JNIEnv* const env = getEnv();
|
||||
auto* env = getEnv();
|
||||
auto cacheFile = getCacheFileForData (data, size);
|
||||
|
||||
LocalRef<jbyteArray> bytes (env->NewByteArray ((jsize) size));
|
||||
env->SetByteArrayRegion (bytes, 0, (jsize) size, (const jbyte*) data);
|
||||
|
||||
typeface = GlobalRef (android.activity.callObjectMethod (JuceAppActivity.getTypeFaceFromByteArray, bytes.get()));
|
||||
typeface = GlobalRef (LocalRef<jobject>(env->CallStaticObjectMethod (TypefaceClass, TypefaceClass.createFromFile,
|
||||
javaString (cacheFile.getFullPathName()).get())));
|
||||
|
||||
initialise (env);
|
||||
}
|
||||
|
||||
void initialise (JNIEnv* const env)
|
||||
{
|
||||
rect = GlobalRef (env->NewObject (AndroidRect, AndroidRect.constructor, 0, 0, 0, 0));
|
||||
rect = GlobalRef (LocalRef<jobject>(env->NewObject (AndroidRect, AndroidRect.constructor, 0, 0, 0, 0)));
|
||||
|
||||
paint = GlobalRef (GraphicsHelpers::createPaint (Graphics::highResamplingQuality));
|
||||
const LocalRef<jobject> ignored (paint.callObjectMethod (AndroidPaint.setTypeface, typeface.get()));
|
||||
|
||||
charArray = GlobalRef (LocalRef<jobject>((jobject) env->NewCharArray (2)));
|
||||
|
||||
paint.callVoidMethod (AndroidPaint.setTextSize, referenceFontSize);
|
||||
|
||||
const float fullAscent = std::abs (paint.callFloatMethod (AndroidPaint.ascent));
|
||||
@ -199,8 +225,8 @@ public:
|
||||
float getStringWidth (const String& text) override
|
||||
{
|
||||
JNIEnv* env = getEnv();
|
||||
const int numChars = CharPointer_UTF16::getBytesRequiredFor (text.getCharPointer());
|
||||
jfloatArray widths = env->NewFloatArray (numChars);
|
||||
auto numChars = CharPointer_UTF16::getBytesRequiredFor (text.getCharPointer());
|
||||
jfloatArray widths = env->NewFloatArray ((int) numChars);
|
||||
|
||||
const int numDone = paint.callIntMethod (AndroidPaint.getTextWidths, javaString (text).get(), widths);
|
||||
|
||||
@ -209,6 +235,7 @@ public:
|
||||
env->DeleteLocalRef (widths);
|
||||
|
||||
float x = 0;
|
||||
|
||||
for (int i = 0; i < numDone; ++i)
|
||||
x += localWidths[i];
|
||||
|
||||
@ -218,8 +245,8 @@ public:
|
||||
void getGlyphPositions (const String& text, Array<int>& glyphs, Array<float>& xOffsets) override
|
||||
{
|
||||
JNIEnv* env = getEnv();
|
||||
const int numChars = CharPointer_UTF16::getBytesRequiredFor (text.getCharPointer());
|
||||
jfloatArray widths = env->NewFloatArray (numChars);
|
||||
auto numChars = CharPointer_UTF16::getBytesRequiredFor (text.getCharPointer());
|
||||
jfloatArray widths = env->NewFloatArray ((int) numChars);
|
||||
|
||||
const int numDone = paint.callIntMethod (AndroidPaint.getTextWidths, javaString (text).get(), widths);
|
||||
|
||||
@ -230,8 +257,8 @@ public:
|
||||
auto s = text.getCharPointer();
|
||||
|
||||
xOffsets.add (0);
|
||||
|
||||
float x = 0;
|
||||
|
||||
for (int i = 0; i < numDone; ++i)
|
||||
{
|
||||
const float local = localWidths[i];
|
||||
@ -290,20 +317,56 @@ public:
|
||||
#else
|
||||
jchar ch1 = glyphNumber, ch2 = 0;
|
||||
#endif
|
||||
Rectangle<int> bounds;
|
||||
auto* env = getEnv();
|
||||
|
||||
JNIEnv* env = getEnv();
|
||||
{
|
||||
LocalRef<jobject> matrix (GraphicsHelpers::createMatrix (env, AffineTransform::scale (referenceFontToUnits).followedBy (t)));
|
||||
|
||||
jobject matrix = GraphicsHelpers::createMatrix (env, AffineTransform::scale (referenceFontToUnits).followedBy (t));
|
||||
jintArray maskData = (jintArray) android.activity.callObjectMethod (JuceAppActivity.renderGlyph, ch1, ch2, paint.get(), matrix, rect.get());
|
||||
jboolean isCopy;
|
||||
auto* buffer = env->GetCharArrayElements ((jcharArray) charArray.get(), &isCopy);
|
||||
|
||||
env->DeleteLocalRef (matrix);
|
||||
buffer[0] = ch1; buffer[1] = ch2;
|
||||
env->ReleaseCharArrayElements ((jcharArray) charArray.get(), buffer, 0);
|
||||
|
||||
const int left = env->GetIntField (rect.get(), AndroidRect.left);
|
||||
const int top = env->GetIntField (rect.get(), AndroidRect.top);
|
||||
const int right = env->GetIntField (rect.get(), AndroidRect.right);
|
||||
const int bottom = env->GetIntField (rect.get(), AndroidRect.bottom);
|
||||
LocalRef<jobject> path (env->NewObject (AndroidPath, AndroidPath.constructor));
|
||||
LocalRef<jobject> boundsF (env->NewObject (AndroidRectF, AndroidRectF.constructor));
|
||||
|
||||
const Rectangle<int> bounds (left, top, right - left, bottom - top);
|
||||
|
||||
env->CallVoidMethod (paint.get(), AndroidPaint.getCharsPath, charArray.get(), 0, (ch2 != 0 ? 2 : 1), 0.0f, 0.0f, path.get());
|
||||
|
||||
env->CallVoidMethod (path.get(), AndroidPath.computeBounds, boundsF.get(), 1);
|
||||
|
||||
env->CallBooleanMethod (matrix.get(), AndroidMatrix.mapRect, boundsF.get());
|
||||
|
||||
env->CallVoidMethod (boundsF.get(), AndroidRectF.roundOut, rect.get());
|
||||
|
||||
bounds = Rectangle<int>::leftTopRightBottom (env->GetIntField (rect.get(), AndroidRect.left) - 1,
|
||||
env->GetIntField (rect.get(), AndroidRect.top),
|
||||
env->GetIntField (rect.get(), AndroidRect.right) + 1,
|
||||
env->GetIntField (rect.get(), AndroidRect.bottom));
|
||||
|
||||
auto w = bounds.getWidth();
|
||||
auto h = jmax (1, bounds.getHeight());
|
||||
|
||||
LocalRef<jobject> bitmapConfig (env->CallStaticObjectMethod (AndroidBitmapConfig, AndroidBitmapConfig.valueOf, javaString ("ARGB_8888").get()));
|
||||
LocalRef<jobject> bitmap (env->CallStaticObjectMethod (AndroidBitmap, AndroidBitmap.createBitmap, w, h, bitmapConfig.get()));
|
||||
LocalRef<jobject> canvas (env->NewObject (AndroidCanvas, AndroidCanvas.create, bitmap.get()));
|
||||
|
||||
env->CallBooleanMethod (matrix.get(), AndroidMatrix.postTranslate, bounds.getX() * -1.0f, bounds.getY() * -1.0f);
|
||||
env->CallVoidMethod (canvas.get(), AndroidCanvas.setMatrix, matrix.get());
|
||||
env->CallVoidMethod (canvas.get(), AndroidCanvas.drawPath, path.get(), paint.get());
|
||||
|
||||
int requiredRenderArraySize = w * h;
|
||||
if (requiredRenderArraySize > lastCachedRenderArraySize)
|
||||
{
|
||||
cachedRenderArray = GlobalRef (LocalRef<jobject> ((jobject) env->NewIntArray (requiredRenderArraySize)));
|
||||
lastCachedRenderArraySize = requiredRenderArraySize;
|
||||
}
|
||||
|
||||
env->CallVoidMethod (bitmap.get(), AndroidBitmap.getPixels, cachedRenderArray.get(), 0, w, 0, 0, w, h);
|
||||
env->CallVoidMethod (bitmap.get(), AndroidBitmap.recycle);
|
||||
}
|
||||
|
||||
EdgeTable* et = nullptr;
|
||||
|
||||
@ -311,10 +374,10 @@ public:
|
||||
{
|
||||
et = new EdgeTable (bounds);
|
||||
|
||||
jint* const maskDataElements = env->GetIntArrayElements (maskData, 0);
|
||||
jint* const maskDataElements = env->GetIntArrayElements ((jintArray) cachedRenderArray.get(), 0);
|
||||
const jint* mask = maskDataElements;
|
||||
|
||||
for (int y = top; y < bottom; ++y)
|
||||
for (int y = bounds.getY(); y < bounds.getBottom(); ++y)
|
||||
{
|
||||
#if JUCE_LITTLE_ENDIAN
|
||||
const uint8* const lineBytes = ((const uint8*) mask) + 3;
|
||||
@ -322,19 +385,19 @@ public:
|
||||
const uint8* const lineBytes = (const uint8*) mask;
|
||||
#endif
|
||||
|
||||
et->clipLineToMask (left, y, lineBytes, 4, bounds.getWidth());
|
||||
et->clipLineToMask (bounds.getX(), y, lineBytes, 4, bounds.getWidth());
|
||||
mask += bounds.getWidth();
|
||||
}
|
||||
|
||||
env->ReleaseIntArrayElements (maskData, maskDataElements, 0);
|
||||
env->ReleaseIntArrayElements ((jintArray) cachedRenderArray.get(), maskDataElements, 0);
|
||||
}
|
||||
|
||||
env->DeleteLocalRef (maskData);
|
||||
return et;
|
||||
}
|
||||
|
||||
GlobalRef typeface, paint, rect;
|
||||
GlobalRef typeface, paint, rect, charArray, cachedRenderArray;
|
||||
float ascent, descent, heightToPointsFactor;
|
||||
int lastCachedRenderArraySize = -1;
|
||||
|
||||
private:
|
||||
static File findFontFile (const String& family,
|
||||
@ -372,6 +435,92 @@ private:
|
||||
return File (path + ".ttf");
|
||||
}
|
||||
|
||||
static LocalRef<jobject> getTypefaceFromAsset (const String& typefaceName)
|
||||
{
|
||||
auto* env = getEnv();
|
||||
|
||||
LocalRef<jobject> assetManager (env->CallObjectMethod (getAppContext().get(), AndroidContext.getAssets));
|
||||
|
||||
if (assetManager == nullptr)
|
||||
return LocalRef<jobject>();
|
||||
|
||||
auto assetTypeface = env->CallStaticObjectMethod (TypefaceClass, TypefaceClass.createFromAsset, assetManager.get(),
|
||||
javaString ("fonts/" + typefaceName).get());
|
||||
|
||||
// this may throw
|
||||
if (env->ExceptionCheck() != 0)
|
||||
{
|
||||
env->ExceptionClear();
|
||||
return LocalRef<jobject>();
|
||||
}
|
||||
|
||||
return LocalRef<jobject> (assetTypeface);
|
||||
}
|
||||
|
||||
static File getCacheDirectory()
|
||||
{
|
||||
static File result = [] ()
|
||||
{
|
||||
auto appContext = getAppContext();
|
||||
|
||||
if (appContext != nullptr)
|
||||
{
|
||||
auto* env = getEnv();
|
||||
|
||||
LocalRef<jobject> cacheFile (env->CallObjectMethod (appContext.get(), AndroidContext.getCacheDir));
|
||||
LocalRef<jstring> jPath ((jstring) env->CallObjectMethod (cacheFile.get(), JavaFile.getAbsolutePath));
|
||||
|
||||
return File (juceString (env, jPath.get()));
|
||||
}
|
||||
|
||||
jassertfalse;
|
||||
return File();
|
||||
} ();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static HashMap<String, File>& getInMemoryFontCache()
|
||||
{
|
||||
static HashMap<String, File> cache;
|
||||
return cache;
|
||||
}
|
||||
|
||||
static File getCacheFileForData (const void* data, size_t size)
|
||||
{
|
||||
static CriticalSection cs;
|
||||
JNIEnv* const env = getEnv();
|
||||
|
||||
String key;
|
||||
{
|
||||
LocalRef<jobject> digest (env->CallStaticObjectMethod (JavaMessageDigest, JavaMessageDigest.getInstance, javaString("MD5").get()));
|
||||
LocalRef<jbyteArray> bytes(env->NewByteArray(size));
|
||||
|
||||
jboolean ignore;
|
||||
auto* jbytes = env->GetByteArrayElements(bytes.get(), &ignore);
|
||||
memcpy(jbytes, data, size);
|
||||
env->ReleaseByteArrayElements(bytes.get(), jbytes, 0);
|
||||
|
||||
env->CallVoidMethod(digest.get(), JavaMessageDigest.update, bytes.get());
|
||||
LocalRef<jbyteArray> result((jbyteArray) env->CallObjectMethod(digest.get(), JavaMessageDigest.digest));
|
||||
|
||||
auto* md5Bytes = env->GetByteArrayElements(result.get(), &ignore);
|
||||
key = String::toHexString(md5Bytes, env->GetArrayLength(result.get()), 0);
|
||||
env->ReleaseByteArrayElements(result.get(), md5Bytes, 0);
|
||||
}
|
||||
|
||||
ScopedLock lock (cs);
|
||||
auto& mapEntry = getInMemoryFontCache().getReference (key);
|
||||
|
||||
if (mapEntry == File())
|
||||
{
|
||||
mapEntry = getCacheDirectory().getChildFile ("bindata_" + key);
|
||||
mapEntry.replaceWithData (data, size);
|
||||
}
|
||||
|
||||
return mapEntry;
|
||||
}
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AndroidTypeface)
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user