Skip to content

Commit 563f83f

Browse files
committed
[jni] Wrote function to get caret edges
1 parent ac9b6a0 commit 563f83f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tehreer-android/src/main/jni/ShapingResult.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2016-2018 Muhammad Tayyab Akram
2+
* Copyright (C) 2016-2019 Muhammad Tayyab Akram
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -142,6 +142,31 @@ static jlong getClusterMapPtr(JNIEnv *env, jobject obj, jlong resultHandle)
142142
return reinterpret_cast<jlong>(charToGlyphMapPtr);
143143
}
144144

145+
static void getCaretEdges(JNIEnv *env, jobject obj, jlong resultHandle,
146+
jbooleanArray caretStops, jfloatArray caretEdges)
147+
{
148+
ShapingResult *shapingResult = reinterpret_cast<ShapingResult *>(resultHandle);
149+
SFAlbumRef baseAlbum = shapingResult->sfAlbum();
150+
151+
void *caretEdgesBuffer = env->GetPrimitiveArrayCritical(caretEdges, nullptr);
152+
void *caretStopsBuffer = nullptr;
153+
154+
if (caretStops) {
155+
caretStopsBuffer = env->GetPrimitiveArrayCritical(caretStops, nullptr);
156+
}
157+
158+
SFBoolean *caretStopValues = static_cast<SFBoolean *>(caretStopsBuffer);
159+
SFFloat *caretEdgeValues = static_cast<SFFloat *>(caretEdgesBuffer);
160+
161+
SFFloat advanceScale = shapingResult->sizeByEm();
162+
SFAlbumGetCaretEdges(baseAlbum, caretStopValues, advanceScale, caretEdgeValues);
163+
164+
if (caretStops) {
165+
env->ReleasePrimitiveArrayCritical(caretStops, caretStopsBuffer, 0);
166+
}
167+
env->ReleasePrimitiveArrayCritical(caretEdges, caretEdgesBuffer, 0);
168+
}
169+
145170
static JNINativeMethod JNI_METHODS[] = {
146171
{ "nCreate", "()J", (void *)create },
147172
{ "nDispose", "(J)V", (void *)dispose },
@@ -155,6 +180,7 @@ static JNINativeMethod JNI_METHODS[] = {
155180
{ "nGetGlyphOffsetsPtr", "(J)J", (void *)getGlyphOffsetsPtr },
156181
{ "nGetGlyphAdvancesPtr", "(J)J", (void *)getGlyphAdvancesPtr },
157182
{ "nGetClusterMapPtr", "(J)J", (void *)getClusterMapPtr },
183+
{ "nGetCaretEdges", "(J[Z[F)V", (void *)getCaretEdges },
158184
};
159185

160186
jint register_com_mta_tehreer_sfnt_ShapingResult(JNIEnv *env)

0 commit comments

Comments
 (0)