blob: 57823129e15fa4063c55534df0001e2fd8e5d340 [file] [log] [blame]
Raph Levien1a73f7322014-01-30 16:06:28 -08001/*
2 * Copyright (C) 2014 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#define LOG_TAG "Minikin"
18
19#include "JNIHelp.h"
20#include <android_runtime/AndroidRuntime.h>
21
22#include "SkTypeface.h"
23#include "GraphicsJNI.h"
24#include <ScopedPrimitiveArray.h>
25#include <ScopedUtfChars.h>
26
27#ifdef USE_MINIKIN
28#include <minikin/FontFamily.h>
29#include "MinikinSkia.h"
30#endif
31
32namespace android {
33
34static jlong FontFamily_create(JNIEnv* env, jobject clazz) {
35#ifdef USE_MINIKIN
36 return (jlong)new FontFamily();
37#else
38 return 0;
39#endif
40}
41
42static void FontFamily_destroy(JNIEnv* env, jobject clazz, jlong ptr) {
43 // TODO: work out lifetime issues
44}
45
46static jboolean FontFamily_addFont(JNIEnv* env, jobject clazz, jlong familyPtr, jstring path) {
47#ifdef USE_MINIKIN
48 NPE_CHECK_RETURN_ZERO(env, path);
49 ScopedUtfChars str(env, path);
50 ALOGD("addFont %s", str.c_str());
51 SkTypeface* face = SkTypeface::CreateFromFile(str.c_str());
52 MinikinFont* minikinFont = new MinikinFontSkia(face);
53 FontFamily* fontFamily = (FontFamily*)familyPtr;
54 return fontFamily->addFont(minikinFont);
55#else
56 return false;
57#endif
58}
59
60///////////////////////////////////////////////////////////////////////////////
61
62static JNINativeMethod gFontFamilyMethods[] = {
63 { "nCreateFamily", "()J", (void*)FontFamily_create },
64 { "nDestroyFamily", "(J)V", (void*)FontFamily_destroy },
65 { "nAddFont", "(JLjava/lang/String;)Z", (void*)FontFamily_addFont },
66};
67
68int register_android_graphics_FontFamily(JNIEnv* env)
69{
70 return android::AndroidRuntime::registerNativeMethods(env,
71 "android/graphics/FontFamily",
72 gFontFamilyMethods, NELEM(gFontFamilyMethods));
73}
74
75}