예제 #1
0
        /// <summary>
        /// Sets visual border style for specified <see cref="Image"/>.
        /// </summary>
        /// <param name="image">Horizontal alignment.</param>
        /// <param name="style">Style to apply.</param>
        /// <returns>
        /// A <see cref="int"/> value that represents the alignment.
        /// </returns>
        public static Image SetVisualStyle(this Image image, PdfImageStyle style)
        {
            if (!string.IsNullOrEmpty(style.Content.Color))
            {
                image.BackgroundColor = new BaseColor(style.Content.GetColor());
            }

            BordersCollection borders = style.Borders;

            image.BorderWidthLeft = 0.0f;
            BaseBorder leftBorder = borders.GetBy(KnownBorderPosition.Left);

            if (leftBorder != null)
            {
                if (leftBorder.Show.AsBoolean())
                {
                    image.BorderWidthLeft = leftBorder.Width;
                    image.BorderColorLeft = new BaseColor(leftBorder.GetColor());
                }
            }

            image.BorderWidthTop = 0.0f;
            BaseBorder topBorder = borders.GetBy(KnownBorderPosition.Top);

            if (topBorder != null)
            {
                if (topBorder.Show.AsBoolean())
                {
                    image.BorderWidthTop = topBorder.Width;
                    image.BorderColorTop = new BaseColor(topBorder.GetColor());
                }
            }

            image.BorderWidthRight = 0.0f;
            BaseBorder rightBorder = borders.GetBy(KnownBorderPosition.Right);

            if (rightBorder != null)
            {
                if (rightBorder.Show.AsBoolean())
                {
                    image.BorderWidthRight = rightBorder.Width;
                    image.BorderColorRight = new BaseColor(rightBorder.GetColor());
                }
            }

            image.BorderWidthBottom = 0.0f;
            BaseBorder bottomBorder = borders.GetBy(KnownBorderPosition.Bottom);

            if (bottomBorder != null)
            {
                if (bottomBorder.Show.AsBoolean())
                {
                    image.BorderWidthBottom = bottomBorder.Width;
                    image.BorderColorBottom = new BaseColor(bottomBorder.GetColor());
                }
            }

            return(image);
        }
예제 #2
0
        /// <summary>
        /// Sets visual border style for specified cell.
        /// </summary>
        /// <param name="cell">Cell which receives visual style.</param>
        /// <param name="borders">Border collection definition to apply.</param>
        /// <returns>
        /// A <see cref="PdfPCell"/> object which contains specified visual style.
        /// </returns>
        public static PdfPCell SetBordersVisualStyle(this PdfPCell cell, BordersCollection borders)
        {
            cell.BorderWidthLeft = 0.0f;
            BaseBorder leftBorder = borders.GetBy(KnownBorderPosition.Left);

            if (leftBorder != null)
            {
                if (leftBorder.Show.AsBoolean())
                {
                    cell.BorderWidthLeft = leftBorder.Width;
                    cell.BorderColorLeft = new BaseColor(leftBorder.GetColor());
                }
            }

            cell.BorderWidthTop = 0.0f;
            BaseBorder topBorder = borders.GetBy(KnownBorderPosition.Top);

            if (topBorder != null)
            {
                if (topBorder.Show.AsBoolean())
                {
                    cell.BorderWidthTop = topBorder.Width;
                    cell.BorderColorTop = new BaseColor(topBorder.GetColor());
                }
            }

            cell.BorderWidthRight = 0.0f;
            BaseBorder rightBorder = borders.GetBy(KnownBorderPosition.Right);

            if (rightBorder != null)
            {
                if (rightBorder.Show.AsBoolean())
                {
                    cell.BorderWidthRight = rightBorder.Width;
                    cell.BorderColorRight = new BaseColor(rightBorder.GetColor());
                }
            }

            cell.BorderWidthBottom = 0.0f;
            BaseBorder bottomBorder = borders.GetBy(KnownBorderPosition.Bottom);

            if (bottomBorder != null)
            {
                if (bottomBorder.Show.AsBoolean())
                {
                    cell.BorderWidthBottom = bottomBorder.Width;
                    cell.BorderColorBottom = new BaseColor(bottomBorder.GetColor());
                }
            }

            return(cell);
        }