Font.java revision 9b949fce39f0f39ce9275b71d7c347210775e7a8
1/*
2 * Copyright (C) 2008 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
17package android.renderscript;
18
19import java.io.IOException;
20import java.io.InputStream;
21
22import android.content.res.Resources;
23import android.content.res.AssetManager;
24import android.util.Log;
25import android.util.TypedValue;
26
27/**
28 * @hide
29 *
30 **/
31public class Font extends BaseObj {
32
33    Font(int id, RenderScript rs) {
34        super(rs);
35        mID = id;
36    }
37
38    static public Font create(RenderScript rs, Resources res, String fileName, int size)
39        throws IllegalArgumentException {
40
41        rs.validate();
42        try {
43            int dpi = res.getDisplayMetrics().densityDpi;
44            int fontId = rs.nFontCreateFromFile(fileName, size, dpi);
45
46            if(fontId == 0) {
47                throw new IllegalStateException("Load loading a font");
48            }
49            Font rsFont = new Font(fontId, rs);
50
51            return rsFont;
52
53        } catch (Exception e) {
54            // Ignore
55        }
56
57        return null;
58    }
59}
60