Пример #1
0
        /// <summary>
        /// Draw centred text
        /// </summary>
        /// <param name="context">The graphics context to draw on</param>
        /// <param name="text">The text to draw</param>
        /// <param name="point">The point to centre the text around</param>
        protected void DrawCentredText(IDrawContext context, string text, Point point)
        {
            (int left, int top, int width, int height) = context.GetPixelExtents(text, false, false);
            double x = point.X - (width / 2 + left);
            double y = point.Y - (height / 2 + top);

            context.MoveTo(x, y);
            context.DrawText(text, false, false);
        }
Пример #2
0
        /// <summary>Calculte the column widths in pixels.</summary>
        /// <param name="cr">The current draing context.</param>
        private void CalculateColumnWidths(IDrawContext cr)
        {
            ColumnWidths = new int[DataProvider.ColumnCount];
            for (int columnIndex = 0; columnIndex < DataProvider.ColumnCount; columnIndex++)
            {
                int columnWidth = 0;
                for (int rowIndex = 0; rowIndex < NumberFrozenRows + 1; rowIndex++)
                {
                    var text = DataProvider.GetCellContents(columnIndex, rowIndex);
                    if (text == null)
                    {
                        text = string.Empty;
                    }

                    var rectangle = cr.GetPixelExtents(text, true, false);

                    columnWidth = Math.Max(columnWidth, rectangle.Width);
                }
                ColumnWidths[columnIndex] = columnWidth + ColumnPadding * 2;
            }
        }
Пример #3
0
        /// <summary>Draw a single cell to the context.</summary>
        /// <param name="cr">The context to draw in.</param>
        /// <param name="columnIndex">The column index.</param>
        /// <param name="rowIndex">The row index.</param>
        private void DrawCell(IDrawContext cr, int columnIndex, int rowIndex)
        {
            try
            {
                var text       = DataProvider.GetCellContents(columnIndex, rowIndex);
                var cellBounds = CalculateBounds(columnIndex, rowIndex);
                if (cellBounds != null)
                {
                    if (text == null)
                    {
                        text = string.Empty;
                    }

                    cr.Rectangle(cellBounds.Clip(Width - 20, Height).ToRectangle());
                    cr.Clip();

                    cr.SetLineWidth(lineWidth);

                    cr.Rectangle(cellBounds.ToRectangle());
                    if (CellPainter.PaintCell(columnIndex, rowIndex))
                    {
                        // Draw the filled in cell.

                        cr.State = CellPainter.GetCellState(columnIndex, rowIndex);
                        cr.DrawFilledRectangle(cellBounds.Left, cellBounds.Top, cellBounds.Width - 5, cellBounds.Height - 5);


                        // Draw cell outline.
                        if (ShowLines)
                        {
                            cr.Rectangle(cellBounds.ToRectangle());
                            cr.Stroke();
                        }

                        // Measure text for cell.
                        var r = cr.GetPixelExtents(text,
                                                   CellPainter.TextBold(columnIndex, rowIndex),
                                                   CellPainter.TextItalics(columnIndex, rowIndex));

                        // Vertically center the text.
                        double y = cellBounds.Top + (cellBounds.Height - r.Height) / 2;

                        // Horizontal alignment is determined by the cell painter.
                        double x;
                        if (CellPainter.TextLeftJustify(columnIndex, rowIndex))
                        {
                            x = cellBounds.Left + ColumnPadding;
                        }
                        else
                        {
                            x = cellBounds.Right - ColumnPadding - r.Width;
                        }

                        cr.MoveTo(x, y);
                        cr.DrawText(text, CellPainter.TextBold(columnIndex, rowIndex),
                                    CellPainter.TextItalics(columnIndex, rowIndex));
                    }
                    cr.ResetClip();
                    cr.State = States.Normal;
                }
            }
            catch (Exception ex)
            {
                MainView.MasterView.ShowError(ex);
            }
        }