Exemplo n.º 1
0
// This installs a default typeface (from a hardcoded path) that allows
// layouts to work (not crash on null pointer) before the default
// typeface is set.
// TODO: investigate why layouts are being created before Typeface.java
// class initialization.
static FontCollection *makeFontCollection() {
    std::vector<FontFamily *>typefaces;
    const char *fns[] = {
        "/system/fonts/Roboto-Regular.ttf",
    };

    FontFamily *family = new FontFamily();
    for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) {
        const char *fn = fns[i];
        ALOGD("makeFontCollection adding %s", fn);
        SkTypeface *skFace = SkTypeface::CreateFromFile(fn);
        if (skFace != NULL) {
            // TODO: might be a nice optimization to get access to the underlying font
            // data, but would require us opening the file ourselves and passing that
            // to the appropriate Create method of SkTypeface.
            MinikinFont *font = new MinikinFontSkia(skFace, NULL, 0, 0);
            family->addFont(font);
            font->Unref();
        } else {
            ALOGE("failed to create font %s", fn);
        }
    }
    typefaces.push_back(family);

    FontCollection *result = new FontCollection(typefaces);
    family->Unref();
    return result;
}
Exemplo n.º 2
0
static Boolean addSkTypeface(
    /* [in] */ android::FontFamily* family,
    /* [in] */ SkTypeface* face)
{
    MinikinFont* minikinFont = new MinikinFontSkia(face);
    bool result = family->addFont(minikinFont);
    minikinFont->Unref();
    return result ? TRUE : FALSE;
}
Exemplo n.º 3
0
Boolean FontFamily::NativeAddFontWeightStyle(
    /* [in] */ Int64 familyPtr,
    /* [in] */ const String& path,
    /* [in] */ Int32 weight,
    /* [in] */ Boolean isItalic)
{
    if (path.IsNull()) {
        return FALSE;
    }
    SkTypeface* face = SkTypeface::CreateFromFile(path.string());
    if (face == NULL) {
        Logger::E(String("FontFamily"), String("addFont failed to create font %s"), path.string());
        return FALSE;
    }
    android::FontFamily* fontFamily = reinterpret_cast<android::FontFamily*>(familyPtr);
    MinikinFont* minikinFont = new MinikinFontSkia(face);
    fontFamily->addFont(minikinFont, android::FontStyle(weight / 100, isItalic));
    minikinFont->Unref();
    return TRUE;
}