PassRefPtr<SimpleFontData> BinaryDataFontFaceSource::createFontData(const FontDescription& fontDescription)
{
    return SimpleFontData::create(
        m_customPlatformData->fontPlatformData(fontDescription.effectiveFontSize(),
            fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic(),
            fontDescription.orientation()), CustomFontData::create());
}
PassRefPtr<SimpleFontData> SVGRemoteFontFaceSource::createFontData(const FontDescription& fontDescription)
{
    if (!isLoaded())
        return createLoadingFallbackFontData(fontDescription);

    // Parse the external SVG document, and extract the <font> element.
    if (!resource()->ensureSVGFontData())
        return nullptr;

    if (!m_externalSVGFontElement) {
        String fragmentIdentifier;
        size_t start = m_uri.find('#');
        if (start != kNotFound)
            fragmentIdentifier = m_uri.substring(start + 1);
        m_externalSVGFontElement = resource()->getSVGFontById(fragmentIdentifier);
    }

    if (!m_externalSVGFontElement)
        return nullptr;

    // Select first <font-face> child
    if (SVGFontFaceElement* fontFaceElement = Traversal<SVGFontFaceElement>::firstChild(*m_externalSVGFontElement)) {
        return SimpleFontData::create(
            SVGFontData::create(fontFaceElement),
            fontDescription.effectiveFontSize(),
            fontDescription.isSyntheticBold(),
            fontDescription.isSyntheticItalic());
    }
    return nullptr;
}
Example #3
0
PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescription& fontDescription)
{
    if (!isLoaded())
        return createLoadingFallbackFontData(fontDescription);

    if (!m_font->ensureCustomFontData() || m_period == FailurePeriod)
        return nullptr;

    m_histograms.recordFallbackTime(m_font.get());

    return SimpleFontData::create(
        m_font->platformDataFromCustomData(fontDescription.effectiveFontSize(),
            fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic(),
            fontDescription.orientation()), CustomFontData::create());
}
Example #4
0
PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescription& fontDescription)
{
    if (!isLoaded())
        return createLoadingFallbackFontData(fontDescription);

    // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef.
    if (!m_font->ensureCustomFontData())
        return nullptr;

    m_histograms.recordFallbackTime(m_font.get());

    return SimpleFontData::create(
        m_font->platformDataFromCustomData(fontDescription.effectiveFontSize(),
            fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic(),
            fontDescription.orientation(), fontDescription.widthVariant()), CustomFontData::create());
}
Example #5
0
PassRefPtr<SimpleFontData> CSSFontFaceSource::getFontData(const FontDescription& fontDescription)
{
    // If the font hasn't loaded or an error occurred, then we've got nothing.
    if (!isValid())
        return 0;

    if (isLocal()) {
        // We're local. Just return a SimpleFontData from the normal cache.
        // We don't want to check alternate font family names here, so pass true as the checkingAlternateName parameter.
        RefPtr<SimpleFontData> fontData = FontCache::fontCache()->getFontData(fontDescription, m_string, true);
        m_histograms.recordLocalFont(fontData);
        return fontData;
    }

    // See if we have a mapping in our FontData cache.
    AtomicString emptyFontFamily = "";
    FontCacheKey key = fontDescription.cacheKey(emptyFontFamily);

    RefPtr<SimpleFontData>& fontData = m_fontDataTable.add(key.hash(), 0).iterator->value;
    if (fontData)
        return fontData; // No release, because fontData is a reference to a RefPtr that is held in the m_fontDataTable.

    // If we are still loading, then we let the system pick a font.
    if (isLoaded()) {
        if (m_font) {
#if ENABLE(SVG_FONTS)
            if (m_hasExternalSVGFont) {
                // For SVG fonts parse the external SVG document, and extract the <font> element.
                if (!m_font->ensureSVGFontData())
                    return 0;

                if (!m_externalSVGFontElement) {
                    String fragmentIdentifier;
                    size_t start = m_string.find('#');
                    if (start != kNotFound)
                        fragmentIdentifier = m_string.string().substring(start + 1);
                    m_externalSVGFontElement = m_font->getSVGFontById(fragmentIdentifier);
                }

                if (!m_externalSVGFontElement)
                    return 0;

                SVGFontFaceElement* fontFaceElement = 0;

                // Select first <font-face> child
                for (Node* fontChild = m_externalSVGFontElement->firstChild(); fontChild; fontChild = fontChild->nextSibling()) {
                    if (fontChild->hasTagName(SVGNames::font_faceTag)) {
                        fontFaceElement = toSVGFontFaceElement(fontChild);
                        break;
                    }
                }

                if (fontFaceElement) {
                    if (!m_svgFontFaceElement) {
                        // We're created using a CSS @font-face rule, that means we're not associated with a SVGFontFaceElement.
                        // Use the imported <font-face> tag as referencing font-face element for these cases.
                        m_svgFontFaceElement = fontFaceElement;
                    }

                    fontData = SimpleFontData::create(
                        SVGFontData::create(fontFaceElement),
                        fontDescription.effectiveFontSize(),
                        fontDescription.isSyntheticBold(),
                        fontDescription.isSyntheticItalic());
                }
            } else
#endif
            {
                // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef.
                if (!m_font->ensureCustomFontData())
                    return 0;

                fontData = SimpleFontData::create(
                    m_font->platformDataFromCustomData(fontDescription.effectiveFontSize(),
                        fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic(),
                        fontDescription.orientation(), fontDescription.widthVariant()), CustomFontData::create(false));
            }
        } else {
#if ENABLE(SVG_FONTS)
            // In-Document SVG Fonts
            if (m_svgFontFaceElement) {
                fontData = SimpleFontData::create(
                    SVGFontData::create(m_svgFontFaceElement.get()),
                    fontDescription.effectiveFontSize(),
                    fontDescription.isSyntheticBold(),
                    fontDescription.isSyntheticItalic());
            }
#endif
        }
    } else {
        // This temporary font is not retained and should not be returned.
        FontCachePurgePreventer fontCachePurgePreventer;
        SimpleFontData* temporaryFont = FontCache::fontCache()->getNonRetainedLastResortFallbackFont(fontDescription);
        if (!temporaryFont) {
            ASSERT_NOT_REACHED();
            return 0;
        }
        RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(true);
        cssFontData->setCSSFontFaceSource(this);
        fontData = SimpleFontData::create(temporaryFont->platformData(), cssFontData);
    }

    return fontData; // No release, because fontData is a reference to a RefPtr that is held in the m_fontDataTable.
}
Example #6
0
std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(
    const FontDescription& fontDescription,
    const FontFaceCreationParams& creationParams,
    float fontSize) {
  ASSERT(creationParams.creationType() == CreateFontByFamily);

  CString name;
  sk_sp<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 nullptr;

    } 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 nullptr;

    } else {
      return nullptr;
    }
  }

  std::unique_ptr<FontPlatformData> result =
      WTF::wrapUnique(new FontPlatformData(
          tf, name.data(), fontSize,
          (fontDescription.weight() >= FontWeight600 && !tf->isBold()) ||
              fontDescription.isSyntheticBold(),
          ((fontDescription.style() == FontStyleItalic ||
            fontDescription.style() == FontStyleOblique) &&
           !tf->isItalic()) ||
              fontDescription.isSyntheticItalic(),
          fontDescription.orientation()));

  struct FamilyMinSize {
    const wchar_t* family;
    unsigned minSize;
  };
  const static FamilyMinSize minAntiAliasSizeForFont[] = {
      {L"simsun", 11},
      {L"dotum", 12},
      {L"gulim", 12},
      {L"pmingliu", 11},
      {L"pmingliu-extb", 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"dotum",       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;
}