• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "graphics_jni_helpers.h"
20 
21 namespace android {
22 namespace {
23 
24 static struct {
25     jmethodID mGet;
26     jmethodID mSize;
27 } gListClassInfo;
28 
29 static struct {
30     jfieldID mTag;
31     jfieldID mStyleValue;
32 } gAxisClassInfo;
33 
34 }  // namespace
35 
size() const36 jint ListHelper::size() const {
37     return mEnv->CallIntMethod(mList, gListClassInfo.mSize);
38 }
39 
get(jint index) const40 jobject ListHelper::get(jint index) const {
41     return mEnv->CallObjectMethod(mList, gListClassInfo.mGet, index);
42 }
43 
getTag() const44 jint AxisHelper::getTag() const {
45     return mEnv->GetIntField(mAxis, gAxisClassInfo.mTag);
46 }
47 
getStyleValue() const48 jfloat AxisHelper::getStyleValue() const {
49     return mEnv->GetFloatField(mAxis, gAxisClassInfo.mStyleValue);
50 }
51 
init_FontUtils(JNIEnv * env)52 void init_FontUtils(JNIEnv* env) {
53     jclass listClass = FindClassOrDie(env, "java/util/List");
54     gListClassInfo.mGet = GetMethodIDOrDie(env, listClass, "get", "(I)Ljava/lang/Object;");
55     gListClassInfo.mSize = GetMethodIDOrDie(env, listClass, "size", "()I");
56 
57     jclass axisClass = FindClassOrDie(env, "android/graphics/fonts/FontVariationAxis");
58     gAxisClassInfo.mTag = GetFieldIDOrDie(env, axisClass, "mTag", "I");
59     gAxisClassInfo.mStyleValue = GetFieldIDOrDie(env, axisClass, "mStyleValue", "F");
60 }
61 
62 }  // namespace android
63