private static bool CheckPagesCounterPresence(CssDeclaration declaration)
        {
            bool pagesCounterPresent = false;

            // MDN: The counters() function can be used with any CSS property, but support for properties other
            // than content is experimental, and support for the type-or-unit parameter is sparse.
            // iText also does not support counter(pages) anywhere else for now
            if (CssConstants.CONTENT.Equals(declaration.GetProperty()))
            {
                CssDeclarationValueTokenizer       tokenizer = new CssDeclarationValueTokenizer(declaration.GetExpression());
                CssDeclarationValueTokenizer.Token token;
                while ((token = tokenizer.GetNextValidToken()) != null)
                {
                    if (token.IsString())
                    {
                        continue;
                    }
                    if (token.GetValue().StartsWith(CssConstants.COUNTERS + "("))
                    {
                        String paramsStr = token.GetValue().JSubstring(CssConstants.COUNTERS.Length + 1, token.GetValue().Length -
                                                                       1);
                        String[] @params = iText.IO.Util.StringUtil.Split(paramsStr, ",");
                        pagesCounterPresent = pagesCounterPresent || CheckCounterFunctionParamsForPagesReferencePresence(@params);
                    }
                    else
                    {
                        if (token.GetValue().StartsWith(CssConstants.COUNTER + "("))
                        {
                            String paramsStr = token.GetValue().JSubstring(CssConstants.COUNTER.Length + 1, token.GetValue().Length -
                                                                           1);
                            String[] @params = iText.IO.Util.StringUtil.Split(paramsStr, ",");
                            pagesCounterPresent = pagesCounterPresent || CheckCounterFunctionParamsForPagesReferencePresence(@params);
                        }
                        else
                        {
                            if (token.GetValue().StartsWith(CssConstants.TARGET_COUNTER + "("))
                            {
                                String paramsStr = token.GetValue().JSubstring(CssConstants.TARGET_COUNTER.Length + 1, token.GetValue().Length
                                                                               - 1);
                                String[] @params = iText.IO.Util.StringUtil.Split(paramsStr, ",");
                                pagesCounterPresent = pagesCounterPresent || (@params.Length >= TARGET_COUNTER_MIN_PARAMS_SIZE && CheckTargetCounterParamsForPageOrPagesReferencePresence
                                                                                  (@params));
                            }
                            else
                            {
                                if (token.GetValue().StartsWith(CssConstants.TARGET_COUNTERS + "("))
                                {
                                    String paramsStr = token.GetValue().JSubstring(CssConstants.TARGET_COUNTERS.Length + 1, token.GetValue().Length
                                                                                   - 1);
                                    String[] @params = iText.IO.Util.StringUtil.Split(paramsStr, ",");
                                    pagesCounterPresent = pagesCounterPresent || (@params.Length >= TARGET_COUNTERS_MIN_PARAMS_SIZE && CheckTargetCounterParamsForPageOrPagesReferencePresence
                                                                                      (@params));
                                }
                            }
                        }
                    }
                }
            }
            return(pagesCounterPresent);
        }
Exemple #2
0
        internal static CssDeclaration ToCss(this ExcelStyle excelStyle)
        {
            var css = new CssDeclaration();

            css["text-align"]       = excelStyle.HorizontalAlignment.ToCssProperty();
            css["background-color"] = excelStyle.Fill.BackgroundColor.ToHexCode();
            css.Update(excelStyle.Font.ToCss());
            css.Update(excelStyle.Border.ToCss());
            return(css);
        }
Exemple #3
0
        internal static CssDeclaration ToCss(this ExcelRow excelRow)
        {
            var css = new CssDeclaration();

            css["height"] = excelRow.Height + "px";

            css.Update(excelRow.Style.ToCss());

            return(css);
        }
 /* (non-Javadoc)
  * @see com.itextpdf.styledxmlparser.css.validate.ICssDeclarationValidator#isValid(com.itextpdf.styledxmlparser.css.CssDeclaration)
  */
 public virtual bool IsValid(CssDeclaration cssDeclaration)
 {
     foreach (ICssDataTypeValidator dTypeValidator in allowedTypes)
     {
         if (dTypeValidator.IsValid(cssDeclaration.GetExpression()))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
        internal static CssDeclaration ToCss(this Border border)
        {
            var css = new CssDeclaration();

            css["border-top"]    = border.Top.ToCssProperty();
            css["border-bottom"] = border.Bottom.ToCssProperty();
            css["border-right"]  = border.Right.ToCssProperty();
            css["border-left"]   = border.Left.ToCssProperty();

            return(css);
        }
Exemple #6
0
        internal static CssDeclaration ToCss(this ExcelStyle excelStyle)
        {
            var css = new CssDeclaration();

            css["text-align"]       = excelStyle.HorizontalAlignment.ToCssProperty();
            css["background-color"] = excelStyle.Fill.BackgroundColor.ToHexCode();
            css["overflow"]         = excelStyle.HorizontalAlignment == ExcelHorizontalAlignment.Fill ? "hidden" : null;
            css["white-space"]      = excelStyle.WrapText ? "normal" : null;
            css.Update(excelStyle.Font.ToCss());
            css.Update(excelStyle.Border.ToCss());
            return(css);
        }
Exemple #7
0
        internal static CssDeclaration ToCss(this ExcelRange excelRange)
        {
            var css = new CssDeclaration();

            if (excelRange.Columns == 1 && excelRange.Rows == 1)
            {
                var excelColumn = excelRange.Worksheet.Column(excelRange.Start.Column);

                css["max-width"] = excelColumn.Width + "em";
                css["width"]     = excelColumn.Width + "em";
                css.Update(excelRange.Style.ToCss());
            }
            return(css);
        }
Exemple #8
0
        internal static CssDeclaration ToCss(this ExcelRange excelRange)
        {
            var css = new CssDeclaration();

            if (excelRange.Columns == 1 && excelRange.Rows == 1)
            {
                var excelColumn = excelRange.Worksheet.Column(excelRange.Start.Column);

                css["max-width"] = excelColumn.Width + "em";
                css["width"]     = excelColumn.Width + "em";
                css["overflow"]  = excelRange.Worksheet.Cells[excelRange.End.Row, excelRange.End.Column + 1].Value != null ? "hidden" : null;

                css.Update(excelRange.Style.ToCss());
            }
            return(css);
        }
Exemple #9
0
        internal static CssDeclaration ToCss(this ExcelFont excelFont)
        {
            var css = new CssDeclaration();

            if (excelFont.Bold)
            {
                css["font-weight"] = "bold";
            }

            css["font-family"] = excelFont.Name;
            css["font-size"]   = excelFont.Size + "pt";

            css["color"] = excelFont.Color.ToHexCode();

            return(css);
        }
Exemple #10
0
        internal static CssDeclaration ToCss(this ExcelRange excelRange)
        {
            var css = new CssDeclaration();

            if (excelRange.Columns == 1 && excelRange.Rows == 1)
            {
                //var excelColumn = excelRange.Worksheet.Column(excelRange.Start.Column);

                //the tables ignore these width anyways
                //css["max-width"] = excelColumn.Width + "em";
                //css["width"] = excelColumn.Width + "em";
                css["overflow"] = excelRange.Worksheet.Cells[excelRange.End.Row, excelRange.End.Column + 1].Value != null ? "hidden" : null;

                css.Update(excelRange.Style.ToCss(excelRange.Worksheet.Dimension.Rows == excelRange.End.Row, excelRange.Worksheet.Dimension.Columns == excelRange.End.Column, excelRange.Merge));
            }
            return(css);
        }
Exemple #11
0
        internal static CssDeclaration ToCss(this ExcelStyle excelStyle, bool isLastRow, bool isLastColumn, bool isMerged)
        {
            var css = new CssDeclaration();

            css["text-align"]       = excelStyle.HorizontalAlignment.ToCssProperty();
            css["background-color"] = excelStyle.Fill.BackgroundColor.ToHexCode();
            css["overflow"]         = excelStyle.HorizontalAlignment == ExcelHorizontalAlignment.Fill ? "hidden" : null;
            css["padding-left"]     = "5px";
            css["padding-right"]    = "5px";

            if (excelStyle.Indent > 0)
            {
                css["padding-left"] = $"{excelStyle.Indent * 10}px";
            }

            css.Update(excelStyle.Font.ToCss());
            css.Update(excelStyle.Border.ToCss(isLastRow, isLastColumn, isMerged));
            return(css);
        }
        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]);
            }
        }
Exemple #13
0
        internal static CssDeclaration ToCss(this Border border, bool isLastRow, bool isLastColumn, bool isMerged)
        {
            var css = new CssDeclaration();

            css["border-top"] = border.Top.ToCssProperty();

            css["border-left"] = border.Left.ToCssProperty();

            //prevent double borders
            if (isLastRow)
            {
                css["border-bottom"] = border.Bottom.ToCssProperty();
            }

            //prevent double borders
            if (isLastColumn || isMerged)
            {
                css["border-right"] = border.Right.ToCssProperty();
            }

            return(css);
        }
        private static bool CheckNonPagesTargetCounterPresence(CssDeclaration declaration)
        {
            bool nonPagesTargetCounterPresent = false;

            if (CssConstants.CONTENT.Equals(declaration.GetProperty()))
            {
                CssDeclarationValueTokenizer       tokenizer = new CssDeclarationValueTokenizer(declaration.GetExpression());
                CssDeclarationValueTokenizer.Token token;
                while ((token = tokenizer.GetNextValidToken()) != null)
                {
                    if (token.IsString())
                    {
                        continue;
                    }
                    if (token.GetValue().StartsWith(CssConstants.TARGET_COUNTER + "("))
                    {
                        String paramsStr = token.GetValue().JSubstring(CssConstants.TARGET_COUNTER.Length + 1, token.GetValue().Length
                                                                       - 1);
                        String[] @params = iText.IO.Util.StringUtil.Split(paramsStr, ",");
                        nonPagesTargetCounterPresent = nonPagesTargetCounterPresent || (@params.Length >= TARGET_COUNTER_MIN_PARAMS_SIZE &&
                                                                                        !CheckTargetCounterParamsForPageOrPagesReferencePresence(@params));
                    }
                    else
                    {
                        if (token.GetValue().StartsWith(CssConstants.TARGET_COUNTERS + "("))
                        {
                            String paramsStr = token.GetValue().JSubstring(CssConstants.TARGET_COUNTERS.Length + 1, token.GetValue().Length
                                                                           - 1);
                            String[] @params = iText.IO.Util.StringUtil.Split(paramsStr, ",");
                            nonPagesTargetCounterPresent = nonPagesTargetCounterPresent || (@params.Length >= TARGET_COUNTERS_MIN_PARAMS_SIZE &&
                                                                                            !CheckTargetCounterParamsForPageOrPagesReferencePresence(@params));
                        }
                    }
                }
            }
            return(nonPagesTargetCounterPresent);
        }
Exemple #15
0
        /* (non-Javadoc)
         * @see com.itextpdf.styledxmlparser.css.CssRuleSet#toString()
         */
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < GetNormalDeclarations().Count; i++)
            {
                if (i > 0)
                {
                    sb.Append(";").Append("\n");
                }
                CssDeclaration declaration = GetNormalDeclarations()[i];
                sb.Append(declaration.ToString());
            }
            for (int i = 0; i < GetImportantDeclarations().Count; i++)
            {
                if (i > 0 || GetNormalDeclarations().Count > 0)
                {
                    sb.Append(";").Append("\n");
                }
                CssDeclaration declaration = GetImportantDeclarations()[i];
                sb.Append(declaration.ToString()).Append(" !important");
            }
            return(sb.ToString());
        }
Exemple #16
0
 public abstract CssPatch Patch(BrowserInfo browser, CssDeclaration declaration);
Exemple #17
0
        public void Act(CssDeclaration declaration)
        {
            var property = this.property.Replace("{0}", side.side);

            declaration.SetValue(property, value);
        }
Exemple #18
0
 public virtual CssPatch GetPatch(CssDeclaration declaration, in BrowserInfo browser)
 public override bool HasPatch(CssDeclaration declaration, in BrowserInfo browser)
Exemple #20
0
 public override CssPatch Patch(BrowserInfo browser, CssDeclaration declaration) => new CssPatch(
     name: browser.Prefix + declaration.Name,
     value: PatchFactory.PatchValue(declaration.Value, browser)
     );
Exemple #21
0
 public void Act(CssDeclaration declaration)
 {
     declaration.SetValue(Name, Value);
 }
        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;
                }
                }
            }
        }
Exemple #23
0
 public void Act(CssDeclaration declaration)
 {
     declaration.SetValue(Name, Value);
 }
Exemple #24
0
 public bool NeedsExpansion(CssDeclaration declaration, in BrowserInfo[]?browsers)
Exemple #25
0
 public void Act(CssDeclaration declaration)
 {
     var property = this.property.Replace("{0}", side.side);
     declaration.SetValue(property, value);
 }
Exemple #26
0
 public Patch Patch(Browser browser, CssDeclaration declaration)
     => new Patch(browser.Prefix + declaration.Name, declaration.Value);
Exemple #27
0
        public virtual Patch GetPatch(Browser browser, CssDeclaration declaration)
        {

            if (PatchValues)
            {
                return CssPatcher.PrefixNameAndValue.Patch(browser, declaration);

            }

            return CssPatcher.PrefixNameAndValue.Patch(browser, declaration);
        }
Exemple #28
0
 public override bool HasPatch(CssDeclaration declaration, Browser browser)
 {
     return CssCursor.NeedsPatch(declaration.Value.ToString(), browser);
   
 }
Exemple #29
0
        public override Patch GetPatch(Browser browser, CssDeclaration declaration)
        {
            return new Patch(declaration.Name, new CssString(browser.Prefix + declaration.Value.ToString()));

        }
 /* (non-Javadoc)
  * @see com.itextpdf.styledxmlparser.css.validate.ICssDeclarationValidator#isValid(com.itextpdf.styledxmlparser.css.CssDeclaration)
  */
 public virtual bool IsValid(CssDeclaration cssDeclaration)
 {
     return(dataTypeValidator.IsValid(cssDeclaration.GetExpression()));
 }
Exemple #31
0
 public virtual bool HasPatch(CssDeclaration declaration, Browser browser)
     => IsPrefixed(browser);
Exemple #32
0
        /// <summary>Checks a CSS declaration.</summary>
        /// <param name="declaration">the CSS declaration</param>
        /// <returns>true, if the validation was successful</returns>
        public static bool CheckDeclaration(CssDeclaration declaration)
        {
            ICssDeclarationValidator validator = DEFAULT_VALIDATORS.Get(declaration.GetProperty());

            return(validator == null || validator.IsValid(declaration));
        }
Exemple #33
0
 public Patch Patch(Browser browser, CssDeclaration declaration)
     => new Patch(browser.Prefix + declaration.Name, CssPatcher.PatchValue(declaration.Value, browser));
Exemple #34
0
 public override CssPatch Patch(BrowserInfo browser, CssDeclaration declaration) => new CssPatch(
     name: browser.Prefix + declaration.Name,
     value: declaration.Value
     );