コード例 #1
0
FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule(
    CFDE_CSSSyntaxParser* pSyntax,
    CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray) {
  CFDE_CSSFontFaceRule* pFontFaceRule = nullptr;
  const FX_WCHAR* pszValue = nullptr;
  int32_t iValueLen = 0;
  FDE_CSSPROPERTYARGS propertyArgs;
  propertyArgs.pStaticStore = m_pAllocator.get();
  propertyArgs.pStringCache = &m_StringCache;
  propertyArgs.pProperty = nullptr;
  for (;;) {
    switch (pSyntax->DoSyntaxParse()) {
      case FDE_CSSSYNTAXSTATUS_PropertyName:
        pszValue = pSyntax->GetCurrentString(iValueLen);
        propertyArgs.pProperty =
            FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen));
        break;
      case FDE_CSSSYNTAXSTATUS_PropertyValue:
        if (propertyArgs.pProperty) {
          pszValue = pSyntax->GetCurrentString(iValueLen);
          if (iValueLen > 0) {
            pFontFaceRule->GetDeclImp().AddProperty(&propertyArgs, pszValue,
                                                    iValueLen);
          }
        }
        break;
      case FDE_CSSSYNTAXSTATUS_DeclOpen:
        if (!pFontFaceRule) {
          pFontFaceRule =
              FXTARGET_NewWith(m_pAllocator.get()) CFDE_CSSFontFaceRule;
          ruleArray.Add(pFontFaceRule);
        }
        break;
      case FDE_CSSSYNTAXSTATUS_DeclClose:
        return FDE_CSSSYNTAXSTATUS_None;
        FDE_CSSSWITCHDEFAULTS();
    }
  }
}
コード例 #2
0
ファイル: fde_cssstylesheet.cpp プロジェクト: andoma/pdfium
FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule(
    IFDE_CSSSyntaxParser* pSyntax,
    CFDE_CSSRuleArray& ruleArray) {
  m_Selectors.RemoveAt(0, m_Selectors.GetSize());
  CFDE_CSSStyleRule* pStyleRule = NULL;
  const FX_WCHAR* pszValue = NULL;
  int32_t iValueLen = 0;
  FDE_CSSPROPERTYARGS propertyArgs;
  propertyArgs.pStaticStore = m_pAllocator;
  propertyArgs.pStringCache = &m_StringCache;
  propertyArgs.pProperty = NULL;
  CFX_WideString wsName;
  for (;;) {
    switch (pSyntax->DoSyntaxParse()) {
      case FDE_CSSSYNTAXSTATUS_Selector: {
        pszValue = pSyntax->GetCurrentString(iValueLen);
        IFDE_CSSSelector* pSelector =
            CFDE_CSSSelector::FromString(m_pAllocator, pszValue, iValueLen);
        if (pSelector != NULL) {
          m_Selectors.Add(pSelector);
        }
      } break;
      case FDE_CSSSYNTAXSTATUS_PropertyName:
        pszValue = pSyntax->GetCurrentString(iValueLen);
        propertyArgs.pProperty = FDE_GetCSSPropertyByName(pszValue, iValueLen);
        if (propertyArgs.pProperty == NULL) {
          wsName = CFX_WideStringC(pszValue, iValueLen);
        }
        break;
      case FDE_CSSSYNTAXSTATUS_PropertyValue:
        if (propertyArgs.pProperty != NULL) {
          pszValue = pSyntax->GetCurrentString(iValueLen);
          if (iValueLen > 0) {
            pStyleRule->GetDeclImp().AddProperty(&propertyArgs, pszValue,
                                                 iValueLen);
          }
        } else if (iValueLen > 0) {
          pszValue = pSyntax->GetCurrentString(iValueLen);
          if (iValueLen > 0) {
            pStyleRule->GetDeclImp().AddProperty(
                &propertyArgs, wsName, wsName.GetLength(), pszValue, iValueLen);
          }
        }
        break;
      case FDE_CSSSYNTAXSTATUS_DeclOpen:
        if (pStyleRule == NULL && m_Selectors.GetSize() > 0) {
          pStyleRule = FDE_NewWith(m_pAllocator) CFDE_CSSStyleRule;
          pStyleRule->SetSelector(m_pAllocator, m_Selectors);
          ruleArray.Add(pStyleRule);
        } else {
          SkipRuleSet(pSyntax);
          return FDE_CSSSYNTAXSTATUS_None;
        }
        break;
      case FDE_CSSSYNTAXSTATUS_DeclClose:
        if (pStyleRule != NULL &&
            pStyleRule->GetDeclImp().GetStartPosition() == NULL) {
          pStyleRule->~CFDE_CSSStyleRule();
          ruleArray.RemoveLast(1);
        }
        return FDE_CSSSYNTAXSTATUS_None;
        FDE_CSSSWITCHDEFAULTS();
    }
  }
}