1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "FontUtils.h"
18 
19 #include <nativehelper/JNIHelp.h>
20 #include <core_jni_helpers.h>
21 
22 namespace android {
23 namespace {
24 
25 static struct {
26     jmethodID mGet;
27     jmethodID mSize;
28 } gListClassInfo;
29 
30 static struct {
31     jfieldID mTag;
32     jfieldID mStyleValue;
33 } gAxisClassInfo;
34 
35 }  // namespace
36 
size() const37 jint ListHelper::size() const {
38     return mEnv->CallIntMethod(mList, gListClassInfo.mSize);
39 }
40 
get(jint index) const41 jobject ListHelper::get(jint index) const {
42     return mEnv->CallObjectMethod(mList, gListClassInfo.mGet, index);
43 }
44 
getTag() const45 jint AxisHelper::getTag() const {
46     return mEnv->GetIntField(mAxis, gAxisClassInfo.mTag);
47 }
48 
getStyleValue() const49 jfloat AxisHelper::getStyleValue() const {
50     return mEnv->GetFloatField(mAxis, gAxisClassInfo.mStyleValue);
51 }
52 
init_FontUtils(JNIEnv * env)53 void init_FontUtils(JNIEnv* env) {
54     jclass listClass = FindClassOrDie(env, "java/util/List");
55     gListClassInfo.mGet = GetMethodIDOrDie(env, listClass, "get", "(I)Ljava/lang/Object;");
56     gListClassInfo.mSize = GetMethodIDOrDie(env, listClass, "size", "()I");
57 
58     jclass axisClass = FindClassOrDie(env, "android/graphics/fonts/FontVariationAxis");
59     gAxisClassInfo.mTag = GetFieldIDOrDie(env, axisClass, "mTag", "I");
60     gAxisClassInfo.mStyleValue = GetFieldIDOrDie(env, axisClass, "mStyleValue", "F");
61 }
62 
63 }  // namespace android
64