コード例 #1
0
ファイル: CssBuilder.cs プロジェクト: JackieyLi/AngleSharp
        public CssRule CreateFontFace(CssToken current)
        {
            var token = _tokenizer.Get();
            var rule  = new CssFontFaceRule(_parser);

            if (token.Type != CssTokenType.CurlyBracketOpen)
            {
                return(SkipDeclarations(token));
            }

            FillDeclarations(rule, Factory.Properties.CreateFont);
            return(rule);
        }
コード例 #2
0
        private CssFontFaceRule CreateFontFace(CssFontFaceRule rule, CssToken current)
        {
            var token = NextToken();

            CollectTrivia(ref token);

            if (token.Type != CssTokenType.CurlyBracketOpen)
            {
                SkipDeclarations(token);
                return(null);
            }

            FillDeclarations(rule);
            return(rule);
        }
コード例 #3
0
ファイル: CssBuilder.cs プロジェクト: neelendu/AngleSharp
        public CssRule CreateFontFace(CssToken current)
        {
            var rule  = new CssFontFaceRule(_parser);
            var start = current.Position;
            var token = NextToken();

            _nodes.Push(rule);
            CollectTrivia(ref token);

            if (token.Type == CssTokenType.CurlyBracketOpen)
            {
                var end = FillDeclarations(rule, Factory.Properties.CreateFont);
                rule.SourceCode = CreateView(start, end);
                _nodes.Pop();
                return(rule);
            }

            _nodes.Pop();
            return(SkipDeclarations(token));
        }
コード例 #4
0
        public virtual void ParseBase64SrcTest()
        {
            CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(sourceFolder + "srcs2.css", FileMode.Open
                                                                                , FileAccess.Read));
            CssFontFaceRule fontFaceRule = (CssFontFaceRule)styleSheet.GetStatements()[0];
            CssDeclaration  src          = fontFaceRule.GetProperties()[0];

            NUnit.Framework.Assert.AreEqual("src", src.GetProperty(), "src expected");
            String[] sources = FontFace.SplitSourcesSequence(src.GetExpression());
            NUnit.Framework.Assert.AreEqual(8, sources.Length, "8 sources expected");
            for (int i = 0; i < 6; i++)
            {
                Match m = iText.IO.Util.StringUtil.Match(FontFace.FontFaceSrc.UrlPattern, sources[i]);
                NUnit.Framework.Assert.IsTrue(m.Success, "Expression doesn't match pattern: " + sources[i]);
            }
            for (int i = 6; i < sources.Length; i++)
            {
                Match m = iText.IO.Util.StringUtil.Match(FontFace.FontFaceSrc.UrlPattern, sources[i]);
                NUnit.Framework.Assert.IsFalse(m.Success, "Expression matches pattern (though it shouldn't!): " + sources[
                                                   i]);
            }
        }
コード例 #5
0
        private ICssRule CreateAtRule(ICssStyleSheet sheet, CssToken token)
        {
            if (token.Data.Is(RuleNames.Media))
            {
                var rule = new CssMediaRule(sheet);
                return(CreateMedia(rule, token));
            }
            else if (token.Data.Is(RuleNames.FontFace))
            {
                var rule = new CssFontFaceRule(sheet);
                return(CreateFontFace(rule, token));
            }
            else if (token.Data.Is(RuleNames.Keyframes))
            {
                var rule = new CssKeyframesRule(sheet);
                return(CreateKeyframes(rule, token));
            }
            else if (token.Data.Is(RuleNames.Import))
            {
                var rule = new CssImportRule(sheet);
                return(CreateImport(rule, token));
            }
            else if (token.Data.Is(RuleNames.Charset))
            {
                var rule = new CssCharsetRule(sheet);
                return(CreateCharset(rule, token));
            }
            else if (token.Data.Is(RuleNames.Namespace))
            {
                var rule = new CssNamespaceRule(sheet);
                return(CreateNamespace(rule, token));
            }
            else if (token.Data.Is(RuleNames.Page))
            {
                var rule = new CssPageRule(sheet);
                return(CreatePage(rule, token));
            }
            else if (token.Data.Is(RuleNames.Supports))
            {
                var rule = new CssSupportsRule(sheet);
                return(CreateSupports(rule, token));
            }
            else if (token.Data.Is(RuleNames.ViewPort))
            {
                var rule = new CssViewportRule(sheet);
                return(CreateViewport(rule, token));
            }
            else if (token.Data.Is(RuleNames.Document))
            {
                var rule = new CssDocumentRule(sheet);
                return(CreateDocument(rule, token));
            }
            else if (_options.IsIncludingUnknownRules)
            {
                return(CreateUnknownAtRule(sheet, token));
            }

            RaiseErrorOccurred(CssParseError.UnknownAtRule, token.Position);
            JumpToRuleEnd(ref token);
            return(null);
        }
コード例 #6
0
        public virtual void SrcPropertyTest()
        {
            String        fontSrc    = "web-fonts/droid-serif-invalid.";
            CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(sourceFolder + "srcs.css", FileMode.Open
                                                                                , FileAccess.Read));
            CssFontFaceRule fontFaceRule = (CssFontFaceRule)styleSheet.GetStatements()[0];
            CssDeclaration  src          = fontFaceRule.GetProperties()[0];

            NUnit.Framework.Assert.AreEqual("src", src.GetProperty(), "src expected");
            String[] sources = iText.IO.Util.StringUtil.Split(src.GetExpression(), ",");
            NUnit.Framework.Assert.AreEqual(27, sources.Length, "27 sources expected");
            for (int i = 0; i < sources.Length; i++)
            {
                Match m = iText.IO.Util.StringUtil.Match(FontFace.FontFaceSrc.UrlPattern, sources[i]);
                NUnit.Framework.Assert.IsTrue(m.Success, "Expression doesn't match pattern: " + sources[i]);
                String format  = iText.IO.Util.StringUtil.Group(m, FontFace.FontFaceSrc.FormatGroup);
                String source2 = MessageFormatUtil.Format("{0}({1}){2}", iText.IO.Util.StringUtil.Group(m, FontFace.FontFaceSrc
                                                                                                        .TypeGroup), iText.IO.Util.StringUtil.Group(m, FontFace.FontFaceSrc.UrlGroup), format != null ? MessageFormatUtil
                                                          .Format(" format({0})", format) : "");
                String url = FontFace.FontFaceSrc.Unquote(iText.IO.Util.StringUtil.Group(m, FontFace.FontFaceSrc.UrlGroup)
                                                          );
                NUnit.Framework.Assert.IsTrue(url.StartsWith(fontSrc), "Invalid url: " + url);
                NUnit.Framework.Assert.IsTrue(format == null || FontFace.FontFaceSrc.ParseFormat(format) != FontFace.FontFormat
                                              .None, "Invalid format: " + format);
                NUnit.Framework.Assert.AreEqual(sources[i], source2, "Group check fails: ");
                FontFace.FontFaceSrc fontFaceSrc = FontFace.FontFaceSrc.Create(sources[i]);
                NUnit.Framework.Assert.IsTrue(fontFaceSrc.src.StartsWith(fontSrc), "Invalid url: " + fontSrc);
                String type = "url";
                if (fontFaceSrc.isLocal)
                {
                    type = "local";
                }
                NUnit.Framework.Assert.IsTrue(sources[i].StartsWith(type), "Type '" + type + "' expected: " + sources[i]);
                switch (fontFaceSrc.format)
                {
                case FontFace.FontFormat.OpenType: {
                    NUnit.Framework.Assert.IsTrue(sources[i].Contains("opentype"), "Format " + fontFaceSrc.format + " expected: "
                                                  + sources[i]);
                    break;
                }

                case FontFace.FontFormat.TrueType: {
                    NUnit.Framework.Assert.IsTrue(sources[i].Contains("truetype"), "Format " + fontFaceSrc.format + " expected: "
                                                  + sources[i]);
                    break;
                }

                case FontFace.FontFormat.SVG: {
                    NUnit.Framework.Assert.IsTrue(sources[i].Contains("svg"), "Format " + fontFaceSrc.format + " expected: " +
                                                  sources[i]);
                    break;
                }

                case FontFace.FontFormat.None: {
                    NUnit.Framework.Assert.IsFalse(sources[i].Contains("format("), "Format " + fontFaceSrc.format + " expected: "
                                                   + sources[i]);
                    break;
                }
                }
            }
        }