のねのBlog

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

DEFAULT_BOLDとDEFAULTの違い

    182     static {
    183         DEFAULT         = create((String) null, 0);
    184         DEFAULT_BOLD    = create((String) null, Typeface.BOLD);
    185         SANS_SERIF      = create("sans-serif", 0);
    186         SERIF           = create("serif", 0);
    187         MONOSPACE       = create("monospace", 0);
    188 
    189         sDefaults = new Typeface[] {
    190             DEFAULT,
    191             DEFAULT_BOLD,
    192             create((String) null, Typeface.ITALIC),
    193             create((String) null, Typeface.BOLD_ITALIC),
    194         };
    195     }
     91     /**
     92      * Create a typeface object that best matches the specified existing
     93      * typeface and the specified Style. Use this call if you want to pick a new
     94      * style from the same family of an existing typeface object. If family is
     95      * null, this selects from the default font's family.
     96      *
     97      * @param family May be null. The name of the existing type face.
     98      * @param style  The style (normal, bold, italic) of the typeface.
     99      *               e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC
    100      * @return The best matching typeface.
    101      */
    102     public static Typeface create(Typeface family, int style) {
    103         int ni = 0;
    104         if (family != null) {
    105             // Return early if we're asked for the same face/style
    106             if (family.mStyle == style) {
    107                 return family;
    108             }
    109 
    110             ni = family.native_instance;
    111         }
    112 
    113         Typeface typeface;
    114         SparseArray<Typeface> styles = sTypefaceCache.get(ni);
    115 
    116         if (styles != null) {
    117             typeface = styles.get(style);
    118             if (typeface != null) {
    119                 return typeface;
    120             }
    121         }
    122 
    123         typeface = new Typeface(nativeCreateFromTypeface(ni, style));
    124         if (styles == null) {
    125             styles = new SparseArray<Typeface>(4);
    126             sTypefaceCache.put(ni, styles);
    127         }
    128         styles.put(style, typeface);
    129 
    130         return typeface;
    131     }
 171 static JNINativeMethod gTypefaceMethods[] = {
    172     { "nativeCreate",        "(Ljava/lang/String;I)I", (void*)Typeface_create },
    173     { "nativeCreateFromTypeface", "(II)I", (void*)Typeface_createFromTypeface },
    174     { "nativeUnref",              "(I)V",  (void*)Typeface_unref },
    175     { "nativeGetStyle",           "(I)I",  (void*)Typeface_getStyle },
    176     { "nativeCreateFromAsset",    "(Landroid/content/res/AssetManager;Ljava/lang/String;)I",
    177                                            (void*)Typeface_createFromAsset },
    178     { "nativeCreateFromFile",     "(Ljava/lang/String;)I",
    179                                            (void*)Typeface_createFromFile },
    180     { "setGammaForText", "(FF)V", (void*)Typeface_setGammaForText },
    181 };
     44 static SkTypeface* Typeface_createFromTypeface(JNIEnv* env, jobject, SkTypeface* family, int style) {
     45     return SkTypeface::CreateFromTypeface(family, (SkTypeface::Style)style);
     46 }
     73 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
     74     return SkFontHost::CreateTypeface(family, NULL, NULL, 0, s);
     75 }