예제 #1
0
 /// <summary>Prepares the image rectangle for drawing.</summary>
 /// <remarks>
 /// Prepares the image rectangle for drawing. This means that the size and position of the image
 /// rectangle will be changed to match the
 /// <see cref="BackgroundRepeatValue"/>
 /// values for the axes.
 /// </remarks>
 /// <param name="imageRectangle">the image rectangle which will be changed</param>
 /// <param name="backgroundArea">the background available area</param>
 /// <returns>the necessary whitespace between backgrounds</returns>
 public virtual Point PrepareRectangleToDrawingAndGetWhitespace(Rectangle imageRectangle, Rectangle backgroundArea
                                                                , BackgroundSize backgroundSize)
 {
     if (BackgroundRepeat.BackgroundRepeatValue.ROUND == xAxisRepeat)
     {
         int ratio = iText.Layout.Properties.BackgroundRepeat.CalculateRatio(backgroundArea.GetWidth(), imageRectangle
                                                                             .GetWidth());
         float initialImageRatio = imageRectangle.GetHeight() / imageRectangle.GetWidth();
         imageRectangle.SetWidth(backgroundArea.GetWidth() / ratio);
         if (BackgroundRepeat.BackgroundRepeatValue.ROUND != yAxisRepeat && backgroundSize.GetBackgroundHeightSize(
                 ) == null)
         {
             imageRectangle.MoveUp(imageRectangle.GetHeight() - imageRectangle.GetWidth() * initialImageRatio);
             imageRectangle.SetHeight(imageRectangle.GetWidth() * initialImageRatio);
         }
     }
     if (BackgroundRepeat.BackgroundRepeatValue.ROUND == yAxisRepeat)
     {
         int ratio = iText.Layout.Properties.BackgroundRepeat.CalculateRatio(backgroundArea.GetHeight(), imageRectangle
                                                                             .GetHeight());
         float initialImageRatio = imageRectangle.GetWidth() / imageRectangle.GetHeight();
         imageRectangle.MoveUp(imageRectangle.GetHeight() - backgroundArea.GetHeight() / ratio);
         imageRectangle.SetHeight(backgroundArea.GetHeight() / ratio);
         if (BackgroundRepeat.BackgroundRepeatValue.ROUND != xAxisRepeat && backgroundSize.GetBackgroundWidthSize()
             == null)
         {
             imageRectangle.SetWidth(imageRectangle.GetHeight() * initialImageRatio);
         }
     }
     return(ProcessSpaceValueAndCalculateWhitespace(imageRectangle, backgroundArea));
 }
예제 #2
0
 /// <summary>Set the image's backgroundSize.</summary>
 /// <param name="backgroundSize">
 ///
 /// <see cref="BackgroundSize"/>
 /// to be set.
 /// </param>
 /// <returns>
 /// this
 /// <see cref="Builder"/>.
 /// </returns>
 public virtual BackgroundImage.Builder SetBackgroundSize(BackgroundSize backgroundSize)
 {
     if (backgroundSize != null)
     {
         this.backgroundSize = backgroundSize;
     }
     return(this);
 }
예제 #3
0
        public virtual void ConstructorTest()
        {
            BackgroundSize size = new BackgroundSize();

            NUnit.Framework.Assert.IsFalse(size.IsContain());
            NUnit.Framework.Assert.IsFalse(size.IsCover());
            NUnit.Framework.Assert.IsNull(size.GetBackgroundWidthSize());
            NUnit.Framework.Assert.IsNull(size.GetBackgroundHeightSize());
        }
예제 #4
0
        public virtual void ClearAndSetToContainTest()
        {
            BackgroundSize size = new BackgroundSize();

            size.SetBackgroundSizeToValues(UnitValue.CreatePointValue(10), UnitValue.CreatePointValue(10));
            size.SetBackgroundSizeToContain();
            NUnit.Framework.Assert.IsTrue(size.IsContain());
            NUnit.Framework.Assert.IsFalse(size.IsCover());
            NUnit.Framework.Assert.IsNull(size.GetBackgroundWidthSize());
            NUnit.Framework.Assert.IsNull(size.GetBackgroundHeightSize());
        }
예제 #5
0
 /// <summary>
 /// Creates a new
 /// <see cref="BackgroundImage"/>
 /// instance.
 /// </summary>
 /// <param name="image">
 /// background-image property.
 /// <see cref="iText.Kernel.Pdf.Xobject.PdfXObject"/>
 /// instance.
 /// </param>
 /// <param name="repeat">
 /// background-repeat property.
 /// <see cref="BackgroundRepeat"/>
 /// instance.
 /// </param>
 /// <param name="position">
 /// background-position property.
 /// <see cref="BackgroundPosition"/>
 /// instance.
 /// </param>
 /// <param name="backgroundSize">
 /// background-size property.
 /// <see cref="BackgroundSize"/>
 /// instance.
 /// </param>
 /// <param name="linearGradientBuilder">
 /// background-image property.
 /// <see cref="iText.Kernel.Colors.Gradients.AbstractLinearGradientBuilder"/>
 /// instance.
 /// </param>
 /// <param name="blendMode">
 /// the image's blend mode.
 /// <see cref="BlendMode"/>
 /// instance.
 /// </param>
 /// <param name="clip">
 /// background-clip property.
 /// <see cref="BackgroundBox"/>
 /// instance.
 /// </param>
 /// <param name="origin">
 /// background-origin property.
 /// <see cref="BackgroundBox"/>
 /// instance.
 /// </param>
 private BackgroundImage(PdfXObject image, BackgroundRepeat repeat, BackgroundPosition position, BackgroundSize
                         backgroundSize, AbstractLinearGradientBuilder linearGradientBuilder, BlendMode blendMode, BackgroundBox
                         clip, BackgroundBox origin)
 {
     this.image = image;
     if (repeat != null)
     {
         this.repeatX = !repeat.IsNoRepeatOnXAxis();
         this.repeatY = !repeat.IsNoRepeatOnYAxis();
     }
     this.repeat                = repeat;
     this.position              = position;
     this.backgroundSize        = backgroundSize;
     this.linearGradientBuilder = linearGradientBuilder;
     if (blendMode != null)
     {
         this.blendMode = blendMode;
     }
     this.backgroundClip   = clip;
     this.backgroundOrigin = origin;
 }