Ejemplo n.º 1
0
        private static string AssureThatTextFitsInColumn(IRenderData renderData, string cellData, KeyValuePair <string, TableColumn> column, double columnPadding, XFont lineFont)
        {
            if (string.IsNullOrEmpty(cellData))
            {
                return(cellData);
            }

            var columnWidth      = column.Value.Width.Value.ToXUnit(renderData.ElementBounds.Width) - columnPadding;
            var originlTextWidth = renderData.Graphics.MeasureString(cellData, lineFont, XStringFormats.TopLeft).Width;

            if (columnWidth - originlTextWidth > -0.0001)
            {
                return(cellData);
            }

            var   calculatedCellData = cellData;
            XSize calculatedCellDataSize;

            do
            {
                calculatedCellData     = calculatedCellData.Substring(0, calculatedCellData.Length - 1);
                calculatedCellDataSize = renderData.Graphics.MeasureString(calculatedCellData, lineFont, XStringFormats.TopLeft);
            }while (calculatedCellDataSize.Width > columnWidth && calculatedCellData != string.Empty);

            return(calculatedCellData);
        }
Ejemplo n.º 2
0
        private static double OutputText(IRenderData renderData, string message, XFont font, XSolidBrush brush, XPoint point, double width)
        {
            var textSize  = renderData.Graphics.MeasureString(message, font);
            var lineCount = 0;

            var offset = 0;
            var part   = 0;
            var more   = true;

            while (more) //offset + part < message.Length)
            {
                more = false;
                part = message.Length - offset;
                while (renderData.Graphics.MeasureString(message.Substring(offset, part), font).Width > width)
                {
                    part--;
                    more = true;
                }
                renderData.Graphics.DrawString(message.Substring(offset, part), font, brush, new XPoint(point.X, point.Y + textSize.Height * lineCount), XStringFormats.TopLeft);

                offset = part;
                lineCount++;
            }


            return(textSize.Height * lineCount);
        }
Ejemplo n.º 3
0
        internal int PreRender(IRenderData renderData)
        {
            var maxTotalPages    = 1;
            var elementsToRender = _elementList.Where(x => x is MultiPageAreaElement || x is MultiPageElement).ToArray();

            foreach (var element in elementsToRender)
            {
                var totalPages = 1;
                if (element as MultiPageElement != null)
                {
                    totalPages = ((MultiPageElement)element).PreRender(renderData);
                }
                else if (element as MultiPageAreaElement != null)
                {
                    totalPages = ((MultiPageAreaElement)element).PreRender(renderData);
                }
                else if (element as SinglePageAreaElement != null)
                {
                    ((SinglePageAreaElement)element).Render(renderData);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(string.Format("Unknown type {0} for pane to render.", element.GetType().Name));
                }

                if (totalPages > maxTotalPages)
                {
                    maxTotalPages = totalPages;
                }
            }

            return(maxTotalPages);
        }
Ejemplo n.º 4
0
        internal override void Render(IRenderData renderData, int page)
        {
            if (!string.IsNullOrEmpty(HideValue))
            {
                var result = renderData.DocumentData.Get(HideValue);
                if (string.IsNullOrEmpty(result))
                {
                    return;
                }
            }

            var bounds = GetBounds(renderData.ParentBounds);

            var rd = new RenderData(renderData.Graphics, bounds, renderData.Section, renderData.DocumentData, renderData.PageNumberInfo, renderData.DebugData, renderData.IncludeBackground, renderData.DocumentProperties);

            RenderChildren(rd, page);

            if (renderData.DebugData != null)
            {
                const int radius = 10;
                renderData.Graphics.DrawEllipse(renderData.DebugData.Pen, bounds.Left - radius, bounds.Top - radius, radius * 2, radius * 2);
                renderData.Graphics.DrawLine(renderData.DebugData.Pen, bounds.Left - radius - 2, bounds.Top, bounds.Left + radius + 2, bounds.Top);
                renderData.Graphics.DrawLine(renderData.DebugData.Pen, bounds.Left, bounds.Top - radius - 2, bounds.Left, bounds.Top + radius + 2);
            }

            //TODO: Change the width and height to the actual area used
            renderData.ElementBounds = new XRect(bounds.Left, bounds.Right, 0, 0);
        }
Ejemplo n.º 5
0
 public Entity(string name, IRenderData renderData, double rotationAngle, double paddleInitialY, CollisionTypeEnum collisionType)
 {
     Name           = name;
     RenderData     = renderData;
     RotationAngle  = rotationAngle;
     PaddleInitialY = paddleInitialY;
     CollisionType  = collisionType;
 }
Ejemplo n.º 6
0
        public void Setup()
        {
            renderData = Substitute.For <IRenderData>();

            renderHexMeshData = new RenderHexMeshData();

            renderOperations = new RenderOperations(
                renderData,
                renderHexMeshData
                );
        }
Ejemplo n.º 7
0
        internal override void Render(IRenderData renderData)
        {
            if (IsNotVisible(renderData))
            {
                return;
            }

            var bounds = GetBounds(renderData.ParentBounds);

            System.Drawing.Image imageData = null;
            try
            {
                imageData = GetImage(renderData.DocumentData, bounds);
                renderData.ElementBounds = GetImageBounds(imageData, bounds);

                if (renderData.IncludeBackground || !IsBackground)
                {
                    using (var image = XImage.FromGdiPlusImage(imageData))
                    {
                        renderData.Graphics.DrawImage(image, renderData.ElementBounds);
                    }
                }
            }
            catch (Exception e)
            {
                var f     = new Font();
                var font  = new XFont(f.GetName(renderData.Section), f.GetSize(renderData.Section) / 1.5, f.GetStyle(renderData.Section));
                var brush = new XSolidBrush(XColor.FromKnownColor(KnownColor.Transparent));
                renderData.Graphics.DrawRectangle(new XPen(f.GetColor(renderData.Section)), brush, bounds);
                var textBrush = new XSolidBrush(XColor.FromArgb(f.GetColor(renderData.Section)));

                try
                {
                    var nextTop = OutputText(renderData, e.Message, font, textBrush, new XPoint(bounds.Left, bounds.Top), bounds.Width);
                    if (e.Data.Contains("source"))
                    {
                        OutputText(renderData, e.Data["source"].ToString(), font, textBrush, new XPoint(bounds.Left, bounds.Top + nextTop), bounds.Width);
                    }
                }
                catch (Exception exception)
                {
                    renderData.Graphics.DrawString(exception.Message, font, brush, new XPoint(bounds.Left, bounds.Top), XStringFormats.TopLeft);
                }
            }
            finally
            {
                imageData?.Dispose();
            }
        }
Ejemplo n.º 8
0
        private int PreRenderChildren(IRenderData renderData)
        {
            var maxPageCount     = 1;
            var elementsToRender = ElementList.Where(x => x is MultiPageAreaElement || x is MultiPageElement);

            var stackTop = new UnitValue();

            foreach (var element in elementsToRender)
            {
                var resetLocation = false;
                if (Stack == StackMethod.Vertical)
                {
                    if (element.Top == null)
                    {
                        resetLocation = true;
                        element.Top   = stackTop;
                    }
                }

                int pageCount;
                if (element is MultiPageAreaElement)
                {
                    pageCount = ((MultiPageAreaElement)element).PreRender(renderData);
                }
                else if (element is MultiPageElement)
                {
                    pageCount = ((MultiPageElement)element).PreRender(renderData);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(string.Format("Unknown type {0}.", element.GetType()));
                }

                stackTop = new UnitValue(stackTop.Value + renderData.ElementBounds.Height, stackTop.Unit);

                if (resetLocation)
                {
                    element.Top = null;
                }

                if (pageCount > maxPageCount)
                {
                    maxPageCount = pageCount;
                }
            }

            return(maxPageCount);
        }
Ejemplo n.º 9
0
        internal bool IsNotVisible(IRenderData renderData)
        {
            if (Visibility != PageVisibility.All &&
                (Visibility != PageVisibility.FirstPage || renderData.PageNumberInfo.PageNumber != 1) &&
                (Visibility != PageVisibility.AllButFirst || renderData.PageNumberInfo.PageNumber == 1) &&
                (Visibility != PageVisibility.LastPage || renderData.PageNumberInfo.PageNumber != renderData.PageNumberInfo.TotalPages) &&
                (Visibility != PageVisibility.AllButLast || renderData.PageNumberInfo.PageNumber == renderData.PageNumberInfo.TotalPages) &&
                (Visibility != PageVisibility.WhenSinglePage || renderData.PageNumberInfo.TotalPages != 1) &&
                (Visibility != PageVisibility.WhenMultiplePages || !(renderData.PageNumberInfo.TotalPages > 1)))
            {
                renderData.ElementBounds = new XRect {
                    X = renderData.ElementBounds.X, Y = renderData.ElementBounds.Y, Width = 0, Height = 0
                };
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
        internal override int PreRender(IRenderData renderData)
        {
            if (!string.IsNullOrEmpty(HideValue))
            {
                var result = renderData.DocumentData.Get(HideValue);
                if (string.IsNullOrEmpty(result))
                {
                    return(0);
                }
            }

            var bounds = GetBounds(renderData.ParentBounds);

            var rd        = new RenderData(renderData.Graphics, bounds, renderData.Section, renderData.DocumentData, renderData.PageNumberInfo, renderData.DebugData, renderData.IncludeBackground, renderData.DocumentProperties);
            var pageCount = PreRenderChildren(rd);

            renderData.ElementBounds = new XRect(bounds.Left, bounds.Right, 0, 0);

            return(pageCount);
        }
Ejemplo n.º 11
0
        internal override void Render(IRenderData renderData)
        {
            if (string.IsNullOrEmpty(Code))
            {
                throw new InvalidOperationException("Code has not been set.");
            }

            if (IsNotVisible(renderData))
            {
                return;
            }

            var bounds = GetBounds(renderData.ParentBounds);

            renderData.ElementBounds = bounds;

            var codeText = GetCode(renderData.DocumentData, renderData.PageNumberInfo);

            if ((!IsBackground || renderData.IncludeBackground) && !string.IsNullOrEmpty(codeText))
            {
                var b = new BarCodeBuilder {
                    SymbologyType = Symbology.Code39Standard, CodeText = codeText
                };
                var memStream = new MemoryStream();
                b.BarCodeImage.Save(memStream, ImageFormat.Png);
                var imageData = System.Drawing.Image.FromStream(memStream);

                //Paint over the license info
                using (var g = Graphics.FromImage(imageData))
                {
                    g.FillRectangle(new SolidBrush(b.BackColor), 0, 0, imageData.Width, 14);
                }

                using (var image = XImage.FromGdiPlusImage(imageData))
                {
                    renderData.Graphics.DrawImage(image, new XRect(renderData.ElementBounds.Left, renderData.ElementBounds.Top, renderData.ElementBounds.Width, renderData.ElementBounds.Height)); // - legendFontSize.Height));
                }

                imageData.Dispose();
            }
        }
Ejemplo n.º 12
0
        private void RenderChildren(IRenderData renderData, int page)
        {
            var stackTop = new UnitValue();

            foreach (var element in ElementList)
            {
                var resetLocation = false;
                if (Stack == StackMethod.Vertical)
                {
                    if (element.Top == null)
                    {
                        resetLocation = true;
                        element.Top   = stackTop;
                    }
                }

                if (element is SinglePageAreaElement)
                {
                    ((SinglePageAreaElement)element).Render(renderData);
                }
                else if (element is MultiPageAreaElement)
                {
                    ((MultiPageAreaElement)element).Render(renderData, page);
                }
                else if (element is MultiPageElement)
                {
                    ((MultiPageElement)element).Render(renderData, page);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(string.Format("Unknown type {0}.", element.GetType()));
                }

                stackTop = new UnitValue(stackTop.Value + renderData.ElementBounds.Height, stackTop.Unit);

                if (resetLocation)
                {
                    element.Top = null;
                }
            }
        }
Ejemplo n.º 13
0
 internal void Render(IRenderData renderData, int page)
 {
     foreach (var element in _elementList)
     {
         if (element as MultiPageElement != null)
         {
             ((MultiPageElement)element).Render(renderData, page);
         }
         else if (element as MultiPageAreaElement != null)
         {
             ((MultiPageAreaElement)element).Render(renderData, page);
         }
         else if (element as SinglePageAreaElement != null)
         {
             ((SinglePageAreaElement)element).Render(renderData);
         }
         else
         {
             throw new ArgumentOutOfRangeException(string.Format("Unknown type {0} for pane to render.", element.GetType().Name));
         }
     }
 }
Ejemplo n.º 14
0
        internal override void Render(IRenderData renderData)
        {
            if (!string.IsNullOrEmpty(HideValue))
            {
                var result = renderData.DocumentData.Get(HideValue);
                if (string.IsNullOrEmpty(result))
                {
                    return;
                }
            }

            if (IsNotVisible(renderData))
            {
                return;
            }

            renderData.ElementBounds = GetBounds(renderData.ParentBounds);

            if (renderData.IncludeBackground || !IsBackground)
            {
                var borderWidth = UnitValue.Parse(Thickness);
                var pen         = new XPen(XColor.FromArgb(Color), borderWidth.ToXUnit(0));

                if (HorixontalSwap(renderData.ParentBounds))
                {
                    renderData.Graphics.DrawLine(pen, renderData.ElementBounds.Right, renderData.ElementBounds.Top, renderData.ElementBounds.Left, renderData.ElementBounds.Bottom);
                }
                else if (VerticalSwap(renderData.ParentBounds))
                {
                    renderData.Graphics.DrawLine(pen, renderData.ElementBounds.Left, renderData.ElementBounds.Bottom, renderData.ElementBounds.Right, renderData.ElementBounds.Top);
                }
                else
                {
                    renderData.Graphics.DrawLine(pen, renderData.ElementBounds.Left, renderData.ElementBounds.Top, renderData.ElementBounds.Right, renderData.ElementBounds.Bottom);
                }
            }
        }
Ejemplo n.º 15
0
        internal override void Render(IRenderData renderData)
        {
            if (IsNotVisible(renderData))
            {
                return;
            }

            renderData.ElementBounds = GetBounds(renderData.ParentBounds);

            if (!IsBackground || renderData.IncludeBackground)
            {
                var pen = new XPen(XColor.FromArgb(BorderColor), BorderWidth.ToXUnit(0));

                if (BackgroundColor != null)
                {
                    var brush = new XSolidBrush(XColor.FromArgb(BackgroundColor.Value));
                    renderData.Graphics.DrawRectangle(pen, brush, renderData.ElementBounds);
                }
                else
                {
                    renderData.Graphics.DrawRectangle(pen, renderData.ElementBounds);
                }
            }
        }
Ejemplo n.º 16
0
        internal override void Render(IRenderData renderData, int page)
        {
            if (IsNotVisible(renderData))
            {
                return;
            }

            var pushTextForwardOnPages = 0;

            if (Visibility == PageVisibility.LastPage && renderData.PageNumberInfo.TotalPages != page)
            {
                pushTextForwardOnPages = renderData.PageNumberInfo.TotalPages.Value - 1;
            }

            if (_pageText == null)
            {
                throw new InvalidOperationException("Pre-render has not been performed.");
            }

            var maxBounds = GetBounds(renderData.ParentBounds);

            if (!renderData.IncludeBackground && IsBackground)
            {
                return;
            }

            var font  = new XFont(_font.GetName(renderData.Section), _font.GetSize(renderData.Section), _font.GetStyle(renderData.Section));
            var brush = new XSolidBrush(XColor.FromArgb(_font.GetColor(renderData.Section)));

            var text     = GetValue(renderData.DocumentData, renderData.PageNumberInfo, renderData.DocumentProperties);
            var textSize = renderData.Graphics.MeasureString(text, font, XStringFormats.TopLeft);

            var left = maxBounds.Left;
            var top  = maxBounds.Top;

            if (_pageText.Count > page - renderData.Section.GetPageOffset() - pushTextForwardOnPages)
            {
                foreach (var line in _pageText[page - renderData.Section.GetPageOffset() - pushTextForwardOnPages])
                {
                    renderData.Graphics.DrawString(line, font, brush, new XPoint(left, top), XStringFormats.TopLeft);
                    var newTextSize = renderData.Graphics.MeasureString(line, font, XStringFormats.TopLeft);
                    top += newTextSize.Height;
                }
            }

            if (Height == null)
            {
                renderData.ElementBounds = new XRect {
                    Location = maxBounds.Location, Width = maxBounds.Width, Height = top - maxBounds.Top
                }
            }
            ;
            else
            {
                renderData.ElementBounds = maxBounds;
            }

            if (renderData.DebugData != null)
            {
                renderData.Graphics.DrawRectangle(renderData.DebugData.Pen, renderData.ElementBounds);
            }
        }
Ejemplo n.º 17
0
        internal override void Render(IRenderData renderData)
        {
            if (IsNotVisible(renderData))
            {
                return;
            }

            var bounds = GetBounds(renderData.ParentBounds);

            var font  = new XFont(_font.GetName(renderData.Section), _font.GetSize(renderData.Section), _font.GetStyle(renderData.Section));
            var brush = new XSolidBrush(XColor.FromArgb(_font.GetColor(renderData.Section)));

            var text     = GetValue(renderData.DocumentData, renderData.PageNumberInfo, renderData.DocumentProperties);
            var textSize = renderData.Graphics.MeasureString(text, font, XStringFormats.TopLeft);

            if (text.EndsWith(Environment.NewLine))
            {
                textSize = renderData.Graphics.MeasureString(text + ".", font, XStringFormats.TopLeft);
            }

            var offset     = 0D;
            var adjustment = 0D;

            switch (TextAlignment)
            {
            case Alignment.Right:
                adjustment = textSize.Width;
                offset     = bounds.Width - adjustment;
                break;

            case Alignment.Left:
                adjustment = 0D;
                offset     = 0D;
                break;

            case Alignment.Center:
                adjustment = textSize.Width / 2;
                offset     = (bounds.Width / 2) - adjustment;
                break;

            default:
                throw new ArgumentOutOfRangeException(string.Format("Unknown TextAlignment {0}.", TextAlignment));
            }

            renderData.ElementBounds = new XRect(bounds.Left + offset, bounds.Y, textSize.Width, textSize.Height);

            if (renderData.IncludeBackground || !IsBackground)
            {
                if (renderData.PageNumberInfo.TotalPages == null)
                {
                    throw new InvalidOperationException("The prerendering step did not set the number of total pages!");
                }

                var    lines      = text.Split(Environment.NewLine.ToCharArray());
                double lineOffset = 0;
                foreach (var line in lines)
                {
                    var elementBounds = new XRect(renderData.ElementBounds.X, renderData.ElementBounds.Y + lineOffset, renderData.ElementBounds.Width, renderData.ElementBounds.Height - lineOffset);
                    renderData.Graphics.DrawString(line, font, brush, elementBounds, XStringFormats.TopLeft);
                    lineOffset += renderData.Graphics.MeasureString(line, font).Height;
                }

                if (renderData.DebugData != null)
                {
                    renderData.Graphics.DrawRectangle(renderData.DebugData.Pen, new XRect(renderData.ElementBounds.Left, renderData.ElementBounds.Top, textSize.Width, textSize.Height));

                    //const int radius = 5;
                    //var l = renderData.ElementBounds.Left + adjustment;
                    //renderData.Graphics.DrawEllipse(renderData.DebugData.Pen, l - radius, renderData.ElementBounds.Top - radius, radius * 2, radius * 2);
                    //renderData.Graphics.DrawLine(renderData.DebugData.Pen, l - radius - 2, bounds.Top, l + radius + 2, bounds.Top);
                    //renderData.Graphics.DrawLine(renderData.DebugData.Pen, l, bounds.Top - radius - 2, l, bounds.Top + radius + 2);
                }
            }
        }
Ejemplo n.º 18
0
 public RenderOperations(IRenderData renderData, RenderHexMeshData hexMeshData)
 {
     this.renderData  = renderData;
     this.hexMeshData = hexMeshData;
 }
Ejemplo n.º 19
0
        internal override void Render(IRenderData renderData, int page)
        {
            if (IsNotVisible(renderData))
            {
                return;
            }

            var pushTextForwardOnPages = 0;

            if (Visibility == PageVisibility.LastPage && renderData.PageNumberInfo.TotalPages != page)
            {
                pushTextForwardOnPages = renderData.PageNumberInfo.TotalPages.Value - 1;
            }

            if (_pageRowSet == null)
            {
                throw new InvalidOperationException("PreRendering has not yet been performed.");
            }

            renderData.ElementBounds = GetBounds(renderData.ParentBounds);

            if (!renderData.IncludeBackground && IsBackground)
            {
                return;
            }

            var headerFont  = new XFont(_headerFont.GetName(renderData.Section), _headerFont.GetSize(renderData.Section), _headerFont.GetStyle(renderData.Section));
            var headerBrush = new XSolidBrush(XColor.FromArgb(_headerFont.GetColor(renderData.Section)));
            var lineFont    = new XFont(_contentFont.GetName(renderData.Section), _contentFont.GetSize(renderData.Section), _contentFont.GetStyle(renderData.Section));
            var lineBrush   = new XSolidBrush(XColor.FromArgb(_contentFont.GetColor(renderData.Section)));
            var groupFont   = new XFont(_groupFont.GetName(renderData.Section), _groupFont.GetSize(renderData.Section), _groupFont.GetStyle(renderData.Section));

            var firstColumn = _columns.FirstOrDefault();

            if (firstColumn.Value == null)
            {
                return;
            }
            var headerSize  = renderData.Graphics.MeasureString(firstColumn.Value.Title, headerFont, XStringFormats.TopLeft);
            var stdLineSize = renderData.Graphics.MeasureString(firstColumn.Value.Title, lineFont, XStringFormats.TopLeft);

            if (renderData.DebugData != null)
            {
                renderData.Graphics.DrawString(string.Format("Table: {0}", Name), renderData.DebugData.Font, renderData.DebugData.Brush, renderData.ElementBounds.Center);
            }

            if (renderData.DocumentData != null)
            {
                var dataTable = renderData.DocumentData.GetDataTable(Name);
                if (dataTable != null)
                {
                    var columnPadding = ColumnPadding.ToXUnit(renderData.ElementBounds.Width);

                    foreach (var column in _columns.Where(x => x.Value.WidthMode == WidthMode.Auto).ToList())
                    {
                        //Get the size of the columnt title text
                        var stringSize = renderData.Graphics.MeasureString(column.Value.Title, headerFont, XStringFormats.TopLeft);
                        var wd         = UnitValue.Parse((stringSize.Width + columnPadding).ToString(CultureInfo.InvariantCulture) + "px");

                        //If there is a fixed width value, start with that.
                        if (column.Value.Width == null)
                        {
                            column.Value.Width = wd;
                        }

                        //If the column header title is greater than
                        if (column.Value.Width.Value < wd)
                        {
                            column.Value.Width = wd;
                        }

                        foreach (var row in dataTable.Rows)
                        {
                            if (row is DocumentDataTableData)
                            {
                                var rowData = row as DocumentDataTableData;

                                var cellData = GetValue(column.Key, rowData.Columns);
                                stringSize = renderData.Graphics.MeasureString(cellData, lineFont, XStringFormats.TopLeft);
                                wd         = UnitValue.Parse((stringSize.Width + columnPadding).ToString(CultureInfo.InvariantCulture) + "px");
                                if (column.Value.Width < wd)
                                {
                                    column.Value.Width = wd;
                                }
                            }
                        }
                    }

                    foreach (var column in _columns.ToList())
                    {
                        if (column.Value.HideValue != null)
                        {
                            column.Value.Hide = true;
                        }

                        foreach (var row in dataTable.Rows)
                        {
                            if (row is DocumentDataTableData)
                            {
                                var rowData         = row as DocumentDataTableData;
                                var cellData        = GetValue(column.Key, rowData.Columns);
                                var parsedHideValue = GetValue(column.Value.HideValue, rowData.Columns);
                                if (parsedHideValue != cellData)
                                {
                                    column.Value.Hide = false;
                                }
                            }
                        }

                        if (column.Value.Hide)
                        {
                            column.Value.Width = new UnitValue();
                            if (HideTableWhenColumnIsHidden == column.Key)
                            {
                                //Hide the entire table
                                return;
                            }
                        }
                    }

                    RenderBorder(renderData.ElementBounds, renderData.Graphics, headerSize);

                    var totalWidth     = renderData.ElementBounds.Width;
                    var nonSpringWidth = _columns.Where(x => x.Value.WidthMode != WidthMode.Spring).Sum(x => x.Value.Width != null ? x.Value.Width.Value.ToXUnit(totalWidth) : 0);

                    var springCount = _columns.Count(x => x.Value.WidthMode == WidthMode.Spring && !x.Value.Hide);
                    if (springCount > 0)
                    {
                        foreach (var column in _columns.Where(x => x.Value.WidthMode == WidthMode.Spring && !x.Value.Hide).ToList())
                        {
                            if (column.Value.Width == null)
                            {
                                column.Value.Width = "0";
                            }
                            var calculatedWidth = new UnitValue((renderData.ElementBounds.Width - nonSpringWidth) / springCount, UnitValue.EUnit.Point);
                            if (calculatedWidth > column.Value.Width)
                            {
                                column.Value.Width = calculatedWidth;
                            }
                        }
                    }

                    AssureTotalColumnWidth(renderData.ElementBounds.Width);

                    //Create header
                    double left         = 0;
                    var    tableColumns = _columns.Values.Where(x => !x.Hide).ToList();
                    foreach (var column in tableColumns)
                    {
                        var alignmentJusttification = 0D;
                        if (column.Align == Alignment.Right)
                        {
                            var stringSize = renderData.Graphics.MeasureString(column.Title, headerFont, XStringFormats.TopLeft);
                            alignmentJusttification = column.Width.Value.ToXUnit(renderData.ElementBounds.Width) - stringSize.Width - (columnPadding / 2);
                        }
                        else
                        {
                            alignmentJusttification += columnPadding / 2;
                        }

                        renderData.Graphics.DrawString(column.Title, headerFont, headerBrush, new XPoint(renderData.ElementBounds.Left + left + alignmentJusttification, renderData.ElementBounds.Top), XStringFormats.TopLeft);
                        left += column.Width.Value.ToXUnit(renderData.ElementBounds.Width);

                        if (renderData.DebugData != null)
                        {
                            renderData.Graphics.DrawLine(renderData.DebugData.Pen, renderData.ElementBounds.Left + left, renderData.ElementBounds.Top, renderData.ElementBounds.Left + left, renderData.ElementBounds.Bottom);
                        }
                    }

                    var top       = headerSize.Height + RowPadding.ToXUnit(renderData.ElementBounds.Height);
                    var pageIndex = 1;

                    var defaultRowset = true;
                    var pageRowSet    = new PageRowSet {
                        FromRow = 1
                    };
                    var index = page - renderData.Section.GetPageOffset() - pushTextForwardOnPages;
                    if (_pageRowSet.Count > index)
                    {
                        try
                        {
                            defaultRowset = false;
                            pageRowSet    = _pageRowSet[index];
                        }
                        catch (Exception exception)
                        {
                            throw new InvalidOperationException(string.Format("_pageRowSet.Count={0}, index={1}", _pageRowSet.Count, index), exception);
                        }
                    }

                    //Draw column separator lines
                    if (ColumnBorderColor != null)
                    {
                        left = 0;
                        var borderPen = new XPen(ColumnBorderColor.Value, 0.1); //TODO: Set the thickness of the boarder
                        foreach (var column in _columns.Where(x => !x.Value.Hide).TakeAllButLast().ToList())
                        {
                            left += column.Value.Width.Value.ToXUnit(renderData.ElementBounds.Width);
                            renderData.Graphics.DrawLine(borderPen, renderData.ElementBounds.Left + left, renderData.ElementBounds.Top, renderData.ElementBounds.Left + left, renderData.ElementBounds.Bottom);
                        }
                    }

                    for (var i = pageRowSet.FromRow; i < pageRowSet.ToRow + 1; i++)
                    {
                        DocumentDataTableLine row;
                        try
                        {
                            row = dataTable.Rows[i];
                        }
                        catch (Exception exception)
                        {
                            var msg = string.Format("Looping from {0} to {1}. Currently at {2}, collection has {3} lines.", pageRowSet.FromRow, pageRowSet.ToRow + 1, i, dataTable.Rows.Count);
                            throw new InvalidOperationException(msg + string.Format("dataTable.Rows.Count={0}, i={1}, pageIndex={2}, page={3}, GetPageOffset={4}, index={5}, FromRow={6}, ToRow={7}, _pageRowSet.Count={8}, defaultRowset={9}", dataTable.Rows.Count, i, pageIndex, page, renderData.Section.GetPageOffset(), index, pageRowSet.FromRow, pageRowSet.ToRow, _pageRowSet.Count, defaultRowset), exception);
                        }

                        left = 0;
                        var lineSize = stdLineSize;
                        if (row is DocumentDataTableData)
                        {
                            var rowData = row as DocumentDataTableData;

                            foreach (var column in _columns.Where(x => !x.Value.Hide).ToList())
                            {
                                var cellData = GetValue(column.Key, rowData.Columns);

                                var alignmentJusttification = 0D;
                                if (column.Value.Align == Alignment.Right)
                                {
                                    var stringSize = renderData.Graphics.MeasureString(cellData, lineFont, XStringFormats.TopLeft);
                                    alignmentJusttification = column.Value.Width.Value.ToXUnit(renderData.ElementBounds.Width) - stringSize.Width - (columnPadding / 2);
                                }
                                else
                                {
                                    alignmentJusttification += columnPadding / 2;
                                }

                                var parsedHideValue = GetValue(column.Value.HideValue, rowData.Columns);
                                if (parsedHideValue == cellData)
                                {
                                    cellData = string.Empty;
                                }

                                //TODO: If the string is too long. Cut the string down.
                                var calculatedCellData = AssureThatTextFitsInColumn(renderData, cellData, column, columnPadding, lineFont);

                                renderData.Graphics.DrawString(calculatedCellData, lineFont, lineBrush, new XPoint(renderData.ElementBounds.Left + left + alignmentJusttification, renderData.ElementBounds.Top + top), XStringFormats.TopLeft);
                                left += column.Value.Width.Value.ToXUnit(renderData.ElementBounds.Width);
                            }

                            if (_skipLine != null && pageIndex % SkipLine.Interval == 0)
                            {
                                var skipLineHeight = SkipLine.Height.ToXUnit(renderData.ElementBounds.Height);

                                if (SkipLine.BorderColor != null)
                                {
                                    renderData.Graphics.DrawLine(new XPen(XColor.FromArgb((Color)SkipLine.BorderColor), 0.1), renderData.ElementBounds.Left, renderData.ElementBounds.Top + top + lineSize.Height + skipLineHeight / 2, renderData.ElementBounds.Right, renderData.ElementBounds.Top + top + lineSize.Height + skipLineHeight / 2);
                                }

                                top += skipLineHeight;
                            }
                        }
                        else if (row is DocumentDataTableGroup)
                        {
                            var group = row as DocumentDataTableGroup;

                            if (pageIndex != 1)
                            {
                                top += GroupSpacing.ToXUnit(renderData.ElementBounds.Height);
                            }

                            var groupData  = group.Content;
                            var stringSize = renderData.Graphics.MeasureString(groupData, groupFont, XStringFormats.TopLeft);
                            lineSize = stringSize;
                            var topLeftBox  = new XPoint(renderData.ElementBounds.Left + left, renderData.ElementBounds.Top + top);
                            var topLeftText = new XPoint(renderData.ElementBounds.Left + left + (columnPadding / 2), renderData.ElementBounds.Top + top);

                            if (GroupBackgroundColor != null)
                            {
                                var brush = new XSolidBrush(XColor.FromArgb(GroupBackgroundColor.Value));
                                var rect  = new XRect(topLeftBox, new XSize(renderData.ElementBounds.Width, stringSize.Height));
                                renderData.Graphics.DrawRectangle(new XPen(XColor.FromArgb(GroupBorderColor ?? GroupBackgroundColor.Value), 0.1), brush, rect);
                            }
                            else if (GroupBorderColor != null)
                            {
                                var rect = new XRect(topLeftBox, new XSize(renderData.ElementBounds.Width, stringSize.Height));
                                renderData.Graphics.DrawRectangle(new XPen(XColor.FromArgb(GroupBorderColor.Value), 0.1), rect);
                            }

                            renderData.Graphics.DrawString(groupData, groupFont, lineBrush, topLeftText, XStringFormats.TopLeft);
                            pageIndex = 0;
                        }

                        top += lineSize.Height;
                        top += RowPadding.ToXUnit(renderData.ElementBounds.Height);

                        pageIndex++;
                    }

                    ////Draw column separator lines
                    //if (ColumnBorderColor != null)
                    //{
                    //    left = 0;
                    //    var borderPen = new XPen(ColumnBorderColor.Value, 0.1); //TODO: Set the thickness of the boarder
                    //    foreach (var column in _columns.Where(x => !x.Value.Hide).TakeAllButLast().ToList())
                    //    {
                    //        left += column.Value.Width.Value.GetXUnitValue(renderData.ElementBounds.Width);
                    //        renderData.Graphics.DrawLine(borderPen, renderData.ElementBounds.Left + left, renderData.ElementBounds.Top, renderData.ElementBounds.Left + left, renderData.ElementBounds.Bottom);
                    //    }
                    //}
                }
            }

            if (renderData.DebugData != null)
            {
                renderData.Graphics.DrawRectangle(renderData.DebugData.Pen, renderData.ElementBounds);
            }
        }
Ejemplo n.º 20
0
        internal override int PreRender(IRenderData renderData)
        {
            _pageRowSet = new List <PageRowSet>();

            renderData.ElementBounds = GetBounds(renderData.ParentBounds);

            if (IsBackground && !renderData.IncludeBackground)
            {
                return(0);
            }

            var headerFont = new XFont(_headerFont.GetName(renderData.Section), _headerFont.GetSize(renderData.Section), _headerFont.GetStyle(renderData.Section));
            var lineFont   = new XFont(_contentFont.GetName(renderData.Section), _contentFont.GetSize(renderData.Section), _contentFont.GetStyle(renderData.Section));
            var groupFont  = new XFont(_groupFont.GetName(renderData.Section), _groupFont.GetSize(renderData.Section), _groupFont.GetStyle(renderData.Section));

            var firstColumn = _columns.FirstOrDefault();

            if (firstColumn.Value == null)
            {
                return(0);
            }

            var headerSize  = renderData.Graphics.MeasureString(firstColumn.Value.Title, headerFont, XStringFormats.TopLeft);
            var stdLineSize = renderData.Graphics.MeasureString(firstColumn.Value.Title, lineFont, XStringFormats.TopLeft);

            if (renderData.DocumentData != null)
            {
                var dataTable = renderData.DocumentData.GetDataTable(Name);
                if (dataTable != null)
                {
                    var top             = headerSize.Height + RowPadding.ToXUnit(renderData.ElementBounds.Height);
                    var pageIndex       = 1;
                    var firstLineOnPage = 0;
                    for (var i = 0; i < dataTable.Rows.Count; i++)
                    {
                        var lineSize = stdLineSize;
                        if (dataTable.Rows[i] is DocumentDataTableData)
                        {
                            if (_skipLine != null && pageIndex % SkipLine.Interval == 0)
                            {
                                top += SkipLine.Height.ToXUnit(renderData.ElementBounds.Height);
                            }
                        }
                        else if (dataTable.Rows[i] is DocumentDataTableGroup)
                        {
                            top      += GroupSpacing.ToXUnit(renderData.ElementBounds.Height);
                            lineSize  = renderData.Graphics.MeasureString("X", groupFont, XStringFormats.TopLeft);
                            pageIndex = 0;
                        }

                        top += lineSize.Height;
                        top += RowPadding.ToXUnit(renderData.ElementBounds.Height);

                        pageIndex++;

                        if (top > renderData.ElementBounds.Height - lineSize.Height)
                        {
                            _pageRowSet.Add(new PageRowSet {
                                FromRow = firstLineOnPage, ToRow = i
                            });
                            firstLineOnPage = i + 1;
                            top             = headerSize.Height + RowPadding.ToXUnit(renderData.ElementBounds.Height);
                        }
                    }

                    if (firstLineOnPage != dataTable.Rows.Count)
                    {
                        _pageRowSet.Add(new PageRowSet {
                            FromRow = firstLineOnPage, ToRow = dataTable.Rows.Count - 1
                        });
                    }
                }
            }

            return(_pageRowSet.Count);
        }
Ejemplo n.º 21
0
 public CountingCoversByDietJob(IReaderData readerData, IRenderData renderData, IDietService dietService)
 {
     _readerData  = readerData;
     _renderData  = renderData;
     _dietService = dietService;
 }
Ejemplo n.º 22
0
 public RenderPin(Bounds bounds, Quaternion rotation, IRenderData renderData)
 {
     Initialize(bounds, rotation, renderData);
 }
Ejemplo n.º 23
0
 internal abstract void Render(IRenderData renderData, int page);
Ejemplo n.º 24
0
 internal abstract int PreRender(IRenderData renderData);
Ejemplo n.º 25
0
 public void Initialize(Bounds bounds, Quaternion rotation, IRenderData renderData)
 {
     Bounds     = bounds;
     Rotation   = rotation;
     RenderData = renderData;
 }
Ejemplo n.º 26
0
 internal abstract void Render(IRenderData renderData);
Ejemplo n.º 27
0
        internal override int PreRender(IRenderData renderData)
        {
            _pageText = new List <string[]>();

            var maxBounds = GetBounds(renderData.ParentBounds);

            if (!renderData.IncludeBackground && IsBackground)
            {
                return(0);
            }

            var font  = new XFont(_font.GetName(renderData.Section), _font.GetSize(renderData.Section), _font.GetStyle(renderData.Section));
            var brush = new XSolidBrush(XColor.FromArgb(_font.GetColor(renderData.Section)));

            var text     = GetValue(renderData.DocumentData, renderData.PageNumberInfo, renderData.DocumentProperties);
            var textSize = renderData.Graphics.MeasureString(text, font, XStringFormats.TopLeft);

            var left = maxBounds.Left;
            var top  = maxBounds.Top;

            if (textSize.Width > maxBounds.Width || text.Contains(Environment.NewLine))
            {
                //Need to set data over more than one page
                var words = text.Split(' ');

                var sb    = new StringBuilder();
                var lines = new List <string>();
                foreach (var nextWord in words)
                {
                    var nws = new[] { nextWord };
                    if (nextWord.Contains(Environment.NewLine))
                    {
                        nws = nextWord.Split(Environment.NewLine.ToArray());
                        nws = nws.Select(x => x == string.Empty ? Environment.NewLine : x).ToArray();
                    }

                    foreach (var nw in nws)
                    {
                        var textSoFar = sb.ToString();
                        if (nw != Environment.NewLine)
                        {
                            sb.AppendFormat("{0} ", nw);
                        }
                        var nextTextSize = renderData.Graphics.MeasureString(sb.ToString(), font, XStringFormats.TopLeft);

                        //Now we are over the limit (Previous state will fit)
                        if (nextTextSize.Width > maxBounds.Width || nw == Environment.NewLine)
                        {
                            if (string.IsNullOrEmpty(textSoFar))
                            {
                                //One singe word that is too long, print it anyway
                                //renderData.Gfx.DrawString(sb.ToString(), font, brush, left, top, XStringFormats.TopLeft);
                                lines.Add(sb.ToString());
                            }
                            else
                            {
                                //renderData.Gfx.DrawString(ready, font, brush, left, top, XStringFormats.TopLeft);
                                lines.Add(textSoFar);
                                sb.Clear();
                                if (nw != Environment.NewLine)
                                {
                                    sb.AppendFormat("{0} ", nw);
                                }
                            }

                            top += nextTextSize.Height;

                            if (top > maxBounds.Bottom - nextTextSize.Height)
                            {
                                //Now we have reached the limit of the page
                                _pageText.Add(lines.ToArray());
                                lines.Clear();
                                top = maxBounds.Top;
                            }
                        }
                    }
                }

                lines.Add(sb.ToString());
                _pageText.Add(lines.ToArray());
            }
            else
            {
                _pageText.Add(new[] { text });
            }

            if (Height == null)
            {
                renderData.ElementBounds = new XRect {
                    Location = maxBounds.Location, Width = maxBounds.Width, Height = top - maxBounds.Top
                }
            }
            ;
            else
            {
                renderData.ElementBounds = maxBounds;
            }

            return(_pageText.Count);
        }