のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

native typeface cannot be made

native typeface cannot be madeの流れ

    168     public static Typeface createFromFile(String path) {
    169         return new Typeface(nativeCreateFromFile(path));
    170     }
    172 static JNINativeMethod gTypefaceMethods[] = {
    173     { "nativeCreate",        "(Ljava/lang/String;I)I", (void*)Typeface_create },
    174     { "nativeCreateFromTypeface", "(II)I", (void*)Typeface_createFromTypeface },
    175     { "nativeUnref",              "(I)V",  (void*)Typeface_unref },
    176     { "nativeGetStyle",           "(I)I",  (void*)Typeface_getStyle },
    177     { "nativeCreateFromAsset",    "(Landroid/content/res/AssetManager;Ljava/lang/String;)I",
    178                                            (void*)Typeface_createFromAsset },
    179     { "nativeCreateFromFile",     "(Ljava/lang/String;)I",
    180                                            (void*)Typeface_createFromFile },
    181 };
    162 static SkTypeface* Typeface_createFromFile(JNIEnv* env, jobject, jstring jpath) {
    163     NPE_CHECK_RETURN_ZERO(env, jpath);
    164 
    165     AutoJavaStringToUTF8 str(env, jpath);
    166 
    167     return SkTypeface::CreateFromFile(str.c_str());
    168 }
     93 SkTypeface* SkTypeface::CreateFromFile(const char path[]) {
     94     return SkFontHost::CreateTypefaceFromFile(path);
     95 }
    210 #ifdef SK_FONTHOST_USES_FONTMGR
    236 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
    237     SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
    238     return fm->createFromFile(path);
    239 }
    246 #endif
     70     /**
     71      *  Create a typeface for the specified fileName and TTC index
     72      *  (pass 0 for none) or NULL if the file is not found, or its contents are
     73      *  not recognized. The caller must call unref() on the returned object
     74      *  if it is not null.
     75      */
     76     SkTypeface* createFromFile(const char path[], int ttcIndex = 0);
    178 SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) {
    179     if (NULL == path) {
    180         return NULL;
    181     }
    182     return this->onCreateFromFile(path, ttcIndex);
    183 }
    281     virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) {
    282         SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
    283         return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
    284     }
    171 SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) {
    172     if (NULL == stream) {
    173         return NULL;
    174     }
    175     return this->onCreateFromStream(stream, ttcIndex);
    176 }
    266     virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) {
    267         const size_t length = stream->getLength();
    268         if (!length) {
    269             return NULL;
    270         }
    271         if (length >= 1024 * 1024 * 1024) {
    272             return NULL;  // don't accept too large fonts (>= 1GB) for safety.
    273         }
    274 
    275         // TODO should the caller give us the style or should we get it from freetype?
    276         SkTypeface::Style style = SkTypeface::kNormal;
    277         SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, false, stream));
    278         return face;
    279     }
    172     // don't allow clients to call this directly
    173     private Typeface(int ni) {
    174         if (ni == 0) {
    175             throw new RuntimeException("native typeface cannot be made");
    176         }
    177 
    178         native_instance = ni;
    179         mStyle = nativeGetStyle(ni);
    180     }