blob: 0cf61b9ade89c9af85d1557e59803b30d555703e [file] [log] [blame]
Clara Bayarri04d72ab2017-01-10 09:31:51 -08001/*
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
Steven Moreland60cc6c02017-08-25 15:49:25 -070019#include <nativehelper/JNIHelp.h>
Clara Bayarri04d72ab2017-01-10 09:31:51 -080020#include <core_jni_helpers.h>
21
22namespace android {
23namespace {
24
25static struct {
26 jmethodID mGet;
27 jmethodID mSize;
28} gListClassInfo;
29
30static struct {
31 jfieldID mTag;
32 jfieldID mStyleValue;
33} gAxisClassInfo;
34
35} // namespace
36
37jint ListHelper::size() const {
38 return mEnv->CallIntMethod(mList, gListClassInfo.mSize);
39}
40
41jobject ListHelper::get(jint index) const {
42 return mEnv->CallObjectMethod(mList, gListClassInfo.mGet, index);
43}
44
45jint AxisHelper::getTag() const {
46 return mEnv->GetIntField(mAxis, gAxisClassInfo.mTag);
47}
48
49jfloat AxisHelper::getStyleValue() const {
50 return mEnv->GetFloatField(mAxis, gAxisClassInfo.mStyleValue);
51}
52
53void 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
Seigo Nonakaff551152017-03-28 16:16:41 -070058 jclass axisClass = FindClassOrDie(env, "android/graphics/fonts/FontVariationAxis");
Clara Bayarri04d72ab2017-01-10 09:31:51 -080059 gAxisClassInfo.mTag = GetFieldIDOrDie(env, axisClass, "mTag", "I");
60 gAxisClassInfo.mStyleValue = GetFieldIDOrDie(env, axisClass, "mStyleValue", "F");
61}
62
63} // namespace android