Ejemplo n.º 1
0
 FixedElement(FixedElement element, Unit left, Unit down)
 {
     Name = element.Name;
     Specification = element.Specification;
     MarginBox = element.MarginBox.Move(left, down);
     BorderBox = element.BorderBox.Move(left, down);
     InnerBox = element.InnerBox.Move(left, down);
     InnerBoxBeforeSplitOrCrop = element.InnerBoxBeforeSplitOrCrop.Move(left, down);
     VisiblePartOfSpecification = element.VisiblePartOfSpecification;
 }
Ejemplo n.º 2
0
        public void Render(XGraphics gfx, FixedElement element)
        {
            var specification = (Image) element.Specification;
            var source = ((PdfSharpImage) specification.Source).Source;

            gfx.DrawImage(source,
                          element.InnerBox.Left.Points,
                          element.InnerBox.Top.Points - element.VisiblePartOfSpecification.Top.Points,
                          element.InnerBox.Width.Points,
                          source.PixelHeight);
        }
Ejemplo n.º 3
0
        public void Render(PdfWriter writer, FixedElement element)
        {
            var spec = (Imaged) element.Specification;

            var image = GetImage(writer, spec);

            image.ScaleAbsolute((float)element.InnerBoxBeforeSplitOrCrop.Width.Points, (float)element.InnerBoxBeforeSplitOrCrop.Height.Points);

            var directContent = writer.DirectContent;
            var template = directContent.CreateTemplate((float)element.InnerBox.Width.Points, (float)element.InnerBox.Height.Points);
            image.SetAbsolutePosition(0, (float)(-image.ScaledHeight + element.InnerBox.Height.Points + element.VisiblePartOfSpecification.Top.Points));
            template.AddImage(image);
            directContent.AddTemplate(template, (float)element.InnerBox.Left.Points, (float)(writer.PageSize.Height - element.InnerBox.Bottom.Points));
        }
Ejemplo n.º 4
0
        public void Render(XGraphics gfx, FixedElement element)
        {
            var spec = (Backgrounded) element.Specification;

            if (spec.BackgroundColor != Colors.Transparent)
            {
                var backgroundBrush = new XSolidBrush(XColor.FromArgb(spec.BackgroundColor));
                gfx.DrawRectangle(backgroundBrush,
                                  element.InnerBox.Left.Points,
                                  element.InnerBox.Top.Points,
                                  element.InnerBox.Width.Points,
                                  element.InnerBox.Height.Points);
            }
        }
Ejemplo n.º 5
0
        public void Render(XElement canvas, FixedElement element)
        {
            var spec = (Backgrounded)element.Specification;

            var styles = new Dictionary<string, string>
            {
                { "position", "absolute" },
                { "left", string.Format("{0}px", element.InnerBox.Left) },
                { "top", string.Format("{0}px", element.InnerBox.Top) },
                { "width", string.Format("{0}px", element.InnerBox.Width) },
                { "height", string.Format("{0}px", element.InnerBox.Height) },
                { "background-color", string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", spec.BackgroundColor.A, spec.BackgroundColor.R, spec.BackgroundColor.G, spec.BackgroundColor.B)},
            };

            var div = new XElement("div");

            div.SetAttributeValue("style", "");
        }
Ejemplo n.º 6
0
        public void Render(PdfWriter writer, FixedElement element)
        {
            var spec = element.Specification;

            var rectangle = new Rectangle((float) element.BorderBox.Left.Points,
                                          writer.PageSize.Height - (float)element.BorderBox.Bottom.Points,
                                          (float)element.BorderBox.Right.Points,
                                          writer.PageSize.Height - (float)element.BorderBox.Top.Points)
            {
                BorderWidthTop = (float) spec.Borders.Top.Points,
                BorderWidthRight = (float) spec.Borders.Right.Points,
                BorderWidthBottom = (float) spec.Borders.Bottom.Points,
                BorderWidthLeft = (float) spec.Borders.Left.Points,
                BorderColor = new global::iTextSharp.text.Color(Color.FromArgb(spec.Borders.Color.A, spec.Borders.Color.R, spec.Borders.Color.G, spec.Borders.Color.B))
            };

            writer.DirectContent.Rectangle(rectangle);
        }
Ejemplo n.º 7
0
        public void Render(PdfWriter writer, FixedElement element)
        {
            var spec = (Backgrounded) element.Specification;

            if (spec.BackgroundColor == Colors.Transparent)
                return;

            var rectangle = new Rectangle((float)element.InnerBox.Left.Points,
                                          writer.PageSize.Height - (float)element.InnerBox.Bottom.Points,
                                          (float)element.InnerBox.Right.Points,
                                          writer.PageSize.Height - (float)element.InnerBox.Top.Points)
            {
                BackgroundColor = new global::iTextSharp.text.Color(Color.FromArgb(spec.BackgroundColor.A,
                                                                                   spec.BackgroundColor.R,
                                                                                   spec.BackgroundColor.G,
                                                                                   spec.BackgroundColor.B))
            };

            writer.DirectContent.Rectangle(rectangle);
        }
Ejemplo n.º 8
0
 public ElementAssertionWrapper(FixedElement element, int pageNumber)
 {
     this.element = element;
     this.pageNumber = pageNumber;
 }
Ejemplo n.º 9
0
 public ElementAssertionWrapper(FixedElement element)
 {
     this.element = element;
 }
Ejemplo n.º 10
0
        public void Render(XGraphics gfx, FixedElement element)
        {
            var specification = (Text) element.Specification;

            //foreach (var textPlaceholderReplacement in element.TextPlaceholderReplacements)
            //{
            //    switch (textPlaceholderReplacement.TextPlaceholder)
            //    {
            //        case TextPlaceholder.Pagenumber:
            //            text = text.Replace(textPlaceholderReplacement.Replacement, pageNumber.ToString());
            //            break;
            //        case TextPlaceholder.TotalNumberOfPages:
            //            text = text.Replace(textPlaceholderReplacement.Replacement, totalPageNumbers.ToString());
            //            break;
            //        default:
            //            throw new ArgumentOutOfRangeException();
            //    }
            //}

            //var fillCharWidth = Unit.Zero;
            //if (!string.IsNullOrEmpty(element.Filling))
            //    fillCharWidth = text.Font.CalculateTextWidth(element.Filling);

            gfx.DrawString(specification.TextContent,
                           ((PdfSharpFont)specification.Font).XFont,
                           new XSolidBrush(XColor.FromArgb(specification.TextColor)),
                           new XRect(element.InnerBox.Left.Points, element.InnerBox.Top.Points, 10, element.InnerBox.Height.Points),
                           XStringFormats.TopLeft);

            //var y = element.InnerTop.Points;
            //var lineHeight = 0.cm();
            //foreach (var lineFromText in ((TextBehavior)specification.Behavior).GetLines(specification.TextContent, specification.Font, element.InnerWidth))
            //{
            //    if (lineHeight < element.ViewportTop || (element.ViewportBottom != 0.cm() && lineHeight > element.ViewportBottom))
            //    {
            //        lineHeight += specification.Font.CalculateLineHeight();
            //        continue;
            //    }

            //    var line = lineFromText;
            //    //if (!string.IsNullOrEmpty(element.Filling))
            //    //{
            //    //    var currentTextWidth = text.Font.CalculateTextWidth(line);

            //    //    while (currentTextWidth + fillCharWidth < element.InnerWidth)
            //    //    {
            //    //        line += element.Filling;
            //    //        currentTextWidth += fillCharWidth;
            //    //    }
            //    //}

            //    double x;
            //    switch (specification.Alignment)
            //    {
            //        case Alignment.Center:
            //            x = (element.InnerWidth - specification.Font.CalculateTextWidth(line)).Points / 2;
            //            break;
            //        case Alignment.Justify:
            //            throw new NotImplementedException("Justification not yet implemented");
            //        case Alignment.Left:
            //            x = 0;
            //            break;
            //        case Alignment.Right:
            //            x = (element.InnerWidth - specification.Font.CalculateTextWidth(line)).Points;
            //            break;
            //        default:
            //            throw new ArgumentOutOfRangeException();
            //    }

            //    gfx.DrawString(line,
            //                   ((PdfSharpFont)specification.Font).XFont,
            //                   new XSolidBrush(XColor.FromArgb(specification.TextColor)),
            //                   element.InnerLeft.Points + x,
            //                   y,
            //                   XStringFormats.TopLeft);
            //    y += specification.Font.CalculateLineHeight().Points;
            //    lineHeight += specification.Font.CalculateLineHeight();
            //    //TODO: ADD LINE SPACING
            //}
        }
Ejemplo n.º 11
0
        public void Render(PdfWriter writer, FixedElement element)
        {
            var spec = (Texted) element.Specification;
            var columnText = new ColumnText(writer.DirectContent)
            {
                Leading = (float) ((iTextSharpFont) spec.Font).Leading,
                UseAscender = true
            };
            var font = ((iTextSharpFont)spec.Font).Font;
            font.Color = new global::iTextSharp.text.Color(Color.FromArgb(spec.TextColor.A, spec.TextColor.R, spec.TextColor.G, spec.TextColor.B));
            var text = spec.TextContent.Replace(Text.PageNumber, writer.CurrentPageNumber.ToString(CultureInfo.InvariantCulture));
            columnText.AddText(new Phrase(text, font));

            var horizontalAlignment = 0;
            switch (spec.HorizontalAlignment)
            {
                case HorizontalAlignment.Left:
                    horizontalAlignment = Element.ALIGN_LEFT;
                    break;
                case HorizontalAlignment.Center:
                    horizontalAlignment = Element.ALIGN_CENTER;
                    break;
                case HorizontalAlignment.Right:
                    horizontalAlignment = Element.ALIGN_RIGHT;
                    break;
                case HorizontalAlignment.Justify:
                    horizontalAlignment = Element.ALIGN_JUSTIFIED;
                    break;
            }

            var textHeight = spec.Font.CalculateTextHeight(text, element.InnerBox.Width);
            var top = Unit.Undefined;
            switch (spec.VerticalAlignment)
            {
                case VerticalAlignment.Top:
                    top = element.InnerBox.Top;
                    break;
                case VerticalAlignment.Middle:
                    top = element.InnerBox.Top + (element.InnerBox.Height - textHeight)/2;
                    break;
                case VerticalAlignment.Bottom:
                    top = element.InnerBox.Top + element.InnerBox.Height - textHeight;
                    break;
            }

            if (element.VisiblePartOfSpecification.Top > 0.cm())
            {
                columnText.SetSimpleColumn((float) element.InnerBox.Left.Points,
                                           0,
                                           (float) element.InnerBox.Right.Points,
                                           (float) -element.VisiblePartOfSpecification.Top.Points);
                columnText.Go(true);
            }

            if (!string.IsNullOrEmpty(spec.Leader) && element.InnerBox.Height.Points < ((iTextSharpFont) spec.Font).Leading*2)
            {
                var leader = "";
                var textWidth = CalculateTextWidth(text, element, font, (float) ((iTextSharpFont)spec.Font).Leading);
                for (var i = 0; i < 1000; i++)
                    leader += spec.Leader;

                var leaderColumnText = new ColumnText(writer.DirectContent);
                leaderColumnText.UseAscender = true;
                leaderColumnText.SetSimpleColumn(new Phrase(leader, font),
                                                 (float) element.InnerBox.Left.Points + textWidth,
                                                 writer.PageSize.Height - (float) element.InnerBox.Bottom.Points,
                                                 (float) element.InnerBox.Right.Points,
                                                 writer.PageSize.Height - (float) top.Points,
                                                 (float) ((iTextSharpFont) spec.Font).Leading,
                                                 Element.ALIGN_RIGHT);

                leaderColumnText.Go();
            }

            columnText.SetSimpleColumn((float) element.InnerBox.Left.Points,
                                       writer.PageSize.Height - (float) element.InnerBox.Bottom.Points,
                                       (float) element.InnerBox.Right.Points,
                                       writer.PageSize.Height - (float)top.Points,
                                       (float) ((iTextSharpFont) spec.Font).Leading,
                                       horizontalAlignment);
            columnText.Go();
        }
Ejemplo n.º 12
0
        static float CalculateTextWidth(string text, FixedElement element, Font font, float leading)
        {
            var ct = new ColumnText(null);
            ct.AddText(new Phrase(text, font));

            ct.SetSimpleColumn(0,
                               0,
                               (float) element.InnerBox.Width.Points,
                               (float) element.InnerBox.Height.Points,
                               leading,
                               Element.ALIGN_LEFT);

            ct.Go(true);
            return ct.FilledWidth;
        }
Ejemplo n.º 13
-1
        public void Render(XGraphics gfx, FixedElement element)
        {
            var spec = element.Specification;

            var penTop = new XPen(XColor.FromArgb(spec.Borders.Color), spec.Borders.Top.Points);
            var penLeft = new XPen(XColor.FromArgb(spec.Borders.Color), spec.Borders.Left.Points);
            var penRight = new XPen(XColor.FromArgb(spec.Borders.Color), spec.Borders.Right.Points);
            var penBottom = new XPen(XColor.FromArgb(spec.Borders.Color), spec.Borders.Bottom.Points);

            var midBorderTop = element.InnerBox.Top - spec.Borders.Top / 2;
            var midBorderRight = element.InnerBox.Right + spec.Borders.Right / 2;
            var midBorderBottom = element.InnerBox.Bottom + spec.Borders.Bottom / 2;
            var midBorderLeft = element.InnerBox.Left - spec.Borders.Left / 2;

            if (spec.Borders.Top != Unit.Zero)
                gfx.DrawLine(penTop, element.InnerBox.Left.Points, midBorderTop.Points, element.InnerBox.Right.Points, midBorderTop.Points);

            if (spec.Borders.Right != Unit.Zero)
                gfx.DrawLine(penRight, midBorderRight.Points, element.MarginBox.Top.Points, midBorderRight.Points, element.MarginBox.Bottom.Points);

            if (spec.Borders.Bottom != Unit.Zero)
                gfx.DrawLine(penBottom, element.InnerBox.Left.Points, midBorderBottom.Points, element.InnerBox.Right.Points, midBorderBottom.Points);

            if (spec.Borders.Left != Unit.Zero)
                gfx.DrawLine(penLeft, midBorderLeft.Points, element.MarginBox.Top.Points, midBorderLeft.Points, element.MarginBox.Bottom.Points);
        }