示例#1
0
MutableStylePropertySet* CanvasFontCache::parseFont(const String& fontString)
{
    MutableStylePropertySet* parsedStyle;
    MutableStylePropertyMap::iterator i = m_fetchedFonts.find(fontString);
    if (i != m_fetchedFonts.end()) {
        ASSERT(m_fontLRUList.contains(fontString));
        parsedStyle = i->value;
        m_fontLRUList.remove(fontString);
        m_fontLRUList.add(fontString);
    } else {
        parsedStyle = MutableStylePropertySet::create(HTMLStandardMode);
        CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true, 0);
        if (parsedStyle->isEmpty())
            return nullptr;
        // According to http://lists.w3.org/Archives/Public/public-html/2009Jul/0947.html,
        // the "inherit" and "initial" values must be ignored.
        CSSValue* fontValue = parsedStyle->getPropertyCSSValue(CSSPropertyFontSize);
        if (fontValue && (fontValue->isInitialValue() || fontValue->isInheritedValue()))
            return nullptr;
        m_fetchedFonts.add(fontString, parsedStyle);
        m_fontLRUList.add(fontString);
        // Hard limit is applied here, on the fly, while the soft limit is
        // applied at the end of the task.
        if (m_fetchedFonts.size() > hardMaxFonts()) {
            ASSERT(m_fetchedFonts.size() == hardMaxFonts() + 1);
            ASSERT(m_fontLRUList.size() == hardMaxFonts() + 1);
            m_fetchedFonts.remove(m_fontLRUList.first());
            m_fontsResolvedUsingDefaultStyle.remove(m_fontLRUList.first());
            m_fontLRUList.removeFirst();
        }
    }
    schedulePruningIfNeeded();

    return parsedStyle;
}
示例#2
0
bool FontFaceSet::resolveFontStyle(const String& fontString, Font& font) {
  if (fontString.isEmpty())
    return false;

  // Interpret fontString in the same way as the 'font' attribute of
  // CanvasRenderingContext2D.
  MutableStylePropertySet* parsedStyle =
      MutableStylePropertySet::create(HTMLStandardMode);
  CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true, 0);
  if (parsedStyle->isEmpty())
    return false;

  String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont);
  if (fontValue == "inherit" || fontValue == "initial")
    return false;

  RefPtr<ComputedStyle> style = ComputedStyle::create();

  FontFamily fontFamily;
  fontFamily.setFamily(defaultFontFamily);

  FontDescription defaultFontDescription;
  defaultFontDescription.setFamily(fontFamily);
  defaultFontDescription.setSpecifiedSize(defaultFontSize);
  defaultFontDescription.setComputedSize(defaultFontSize);

  style->setFontDescription(defaultFontDescription);

  style->font().update(style->font().getFontSelector());

  document()->ensureStyleResolver().computeFont(style.get(), *parsedStyle);

  font = style->font();
  font.update(document()->styleEngine().fontSelector());
  return true;
}