| 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) { |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame^] | 34 | super(id, rs); |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static public Font create(RenderScript rs, Resources res, String fileName, int size) |
| 38 | throws IllegalArgumentException { |
| 39 | |
| 40 | rs.validate(); |
| 41 | try { |
| 42 | int dpi = res.getDisplayMetrics().densityDpi; |
| 43 | int fontId = rs.nFontCreateFromFile(fileName, size, dpi); |
| 44 | |
| 45 | if(fontId == 0) { |
| 46 | throw new IllegalStateException("Load loading a font"); |
| 47 | } |
| 48 | Font rsFont = new Font(fontId, rs); |
| 49 | |
| 50 | return rsFont; |
| 51 | |
| 52 | } catch (Exception e) { |
| 53 | // Ignore |
| 54 | } |
| 55 | |
| 56 | return null; |
| 57 | } |
| 58 | } |