Пример #1
0
        private RectangleF RenderTableHeader(Font font, RectangleF rc, params string[] fields)
        {
            // calculate cell width (same for all columns)
            RectangleF rcCell = rc;

            rcCell.Width  = rc.Width / fields.Length;
            rcCell.Height = 0;

            // calculate cell height (max of all columns)
            foreach (string field in fields)
            {
                float height = PdfCotizacion.MeasureString(field, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }

            // render header cells
            StringFormat sf = new StringFormat();

            foreach (string field in fields)
            {
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;

                PdfCotizacion.FillRectangle(Brushes.Black, rcCell);
                PdfCotizacion.DrawString(field, font, Brushes.White, rcCell, sf);
                rcCell.Offset(rcCell.Width, 0);
            }

            // update rectangle and return it
            rc.Offset(0, rcCell.Height);
            return(rc);
        }
Пример #2
0
        private RectangleF RenderTableRow(Font font, Font hdrFont, RectangleF rcPage, RectangleF rc, string[] fields, DataRow dr)
        {
            // calculate cell width (same for all columns)
            RectangleF rcCell = rc;

            rcCell.Width  = rc.Width / fields.Length;
            rcCell.Height = 0;

            // calculate cell height (max of all columns)
            rcCell.Inflate(-4, 0);
            foreach (string field in fields)
            {
                string text   = dr[field].ToString();
                float  height = PdfCotizacion.MeasureString(text, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }
            rcCell.Inflate(4, 0);

            // break page if we have to
            if (rcCell.Bottom > rcPage.Bottom)
            {
                PdfCotizacion.NewPage();
                rc       = RenderTableHeader(hdrFont, rcPage, fields);
                rcCell.Y = rc.Y;
            }

            // center vertically just to show how
            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Near;

            // render data cells
            Pen pen = new Pen(Brushes.Blue, 0.1f);

            foreach (string field in fields)
            {
                // get content
                string text = dr[field].ToString();

                // set horizontal alignment
                double d;
                sf.Alignment = (double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out d))
                    ? StringAlignment.Near
                    : StringAlignment.Near;

                // render cell
                PdfCotizacion.DrawRectangle(pen, rcCell);
                rcCell.Inflate(-4, 0);
                PdfCotizacion.DrawString(text, font, Brushes.Black, rcCell, sf);
                rcCell.Inflate(4, 0);
                rcCell.Offset(rcCell.Width, 0);
            }
            pen.Dispose();

            // update rectangle and return it
            rc.Offset(0, rcCell.Height);
            return(rc);
        }
Пример #3
0
        internal RectangleF RenderParagraph(string text, Font font, RectangleF rcPage, RectangleF rc, bool outline, int Tipo)
        {
            // if it won't fit this page, do a page break
            rc.Height = PdfCotizacion.MeasureString(text, font, rc.Width).Height;
            if (rc.Bottom > rcPage.Bottom)
            {
                PdfCotizacion.NewPage();
                rc.Y = rcPage.Top;
            }

            // draw the string
            StringFormat sf = new StringFormat();

            if (Tipo == 1)
            {
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                PdfCotizacion.DrawString(text, font, Brushes.Black, rc, sf);
            }
            else if (Tipo == 2)
            {
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Near;
                PdfCotizacion.DrawString(text, font, Brushes.Black, rc, sf);
            }
            else if (Tipo == 3)
            {
                sf.Alignment     = StringAlignment.Far;
                sf.LineAlignment = StringAlignment.Far;
                PdfCotizacion.DrawString(text, font, Brushes.Black, rc, sf);
            }


            //add headings to outline
            if (outline)
            {
                PdfCotizacion.DrawLine(Pens.Black, rc.X, rc.Y, rc.Right, rc.Y);
            }


            // update rectangle for next time
            rc.Offset(0, rc.Height);
            return(rc);
        }