Example #1
0
            /// <summary>
            /// Gets or sets font family.
            /// </summary>
            /// <param name="value">New value.</param>
            /// <returns>Value.</returns>
            private string QueryFontFamily(string value = null)
            {
                int        trimIndex  = -1;
                Property   prop       = null;
                StyleRule  rule       = null;
                string     ret        = string.Empty;
                ImportRule fontImport = null;

                rule = _stylesheet.Rules.OfType <StyleRule>()
                       .Where(r => string.Compare(r.Selector.ToString(), string.Concat(".theme-", _id), true) == 0)
                       .FirstOrDefault();

                if (rule != null)
                {
                    prop = rule.Declarations.Where(d => string.Compare(d.Name, "font-family", true) == 0)
                           .FirstOrDefault();

                    if (prop != null)
                    {
                        // Removing everyting except of the font name itself (assuming sans-serif).

                        ret       = value != null ? value : prop.Term.ToString();
                        trimIndex = ret.IndexOf('\'');

                        if (trimIndex < 0)
                        {
                            trimIndex = ret.IndexOf(' ');
                        }

                        if (trimIndex > 0)
                        {
                            ret = ret.Substring(0, trimIndex).Trim('\'').Trim();
                        }

                        if (value != null)
                        {
                            rule.Declarations.Add(NewProperty("font-family", string.Format("'{0}', sans-serif", value)));

                            _stylesheet.Rules.OfType <ImportRule>().ToList().ForEach(ir => {
                                if (ir.Href.ToLowerInvariant().IndexOf("fonts.googleapis.com") >= 0)
                                {
                                    _stylesheet.Rules.Remove(ir);
                                }
                            });

                            fontImport          = new ImportRule();
                            fontImport.RuleType = RuleType.Import;
                            fontImport.Href     = string.Format("http://fonts.googleapis.com/css?family={0}", HttpUtility.UrlEncode(value));

                            _stylesheet.Rules.Add(fontImport);
                        }
                    }
                }

                return(ret);
            }
Example #2
0
        static ImportRule NewImportRule(string cssText)
        {
            var parser = new StylesheetParser();
            var rule   = new ImportRule(parser)
            {
                Text = cssText
            };

            return(rule);
        }
Example #3
0
        private bool ParseImport(Block token)
        {
            if (token.GrammarSegment == GrammarSegment.String || token.GrammarSegment == GrammarSegment.Url)
            {
                ImportRule importRule = CastRuleSet <ImportRule>();
                importRule.Href = ((StringBlock)token).Value;
                SetParsingContext(ParsingContext.InMediaList);
                _styleSheet.AddExternalUrl(importRule.Href);
                return(true);
            }

            SetParsingContext(ParsingContext.AfterInstruction);

            return(false);
        }
 public ImportRuleReference(Parser parser, ImportRule importRule)
     : base(new ReferenceArgs(parser, ReferenceKind.ExternalResource))
 {
     _importRule = importRule;
 }
Example #5
0
        public CssRule ReadImportRule()
        {
            var value = ReadValueList();

            var rule = new ImportRule(CssUrlValue.Parse(value.ToString()));

            if (current.Kind == TokenKind.Semicolon)
            {
                Read();
            }

            rule.Trailing = ReadTrivia();

            return rule;
        }
Example #6
0
 public void Initialize()
 {
     _rule = RuleFactory.RejectOldEntriesWithLowSeverity(TimeSpan.FromDays(7));
 }