private static CSSRule ParseFontFace(AtRule rule, ref string OriginalCss) { CSSFontFaceRule fontrule = new CSSFontFaceRule(); int startindex = 0; int endindex = 0; int endselectindex = -1; foreach (var item in rule.prelude) { if (startindex == 0) { startindex = item.startindex; } if (item.endindex > endselectindex) { endselectindex = item.endindex; } } CSSStyleDeclaration style = ParseDeclarations(rule.block, ref endindex, ref OriginalCss); fontrule.style = style; fontrule.StartIndex = startindex; fontrule.EndIndex = endindex; fontrule.EndSelectorIndex = endselectindex - fontrule.StartIndex + 1; return(fontrule); }
/// <summary> /// Creates a new @font-face-rule from the given source. /// </summary> /// <param name="source">The token iterator.</param> /// <returns>The @font-face-rule.</returns> CSSFontFaceRule CreateFontFaceRule(IEnumerator <CssToken> source) { var fontface = new CSSFontFaceRule(); fontface.ParentStyleSheet = sheet; fontface.ParentRule = CurrentRule; open.Push(fontface); if (source.Current.Type == CssTokenType.CurlyBracketOpen) { if (SkipToNextNonWhitespace(source)) { var tokens = LimitToCurrentBlock(source); AppendDeclarations(tokens.GetEnumerator(), fontface.CssRules.List); } } open.Pop(); return(fontface); }
public static List <CssConvertResult> ConvertCss(CSSRuleList rulelist, Guid ParentStyleId, Guid ParentCssRuleId = default(Guid)) { List <CssConvertResult> Result = new List <CssConvertResult>(); int counter = rulelist.item.Count; for (int i = 0; i < counter; i++) { CmsCssRule cmsrule = new CmsCssRule(); cmsrule.ParentCssRuleId = ParentCssRuleId; cmsrule.ParentStyleId = ParentStyleId; cmsrule.OwnerObjectId = ParentStyleId; cmsrule.OwnerObjectConstType = ConstObjectType.Style; cmsrule.TempCssRuleIndex = i; CSSRule item = rulelist.item[i]; cmsrule.selectorPositionIndex = item.EndSelectorIndex; if (item.type == enumCSSRuleType.STYLE_RULE) { CSSStyleRule stylerule = item as CSSStyleRule; cmsrule.CssText = stylerule.cssText; cmsrule.ruleType = RuleType.StyleRule; cmsrule.Properties = stylerule.style.item.Where(o => o != null && !string.IsNullOrWhiteSpace(o.propertyname)).Select(o => o.propertyname).ToList(); } else if (item.type == enumCSSRuleType.IMPORT_RULE) { CSSImportRule importrule = item as CSSImportRule; cmsrule.CssText = importrule.cssText; cmsrule.ruleType = RuleType.ImportRule; } else if (item.type == enumCSSRuleType.MEDIA_RULE) { CSSMediaRule mediarule = item as CSSMediaRule; cmsrule.CssText = mediarule.cssText; cmsrule.ruleType = RuleType.MediaRule; } else if (item.type == enumCSSRuleType.FONT_FACE_RULE) { CSSFontFaceRule facerule = item as CSSFontFaceRule; cmsrule.CssText = facerule.cssText; cmsrule.ruleType = RuleType.FontFaceRule; } else { continue; } /// check duplicate in the current collections. cmsrule.DuplicateIndex = CssService.GetDuplicateIndex(Result, cmsrule.SelectorText, cmsrule.ruleType); CssConvertResult converted = new CssConvertResult(); converted.RuleId = cmsrule.Id; converted.CmsRule = cmsrule; converted.CssRule = item; Result.Add(converted); if (item.type == enumCSSRuleType.MEDIA_RULE) { var mediarule = item as Kooboo.Dom.CSS.CSSMediaRule; var sub = ConvertCss(mediarule.cssRules, ParentStyleId, cmsrule.Id); if (sub != null && sub.Count() > 0) { Result.AddRange(sub); } } } return(Result); }