Exemplo n.º 1
0
 public Background()
 {
     color=	new Color(255, 255, 255);
     image=	null;
     position=	new FlexiblePoint(0f, 0f);
     repeat=	BackgroundRepeat.repeat;
 }
Exemplo n.º 2
0
 public Background(string color = null, string imageurl = null, Coordinate position = null, BackgroundRepeat repeat = null)
 {
     Color = color;
     ImageUrl = imageurl;
     Position = position;
     Repeat = repeat;
 }
 /// <summary>
 /// Creates a new
 /// <see cref="HtmlBackgroundImage"/>
 /// instance.
 /// </summary>
 /// <param name="xObject">
 /// background-image property.
 /// <see cref="iText.Kernel.Pdf.Xobject.PdfImageXObject"/>
 /// instance.
 /// </param>
 /// <param name="repeat">
 /// background-repeat property.
 /// <see cref="iText.Layout.Properties.BackgroundRepeat"/>
 /// instance.
 /// </param>
 /// <param name="position">
 /// background-position property.
 /// <see cref="iText.Layout.Properties.BackgroundPosition"/>
 /// instance.
 /// </param>
 /// <param name="blendMode">
 /// background-blend-mode property.
 /// <see cref="iText.Layout.Properties.BlendMode"/>
 /// instance.
 /// </param>
 /// <param name="clip">
 /// background-clip property.
 /// <see cref="iText.Layout.Properties.BackgroundBox"/>
 /// instance.
 /// </param>
 /// <param name="origin">
 /// background-origin property.
 /// <see cref="iText.Layout.Properties.BackgroundBox"/>
 /// instance.
 /// </param>
 public HtmlBackgroundImage(PdfImageXObject xObject, BackgroundRepeat repeat, BackgroundPosition position,
                            BlendMode blendMode, BackgroundBox clip, BackgroundBox origin)
     : base(new BackgroundImage.Builder().SetImage(xObject).SetBackgroundRepeat(repeat).SetBackgroundPosition(position
                                                                                                              ).SetBackgroundBlendMode(blendMode).SetBackgroundClip(clip).SetBackgroundOrigin(origin).Build())
 {
     dimensionMultiplier = PX_TO_PT_MULTIPLIER;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="a"></param>
 /// <param name="c"></param>
 /// <param name="i"></param>
 /// <param name="r"></param>
 /// <param name="p"></param>
 public BackgroundStyles(string a, Color c, string i, BackgroundRepeat r, BackgroundPosition p)
 {
     attachment = a;
     color      = c;
     image      = i;
     repeat     = r;
     position   = p;
 }
Exemplo n.º 5
0
 private string ExportRepeat(BackgroundRepeat repeat)
 {
     return(repeat switch
     {
         BackgroundRepeat.Repeat => "repeat",
         BackgroundRepeat.RepeatX => "repeat-x",
         BackgroundRepeat.RepeatY => "repeat-y",
         _ => "no-repeat"
     });
Exemplo n.º 6
0
 protected override void RenderAttributes(XElement element, FoRenderOptions options)
 {
     if (RegionName.HasValue())
     {
         element.Add(new XAttribute("region-name", RegionName));
     }
     if (BackgroundRepeat.HasValue())
     {
         element.Add(new XAttribute("background-repeat", BackgroundRepeat));
     }
     if (BackgroundImage.HasValue())
     {
         element.Add(new XAttribute("background-image", "url(" + BackgroundImage + ")"));
     }
     if (ColumnCount > 0)
     {
         element.Add(new XAttribute("column-count", ColumnCount));
     }
     if (ColumnGap.HasValue())
     {
         element.Add(new XAttribute("column-gap", ColumnGap));
     }
     if (Extent.HasValue())
     {
         element.Add(new XAttribute("extent", Extent));
     }
     if (Margin.HasValue())
     {
         element.Add(new XAttribute("margin", Margin));
     }
     if (MarginTop.HasValue())
     {
         element.Add(new XAttribute("margin-top", MarginTop));
     }
     if (MarginRight.HasValue())
     {
         element.Add(new XAttribute("margin-right", MarginRight));
     }
     if (MarginBottom.HasValue())
     {
         element.Add(new XAttribute("margin-bottom", MarginBottom));
     }
     if (MarginLeft.HasValue())
     {
         element.Add(new XAttribute("margin-left", MarginLeft));
     }
 }
        private static IList <BackgroundImage> GetBackgroundImagesList(IList <String> backgroundImagesArray, ProcessorContext
                                                                       context, float em, float rem, IList <String> backgroundPositionXArray, IList <String> backgroundPositionYArray
                                                                       , IList <IList <String> > backgroundSizeArray, IList <String> backgroundBlendModeArray, IList <String> backgroundRepeatArray
                                                                       , IList <String> backgroundClipArray, IList <String> backgroundOriginArray)
        {
            IList <BackgroundImage> backgroundImagesList = new List <BackgroundImage>();

            for (int i = 0; i < backgroundImagesArray.Count; ++i)
            {
                String backgroundImage = backgroundImagesArray[i];
                if (backgroundImage == null || CssConstants.NONE.Equals(backgroundImage))
                {
                    continue;
                }
                BackgroundPosition position = ApplyBackgroundPosition(backgroundPositionXArray, backgroundPositionYArray,
                                                                      i, em, rem);
                BlendMode        blendMode    = ApplyBackgroundBlendMode(backgroundBlendModeArray, i);
                bool             imageApplied = false;
                BackgroundRepeat repeat       = ApplyBackgroundRepeat(backgroundRepeatArray, i);
                BackgroundBox    clip         = GetBackgroundBoxProperty(backgroundClipArray, i, BackgroundBox.BORDER_BOX);
                BackgroundBox    origin       = GetBackgroundBoxProperty(backgroundOriginArray, i, BackgroundBox.PADDING_BOX);
                if (CssGradientUtil.IsCssLinearGradientValue(backgroundImage))
                {
                    imageApplied = ApplyLinearGradient(backgroundImage, backgroundImagesList, blendMode, position, em, rem, repeat
                                                       , clip, origin);
                }
                else
                {
                    PdfXObject image = context.GetResourceResolver().RetrieveImageExtended(CssUtils.ExtractUrl(backgroundImage
                                                                                                               ));
                    imageApplied = ApplyBackgroundImage(image, backgroundImagesList, repeat, blendMode, position, clip, origin
                                                        );
                }
                if (imageApplied)
                {
                    ApplyBackgroundSize(backgroundSizeArray, em, rem, i, backgroundImagesList[backgroundImagesList.Count - 1]);
                }
            }
            return(backgroundImagesList);
        }
 /// <summary>
 /// Creates a new
 /// <see cref="HtmlBackgroundImage"/>
 /// instance.
 /// </summary>
 /// <param name="xObject">
 /// background-image property.
 /// <see cref="iText.Kernel.Pdf.Xobject.PdfFormXObject"/>
 /// instance.
 /// </param>
 /// <param name="repeat">
 /// background-repeat property.
 /// <see cref="iText.Layout.Properties.BackgroundRepeat"/>
 /// instance.
 /// </param>
 /// <param name="position">
 /// background-position property.
 /// <see cref="iText.Layout.Properties.BackgroundPosition"/>
 /// instance.
 /// </param>
 /// <param name="blendMode">
 /// background-blend-mode property.
 /// <see cref="iText.Layout.Properties.BlendMode"/>
 /// instance.
 /// </param>
 /// <param name="clip">
 /// background-clip property.
 /// <see cref="iText.Layout.Properties.BackgroundBox"/>
 /// instance.
 /// </param>
 /// <param name="origin">
 /// background-origin property.
 /// <see cref="iText.Layout.Properties.BackgroundBox"/>
 /// instance.
 /// </param>
 public HtmlBackgroundImage(PdfFormXObject xObject, BackgroundRepeat repeat, BackgroundPosition position, BlendMode
                            blendMode, BackgroundBox clip, BackgroundBox origin)
     : base(new BackgroundImage.Builder().SetImage(xObject).SetBackgroundRepeat(repeat).SetBackgroundPosition(position
                                                                                                              ).SetBackgroundBlendMode(blendMode).SetBackgroundClip(clip).SetBackgroundOrigin(origin).Build())
 {
 }
 private static bool ApplyLinearGradient(String image, IList <BackgroundImage> backgroundImagesList, BlendMode
                                         blendMode, BackgroundPosition position, float em, float rem, BackgroundRepeat repeat, BackgroundBox clip
                                         , BackgroundBox origin)
 {
     try {
         StrategyBasedLinearGradientBuilder gradientBuilder = CssGradientUtil.ParseCssLinearGradient(image, em, rem
                                                                                                     );
         if (gradientBuilder != null)
         {
             backgroundImagesList.Add(new BackgroundImage.Builder().SetLinearGradientBuilder(gradientBuilder).SetBackgroundBlendMode
                                          (blendMode).SetBackgroundPosition(position).SetBackgroundRepeat(repeat).SetBackgroundClip(clip).SetBackgroundOrigin
                                          (origin).Build());
             return(true);
         }
     }
     catch (StyledXMLParserException) {
         LOGGER.Warn(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.INVALID_GRADIENT_DECLARATION, image
                                              ));
     }
     return(false);
 }
 private static bool ApplyBackgroundImage(PdfXObject image, IList <BackgroundImage> backgroundImagesList, BackgroundRepeat
                                          repeat, BlendMode backgroundBlendMode, BackgroundPosition position, BackgroundBox clip, BackgroundBox
                                          origin)
 {
     if (image == null)
     {
         return(false);
     }
     if (image is PdfImageXObject)
     {
         backgroundImagesList.Add(new BackgroundApplierUtil.HtmlBackgroundImage((PdfImageXObject)image, repeat, position
                                                                                , backgroundBlendMode, clip, origin));
         return(true);
     }
     else
     {
         if (image is PdfFormXObject)
         {
             backgroundImagesList.Add(new BackgroundApplierUtil.HtmlBackgroundImage((PdfFormXObject)image, repeat, position
                                                                                    , backgroundBlendMode, clip, origin));
             return(true);
         }
         else
         {
             throw new InvalidOperationException();
         }
     }
 }
Exemplo n.º 11
0
 public BackgroundImage(Source source, BackgroundRepeat backgroundRepeat, string value)
 {
     _source           = source;
     _backgroundRepeat = backgroundRepeat;
     _value            = value;
 }
Exemplo n.º 12
0
        private static int GetBackgroundPageNumber(int currentDocumentPage, int numberOfBackgroundpages, BackgroundRepeat repeat, int startOffset, int endPage)
        {
            if (currentDocumentPage <= startOffset)
            {
                return(-1);
            }
            if (currentDocumentPage > endPage)
            {
                return(-1);
            }

            switch (repeat)
            {
            case BackgroundRepeat.RepeatAllPages:
                return(((currentDocumentPage - startOffset - 1) % numberOfBackgroundpages) + 1);

            case BackgroundRepeat.RepeatLastPage:
                if ((currentDocumentPage - startOffset) < numberOfBackgroundpages)
                {
                    return(currentDocumentPage - startOffset);
                }
                //else if (currentDocumentPage - startOffset >= numberOfBackgroundpages)
                return(numberOfBackgroundpages);

            case BackgroundRepeat.NoRepetition:
                if ((currentDocumentPage - startOffset) <= numberOfBackgroundpages)
                {
                    return(currentDocumentPage - startOffset);
                }
                //else
                return(-1);
            }
            return(-1); //default
        }
 public BackgroundImage(Source source, BackgroundRepeat backgroundRepeat, string value)
 {
     this.source           = source;
     this.backgroundRepeat = backgroundRepeat;
     this.value            = value;
 }
Exemplo n.º 14
0
 public static T GradientRepeat <T>(this T control, BackgroundRepeat repeat) where T : IGradientControl
 {
     control.GradientRepeat = repeat;
     return(control);
 }
Exemplo n.º 15
0
        public void Render(IOutputStream outputStream)
        {
            outputStream.Write(HTMLElements.m_openDiv);
            if (!string.IsNullOrEmpty(Role))
            {
                outputStream.Write(HTMLElements.m_space);
                outputStream.Write(HTMLElements.m_role);
                outputStream.Write(HTMLElements.m_equal);
                outputStream.Write(HTMLElements.m_quote);
                outputStream.Write(Role);
                outputStream.Write(HTMLElements.m_quote);
            }
            if (!string.IsNullOrEmpty(AriaLabel))
            {
                outputStream.Write(HTMLElements.m_space);
                outputStream.Write(HTMLElements.m_ariaLabel);
                outputStream.Write(HTMLElements.m_equal);
                outputStream.Write(HTMLElements.m_quote);
                outputStream.Write(AntiXssEncoder.XmlAttributeEncode(AriaLabel));
                outputStream.Write(HTMLElements.m_quote);
            }
            string text = string.Empty;

            if (Size != null && Size.Width != null && Size.Width.GetType() == typeof(AutoScaleTo100Percent))
            {
                text = HTMLElements.m_resize100WidthClassName;
            }
            if (Size != null && Size.Height != null && Size.Height.GetType() == typeof(AutoScaleTo100Percent))
            {
                text = text + HTMLElements.m_spaceString + HTMLElements.m_resize100HeightClassName;
            }
            if (!string.IsNullOrEmpty(text))
            {
                outputStream.Write(HTMLElements.m_classStyle);
                outputStream.Write(text);
                outputStream.Write(HTMLElements.m_quoteString);
            }
            outputStream.Write(HTMLElements.m_openStyle);
            if (Size != null)
            {
                Size.Render(outputStream);
            }
            if (BackgroundImage != null)
            {
                outputStream.Write(HTMLElements.m_space);
                outputStream.Write(HTMLElements.m_backgroundImage);
                outputStream.Write(BackgroundImage.Replace("(", "%28").Replace(")", "%29"));
                outputStream.Write(HTMLElements.m_closeParenthesis);
                outputStream.Write(HTMLElements.m_semiColon);
            }
            if (BackgroundImageSize != null)
            {
                outputStream.Write(HTMLElements.m_space);
                outputStream.Write(HTMLElements.m_backgroundSize);
                outputStream.Write(BackgroundImageSize);
                outputStream.Write(HTMLElements.m_semiColon);
            }
            if (BackgroundRepeat != null)
            {
                outputStream.Write(HTMLElements.m_space);
                outputStream.Write(HTMLElements.m_backgroundRepeat);
                BackgroundRepeat.Render(outputStream);
                outputStream.Write(HTMLElements.m_semiColon);
            }
            if (Overflow != null)
            {
                outputStream.Write(HTMLElements.m_overflow);
                outputStream.Write(Overflow);
                outputStream.Write(HTMLElements.m_semiColon);
            }
            outputStream.Write(HTMLElements.m_quoteString);
            outputStream.Write(HTMLElements.m_closeBracket);
            if (ChildElement != null)
            {
                ChildElement.Render(outputStream);
            }
            outputStream.Write(HTMLElements.m_closeDiv);
        }