Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame^] | 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 | |
| 17 | package android.renderscript; |
| 18 | |
| 19 | import java.io.IOException; |
| 20 | import java.io.InputStream; |
| 21 | |
| 22 | import android.content.res.Resources; |
| 23 | import android.content.res.AssetManager; |
| 24 | import android.util.Log; |
| 25 | import android.util.TypedValue; |
| 26 | |
| 27 | /** |
| 28 | * @hide |
| 29 | * |
| 30 | **/ |
| 31 | public 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 | } |