のねのBlog

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

makeFamilyFromParsed

    262     private static FontFamily makeFamilyFromParsed(FontListParser.Family family) {
    263         FontFamily fontFamily = new FontFamily(family.lang, family.variant);
    264         for (FontListParser.Font font : family.fonts) {
    265             fontFamily.addFontWeightStyle(font.fontName, font.weight, font.isItalic);
    266         }
    267         return fontFamily;
    268     }
     65     public boolean addFontWeightStyle(String path, int weight, boolean style) {
     66         return nAddFontWeightStyle(mNativePtr, path, weight, style);
     67     }
     68 
  117 static JNINativeMethod gFontFamilyMethods[] = {
    118     { "nCreateFamily",         "(Ljava/lang/String;I)J", (void*)FontFamily_create },
    119     { "nUnrefFamily",          "(J)V", (void*)FontFamily_unref },
    120     { "nAddFont",              "(JLjava/lang/String;)Z", (void*)FontFamily_addFont },
    121     { "nAddFontWeightStyle",   "(JLjava/lang/String;IZ)Z", (void*)FontFamily_addFontWeightStyle },
    122     { "nAddFontFromAsset",     "(JLandroid/content/res/AssetManager;Ljava/lang/String;)Z",
    123                                            (void*)FontFamily_addFontFromAsset },
    124 };
    125 
     69 static jboolean FontFamily_addFontWeightStyle(JNIEnv* env, jobject clazz, jlong familyPtr,
     70         jstring path, jint weight, jboolean isItalic) {
     71     NPE_CHECK_RETURN_ZERO(env, path);
     72     ScopedUtfChars str(env, path);
     73     SkTypeface* face = SkTypeface::CreateFromFile(str.c_str());
     74     if (face == NULL) {
     75         ALOGE("addFont failed to create font %s", str.c_str());
     76         return false;
     77     }
     78     FontFamily* fontFamily = reinterpret_cast<FontFamily*>(familyPtr);
     79     MinikinFont* minikinFont = new MinikinFontSkia(face);
     80     fontFamily->addFont(minikinFont, FontStyle(weight / 100, isItalic));
     81     minikinFont->Unref();
     82     return true;
     83 }
    124 void FontFamily::addFont(MinikinFont* typeface, FontStyle style) {
    125     AutoMutex _l(gMinikinLock);
    126     addFontLocked(typeface, style);
    127 }
    129 void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) {    typeface->RefLocked();
    130     mFonts.push_back( Font(typeface, style) );
    131 }
    145     class Font {
    146     public:
    147         Font(MinikinFont* typeface, FontStyle style) :
    148             typeface(typeface), style(style) { }

    149         MinikinFont* typeface;
    150         FontStyle style;
    151     };