Beispiel #1
0
PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescription& fontDescription, UChar32 c, const SimpleFontData*)
{
    AtomicString familyName = getFamilyNameForCharacter(c, fontDescription.script());
    if (familyName.isEmpty())
        return getLastResortFallbackFont(fontDescription, DoNotRetain);
    return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, FontFaceCreationParams(familyName)), DoNotRetain);
}
PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescription& fontDescription, UChar32 c, const SimpleFontData*, FontFallbackPriority fallbackPriority)
{
    RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
    AtomicString familyName = getFamilyNameForCharacter(fm.get(), c, fontDescription, fallbackPriority);
    if (familyName.isEmpty())
        return getLastResortFallbackFont(fontDescription, DoNotRetain);
    return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, FontFaceCreationParams(familyName)), DoNotRetain);
}
Beispiel #3
0
PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescription& fontDescription, UChar32 c, const SimpleFontData*)
{
    // First try the specified font with standard style & weight.
    if (fontDescription.style() == FontStyleItalic
        || fontDescription.weight() >= FontWeight600) {
        RefPtr<SimpleFontData> fontData = fallbackOnStandardFontStyle(
            fontDescription, c);
        if (fontData)
            return fontData;
    }

    FontCache::PlatformFallbackFont fallbackFont;
    FontCache::getFontForCharacter(c, fontDescription.locale().ascii().data(), &fallbackFont);
    if (fallbackFont.name.isEmpty())
        return nullptr;

    FontFaceCreationParams creationParams;
    creationParams = FontFaceCreationParams(fallbackFont.filename, fallbackFont.fontconfigInterfaceId, fallbackFont.ttcIndex);

    // Changes weight and/or italic of given FontDescription depends on
    // the result of fontconfig so that keeping the correct font mapping
    // of the given character. See http://crbug.com/32109 for details.
    bool shouldSetSyntheticBold = false;
    bool shouldSetSyntheticItalic = false;
    FontDescription description(fontDescription);
    if (fallbackFont.isBold && description.weight() < FontWeightBold)
        description.setWeight(FontWeightBold);
    if (!fallbackFont.isBold && description.weight() >= FontWeightBold) {
        shouldSetSyntheticBold = true;
        description.setWeight(FontWeightNormal);
    }
    if (fallbackFont.isItalic && description.style() == FontStyleNormal)
        description.setStyle(FontStyleItalic);
    if (!fallbackFont.isItalic && description.style() == FontStyleItalic) {
        shouldSetSyntheticItalic = true;
        description.setStyle(FontStyleNormal);
    }

    FontPlatformData* substitutePlatformData = getFontPlatformData(description, creationParams);
    if (!substitutePlatformData)
        return nullptr;
    FontPlatformData platformData = FontPlatformData(*substitutePlatformData);
    platformData.setSyntheticBold(shouldSetSyntheticBold);
    platformData.setSyntheticItalic(shouldSetSyntheticItalic);
    return fontDataFromFontPlatformData(&platformData, DoNotRetain);
}
Beispiel #4
0
PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle(
    const FontDescription& fontDescription,
    UChar32 character) {
  FontDescription substituteDescription(fontDescription);
  substituteDescription.setStyle(FontStyleNormal);
  substituteDescription.setWeight(FontWeightNormal);

  FontFaceCreationParams creationParams(
      substituteDescription.family().family());
  FontPlatformData* substitutePlatformData =
      getFontPlatformData(substituteDescription, creationParams);
  if (substitutePlatformData &&
      substitutePlatformData->fontContainsCharacter(character)) {
    FontPlatformData platformData = FontPlatformData(*substitutePlatformData);
    platformData.setSyntheticBold(fontDescription.weight() >= FontWeight600);
    platformData.setSyntheticItalic(
        fontDescription.style() == FontStyleItalic ||
        fontDescription.style() == FontStyleOblique);
    return fontDataFromFontPlatformData(&platformData, DoNotRetain);
  }

  return nullptr;
}
Beispiel #5
0
// Given the desired base font, this will create a SimpleFontData for a specific
// font that can be used to render the given range of characters.
PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescription& fontDescription, UChar32 character, const SimpleFontData*)
{
    // FIXME: Consider passing fontDescription.dominantScript()
    // to GetFallbackFamily here.
    UScriptCode script;
    const wchar_t* family = getFallbackFamily(character,
        fontDescription.genericFamily(),
        &script,
        m_fontManager.get());
    FontPlatformData* data = 0;
    if (family) {
        FontFaceCreationParams createByFamily(AtomicString(family, wcslen(family)));
        data = getFontPlatformData(fontDescription, createByFamily);
    }

    // Last resort font list : PanUnicode. CJK fonts have a pretty
    // large repertoire. Eventually, we need to scan all the fonts
    // on the system to have a Firefox-like coverage.
    // Make sure that all of them are lowercased.
    const static wchar_t* const cjkFonts[] = {
        L"arial unicode ms",
        L"ms pgothic",
        L"simsun",
        L"gulim",
        L"pmingliu",
        L"wenquanyi zen hei", // Partial CJK Ext. A coverage but more widely known to Chinese users.
        L"ar pl shanheisun uni",
        L"ar pl zenkai uni",
        L"han nom a", // Complete CJK Ext. A coverage.
        L"code2000" // Complete CJK Ext. A coverage.
        // CJK Ext. B fonts are not listed here because it's of no use
        // with our current non-BMP character handling because we use
        // Uniscribe for it and that code path does not go through here.
    };

    const static wchar_t* const commonFonts[] = {
        L"tahoma",
        L"arial unicode ms",
        L"lucida sans unicode",
        L"microsoft sans serif",
        L"palatino linotype",
        // Six fonts below (and code2000 at the end) are not from MS, but
        // once installed, cover a very wide range of characters.
        L"dejavu serif",
        L"dejavu sasns",
        L"freeserif",
        L"freesans",
        L"gentium",
        L"gentiumalt",
        L"ms pgothic",
        L"simsun",
        L"gulim",
        L"pmingliu",
        L"code2000"
    };

    const wchar_t* const* panUniFonts = 0;
    int numFonts = 0;
    if (script == USCRIPT_HAN) {
        panUniFonts = cjkFonts;
        numFonts = WTF_ARRAY_LENGTH(cjkFonts);
    } else {
        panUniFonts = commonFonts;
        numFonts = WTF_ARRAY_LENGTH(commonFonts);
    }
    // Font returned from getFallbackFamily may not cover |character|
    // because it's based on script to font mapping. This problem is
    // critical enough for non-Latin scripts (especially Han) to
    // warrant an additional (real coverage) check with fontCotainsCharacter.
    int i;
    for (i = 0; (!data || !fontContainsCharacter(data, family, character)) && i < numFonts; ++i) {
        family = panUniFonts[i];
        FontFaceCreationParams createByFamily(AtomicString(family, wcslen(family)));
        data = getFontPlatformData(fontDescription, createByFamily);
    }

    // When i-th font (0-base) in |panUniFonts| contains a character and
    // we get out of the loop, |i| will be |i + 1|. That is, if only the
    // last font in the array covers the character, |i| will be numFonts.
    // So, we have to use '<=" rather than '<' to see if we found a font
    // covering the character.
    if (i <= numFonts)
        return fontDataFromFontPlatformData(data, DoNotRetain);

    return nullptr;
}
Beispiel #6
0
// Given the desired base font, this will create a SimpleFontData for a specific
// font that can be used to render the given range of characters.
PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(
    const FontDescription& fontDescription,
    UChar32 character,
    const SimpleFontData* originalFontData,
    FontFallbackPriority fallbackPriority) {
  // First try the specified font with standard style & weight.
  if (fallbackPriority != FontFallbackPriority::EmojiEmoji &&
      (fontDescription.style() == FontStyleItalic ||
       fontDescription.weight() >= FontWeightBold)) {
    RefPtr<SimpleFontData> fontData =
        fallbackOnStandardFontStyle(fontDescription, character);
    if (fontData)
      return fontData;
  }

  UScriptCode script;
  const wchar_t* family = getFallbackFamily(
      character, fontDescription.genericFamily(), fontDescription.locale(),
      &script, fallbackPriority, m_fontManager.get());
  FontPlatformData* data = nullptr;
  if (family) {
    FontFaceCreationParams createByFamily(AtomicString(family, wcslen(family)));
    data = getFontPlatformData(fontDescription, createByFamily);
  }

  if ((!data || !data->fontContainsCharacter(character)) &&
      s_useSkiaFontFallback) {
    const char* bcp47Locale = nullptr;
    int localeCount = 0;
    // If the font description has a locale, use that. Otherwise, Skia will
    // fall back on the user's default locale.
    // TODO(kulshin): extract locale fallback logic from
    //   FontCacheAndroid.cpp and share that code
    if (fontDescription.locale()) {
      bcp47Locale = fontDescription.locale()->localeForSkFontMgr();
      localeCount = 1;
    }

    CString familyName = fontDescription.family().family().utf8();

    SkTypeface* typeface = m_fontManager->matchFamilyStyleCharacter(
        familyName.data(), fontDescription.skiaFontStyle(), &bcp47Locale,
        localeCount, character);
    if (typeface) {
      SkString skiaFamily;
      typeface->getFamilyName(&skiaFamily);
      FontFaceCreationParams createByFamily(AtomicString(skiaFamily.c_str()));
      data = getFontPlatformData(fontDescription, createByFamily);
    }
  }

  // Last resort font list : PanUnicode. CJK fonts have a pretty
  // large repertoire. Eventually, we need to scan all the fonts
  // on the system to have a Firefox-like coverage.
  // Make sure that all of them are lowercased.
  const static wchar_t* const cjkFonts[] = {
      L"arial unicode ms", L"ms pgothic", L"simsun", L"gulim", L"pmingliu",
      L"wenquanyi zen hei",  // Partial CJK Ext. A coverage but more widely
                             // known to Chinese users.
      L"ar pl shanheisun uni", L"ar pl zenkai uni",
      L"han nom a",  // Complete CJK Ext. A coverage.
      L"code2000"    // Complete CJK Ext. A coverage.
      // CJK Ext. B fonts are not listed here because it's of no use
      // with our current non-BMP character handling because we use
      // Uniscribe for it and that code path does not go through here.
  };

  const static wchar_t* const commonFonts[] = {
      L"tahoma", L"arial unicode ms", L"lucida sans unicode",
      L"microsoft sans serif", L"palatino linotype",
      // Six fonts below (and code2000 at the end) are not from MS, but
      // once installed, cover a very wide range of characters.
      L"dejavu serif", L"dejavu sasns", L"freeserif", L"freesans", L"gentium",
      L"gentiumalt", L"ms pgothic", L"simsun", L"gulim", L"pmingliu",
      L"code2000"};

  const wchar_t* const* panUniFonts = nullptr;
  int numFonts = 0;
  if (script == USCRIPT_HAN) {
    panUniFonts = cjkFonts;
    numFonts = WTF_ARRAY_LENGTH(cjkFonts);
  } else {
    panUniFonts = commonFonts;
    numFonts = WTF_ARRAY_LENGTH(commonFonts);
  }
  // Font returned from getFallbackFamily may not cover |character|
  // because it's based on script to font mapping. This problem is
  // critical enough for non-Latin scripts (especially Han) to
  // warrant an additional (real coverage) check with fontCotainsCharacter.
  int i;
  for (i = 0;
       (!data || !data->fontContainsCharacter(character)) && i < numFonts;
       ++i) {
    family = panUniFonts[i];
    FontFaceCreationParams createByFamily(AtomicString(family, wcslen(family)));
    data = getFontPlatformData(fontDescription, createByFamily);
  }

  // For font fallback we want to match the subpixel behavior of the original
  // font. Mixing subpixel and non-subpixel in the same text run looks really
  // odd and causes problems with preferred width calculations.
  if (data && originalFontData) {
    const FontPlatformData& platformData = originalFontData->platformData();
    data->setMinSizeForAntiAlias(platformData.minSizeForAntiAlias());
    data->setMinSizeForSubpixel(platformData.minSizeForSubpixel());
  }

  // When i-th font (0-base) in |panUniFonts| contains a character and
  // we get out of the loop, |i| will be |i + 1|. That is, if only the
  // last font in the array covers the character, |i| will be numFonts.
  // So, we have to use '<=" rather than '<' to see if we found a font
  // covering the character.
  if (i <= numFonts)
    return fontDataFromFontPlatformData(data, DoNotRetain);

  return nullptr;
}