Exemplo n.º 1
0
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family, float fontSize)
{
    CString name;
    RefPtr<SkTypeface> tf = createTypeface(fontDescription, family, name);
    if (!tf)
        return 0;

    // Windows will always give us a valid pointer here, even if the face name
    // is non-existent. We have to double-check and see if the family name was
    // really used.
    // FIXME: Do we need to use predefined fonts "guaranteed" to exist
    // when we're running in layout-test mode?
    if (!typefacesMatchesFamily(tf.get(), family)) {
        return 0;
    }

    FontPlatformData* result = new FontPlatformData(tf,
        name.data(),
        fontSize,
        fontDescription.weight() >= FontWeightBold && !tf->isBold() || fontDescription.isSyntheticBold(),
        fontDescription.italic() && !tf->isItalic() || fontDescription.isSyntheticItalic(),
        fontDescription.orientation(),
        m_useSubpixelPositioning);
    return result;
}
Exemplo n.º 2
0
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const FontFaceCreationParams& creationParams, float fontSize)
{
    ASSERT(creationParams.creationType() == CreateFontByFamily);
    CString name;
    RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name);
    if (!tf)
        return 0;

    // Windows will always give us a valid pointer here, even if the face name
    // is non-existent. We have to double-check and see if the family name was
    // really used.
    // FIXME: Do we need to use predefined fonts "guaranteed" to exist
    // when we're running in layout-test mode?
    if (!typefacesMatchesFamily(tf.get(), creationParams.family())) {
        return 0;
    }

    FontPlatformData* result = new FontPlatformData(tf,
        name.data(),
        fontSize,
        fontDescription.weight() >= FontWeightBold && !tf->isBold() || fontDescription.isSyntheticBold(),
        fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDescription.isSyntheticItalic(),
        fontDescription.orientation(),
        s_useSubpixelPositioning);

    struct FamilyMinSize {
        const wchar_t* family;
        unsigned minSize;
    };
    const static FamilyMinSize minAntiAliasSizeForFont[] = {
        { L"simsun", 16 },
        { L"dotum", 12 },
        { L"gulim", 12 },
        { L"pmingliu", 11 }
    };
    size_t numFonts = WTF_ARRAY_LENGTH(minAntiAliasSizeForFont);
    for (size_t i = 0; i < numFonts; i++) {
        FamilyMinSize entry = minAntiAliasSizeForFont[i];
        if (typefacesMatchesFamily(tf.get(), entry.family)) {
            result->setMinSizeForAntiAlias(entry.minSize);
            break;
        }
    }

    return result;
}
Exemplo n.º 3
0
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const FontFaceCreationParams& creationParams, float fontSize)
{
    ASSERT(creationParams.creationType() == CreateFontByFamily);

    CString name;
    RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name);
    // Windows will always give us a valid pointer here, even if the face name
    // is non-existent. We have to double-check and see if the family name was
    // really used.
    if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) {
        AtomicString adjustedName;
        FontWeight variantWeight;
        FontStretch variantStretch;

        if (typefacesHasWeightSuffix(creationParams.family(), adjustedName,
            variantWeight)) {
            FontFaceCreationParams adjustedParams(adjustedName);
            FontDescription adjustedFontDescription = fontDescription;
            adjustedFontDescription.setWeight(variantWeight);
            tf = createTypeface(adjustedFontDescription, adjustedParams, name);
            if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName))
                return 0;

        } else if (typefacesHasStretchSuffix(creationParams.family(),
            adjustedName, variantStretch)) {
            FontFaceCreationParams adjustedParams(adjustedName);
            FontDescription adjustedFontDescription = fontDescription;
            adjustedFontDescription.setStretch(variantStretch);
            tf = createTypeface(adjustedFontDescription, adjustedParams, name);
            if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName))
                return 0;

        } else {
            return 0;
        }
    }

    FontPlatformData* result = new FontPlatformData(tf,
        name.data(),
        fontSize,
        fontDescription.weight() >= FontWeight600 && !tf->isBold() || fontDescription.isSyntheticBold(),
        fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDescription.isSyntheticItalic(),
        fontDescription.orientation(),
        s_useSubpixelPositioning);

    struct FamilyMinSize {
        const wchar_t* family;
        unsigned minSize;
    };
    const static FamilyMinSize minAntiAliasSizeForFont[] = {
        { L"simsun", 11 },
        { L"dotum", 12 },
        { L"gulim", 12 },
        { L"pmingliu", 11 }
    };
    size_t numFonts = WTF_ARRAY_LENGTH(minAntiAliasSizeForFont);
    for (size_t i = 0; i < numFonts; i++) {
        FamilyMinSize entry = minAntiAliasSizeForFont[i];
        if (typefacesMatchesFamily(tf.get(), entry.family)) {
            result->setMinSizeForAntiAlias(entry.minSize);
            break;
        }
    }

    // List of fonts that look bad with subpixel text rendering at smaller font
    // sizes. This includes all fonts in the Microsoft Core fonts for the Web
    // collection.
    const static wchar_t* noSubpixelForSmallSizeFont[] = {
        L"andale mono",
        L"arial",
        L"comic sans",
        L"courier new",
        L"georgia",
        L"impact",
        L"lucida console",
        L"tahoma",
        L"times new roman",
        L"trebuchet ms",
        L"verdana",
        L"webdings"
    };
    const static float minSizeForSubpixelForFont = 16.0f;
    numFonts = WTF_ARRAY_LENGTH(noSubpixelForSmallSizeFont);
    for (size_t i = 0; i < numFonts; i++) {
        const wchar_t* family = noSubpixelForSmallSizeFont[i];
        if (typefacesMatchesFamily(tf.get(), family)) {
            result->setMinSizeForSubpixel(minSizeForSubpixelForFont);
            break;
        }
    }

    return result;
}