Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Id">테이블의 고유 ID, 중복시 에러남.</param>
        /// <param name="Width">테이블의 너비, -1이면 100%를 의미함.</param>
        public Table(string Id, int Width)
        {
            this.Id    = Id;
            this.Width = Width;

            mRows = new CRows();
        }
Esempio n. 2
0
        private int GetPrevColWidth(CRows rows, int rw, int cl, int ColSpan)
        {
            int ColWidth = 0;

            for (int i = cl; i < (cl + ColSpan); i++)
            {
                ColWidth += GetPrevColWidth(rows, rw, i);
            }
            return(ColWidth);
        }
Esempio n. 3
0
        private int GetPrevColWidth(CRows rows, int rw, int cl)
        {
            int WidthLast = 0;

            int WidthBeforeSpan = rows[rw - 1].Columns[cl].WidthBeforeSpan;
            int Width           = rows[rw - 1].Columns[cl].Width;

            if ((Width == 0) && (WidthBeforeSpan > 0))
            {
                WidthLast = WidthBeforeSpan;
            }
            else if ((Width > 0) && (WidthBeforeSpan == 0))
            {
                WidthLast = Width;
            }
            else if ((Width > 0) && (WidthBeforeSpan > 0))
            {
                WidthLast = (Width > WidthBeforeSpan) ? WidthBeforeSpan : Width;
            }

            return(WidthLast);
        }
Esempio n. 4
0
        private void SetColWidthOverwriteStyle(Table table)
        {
            CRows rows            = table.Rows;
            int   ColSpanRest     = 0;
            bool  ColSpanStarted  = false;
            int   ColSpanWidthAvg = 0;
            int   ColWidth        = 0;

            for (int rw = 0, rw2 = rows.Count; rw < rw2; rw++)
            {
                CRow row = table.Rows[rw];

                //.TABLE 스타일 있다면 적용.
                HtmlStyle styT = mHtmlStyles["TABLE"];
                if (styT != null)
                {
                    OverwriteStyle(styT, table.Style);
                }

                OverwriteStyle(table.Style, row.Style);
                //.TR 스타일 있다면 적용.
                HtmlStyle styTR = mHtmlStyles["TR"];
                if (styTR != null)
                {
                    OverwriteStyle(styTR, row.Style);
                }

                Columns cols = row.Columns;

                for (int cl = 0, cl2 = cols.Count; cl < cl2; cl++)
                {
                    Column col = cols[cl];

                    OverwriteStyle(row.Style, col.Style);
                    //.TD 스타일 있다면 적용.
                    HtmlStyle styTD = mHtmlStyles["TD"];
                    if (styTD != null)
                    {
                        OverwriteStyle(styTD, col.Style);
                    }

                    for (int v = 0, v2 = col.Values.Count; v < v2; v++)
                    {
                        OverwriteStyle(col.Style, col.Values[v].Style);
                        //if (col.Values[v].Text == "333333-3333333")
                        //	System.Diagnostics.Debug.Assert(false);
                    }

                    if (rw == 0)
                    {
                        if (col.ColSpan > 1)
                        {
                            ColSpanStarted      = true;
                            ColSpanRest         = col.ColSpan - 1;
                            ColWidth            = col.Width;
                            ColSpanWidthAvg     = Convert.ToInt32(ColWidth / col.ColSpan);
                            col.WidthBeforeSpan = ColSpanWidthAvg;
                        }
                        else if (ColSpanStarted)
                        {
                            ColSpanRest--;
                            if (ColSpanRest == 0)
                            {
                                ColSpanStarted = false;
                            }
                            col.WidthBeforeSpan = ColSpanWidthAvg;
                            col.Width           = 0;
                        }
                        else
                        {
                            if (col.Width == 0)
                            {
                                //첫번째 행이면 테이블 너비 / 열 개수
                                col.Width = Convert.ToInt32(table.Width / row.Columns.Count);
                            }
                        }
                    }
                    else
                    {
                        if (col.ColSpan > 1)
                        {
                            ColSpanStarted = true;
                            ColSpanRest    = col.ColSpan - 1;

                            col.WidthBeforeSpan = GetPrevColWidth(rows, rw, cl);
                            if (col.Width == 0)
                            {
                                col.Width = GetPrevColWidth(rows, rw, cl, col.ColSpan);
                            }
                        }
                        else if (ColSpanStarted)
                        {
                            ColSpanRest--;
                            if (ColSpanRest == 0)
                            {
                                ColSpanStarted = false;
                            }
                            col.WidthBeforeSpan = GetPrevColWidth(rows, rw, cl);
                            col.Width           = 0;
                        }
                        else
                        {
                            if (col.Width == 0)
                            {
                                //두번째 행부터는 이전 행의 너비를 따름.
                                col.Width = GetPrevColWidth(rows, rw, cl);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public void PrintTable(Graphics g, Table table, float x, ref int y, int ContainerMarginLeft, int ContainerWidth)
        {
            float XStart      = 0;
            int   YStart      = 0;
            Color BorderColor = table.BorderColor;

            //100%에 해당
            if (table.Width == -1)
            {
                table.Width = ContainerWidth - table.Border;
            }

            SetColWidthOverwriteStyle(table);

            Pen PenBorder = new Pen(new SolidBrush(BorderColor), table.Border);
            Pen PenTopLine, PenBottomLine;

            switch (table.Align)
            {
            case HAlign.Left:
                x += ContainerMarginLeft;
                break;

            case HAlign.Center:
                x += (ContainerWidth - table.Width) / 2;
                break;

            case HAlign.Right:
                x += ContainerWidth - table.Width;
                break;
            }

            XStart = x; YStart = y;

            CRows rows = table.Rows;

            for (int rw = 0, rw2 = rows.Count; rw < rw2; rw++)
            {
                CRow row = rows[rw];
                //if (row.Style.BackgroundColor == Color.Black) {int xx = 0;}

                row.Height = GetRowHeight(g, table, row);

                x = XStart;


                int TopLineWidth = 0;
                if (rw == 0)
                {
                    TopLineWidth = table.Border;
                    PenTopLine   = new Pen(new SolidBrush(BorderColor), TopLineWidth);
                }
                else
                {
                    TopLineWidth = table.Border > 0 ? 1 : 0;
                    PenTopLine   = new Pen(new SolidBrush(BorderColor), TopLineWidth);
                }

                int BottomLineWidth = 0;
                if ((rw + 1) == rw2)
                {
                    BottomLineWidth = table.Border;
                    PenBottomLine   = new Pen(new SolidBrush(BorderColor), BottomLineWidth);
                }
                else
                {
                    BottomLineWidth = table.Border > 0 ? 1 : 0;
                    PenBottomLine   = new Pen(new SolidBrush(BorderColor), BottomLineWidth);
                }

                y += TopLineWidth + table.CellSpacing;

                Columns cols = row.Columns;

                for (int cl = 0, cl2 = cols.Count; cl < cl2; cl++)
                {
                    Column col = cols[cl];

                    col.Align  = OverwriteHAlign(row.Align, col.Align);
                    col.VAlign = OverwriteVAlign(row.VAlign, col.VAlign);

                    //Values.Count가 2개 이상이면 DrawStringStep에서 정렬함.
                    if (col.Values.Count == 1)
                    {
                        switch (col.Align)
                        {
                        case HAlign.Left:
                            col.Values[0].Style.Format.Alignment = StringAlignment.Near;
                            break;

                        case HAlign.Center:
                            col.Values[0].Style.Format.Alignment = StringAlignment.Center;
                            break;

                        case HAlign.Right:
                            col.Values[0].Style.Format.Alignment = StringAlignment.Far;
                            break;
                        }
                    }

                    //수직 가운데는 StringFormat 속성에 없으므로 시작위치를 설정함.
                    float ytext = 0;
                    switch (col.VAlign)
                    {
                    case VAlign.Top:
                        ytext = y + table.CellPadding + col.Style.BorderTop.WidthReal;
                        break;

                    case VAlign.Middle:
                        float textHeightMargin = row.Height - (table.CellPadding * 2)
                                                 - col.Style.BorderTop.WidthReal - col.Style.BorderBottom.WidthReal;
                        ytext = y + table.CellPadding + col.Style.BorderTop.WidthReal
                                + ((textHeightMargin - col.TextHeight) / 2f);
                        break;

                    case VAlign.Bottom:
                        ytext = y + (row.Height - table.CellPadding - col.Style.BorderBottom.WidthReal
                                     - col.TextHeight);
                        break;
                    }

                    if (col.Values.Count > 0)
                    {
                        //안에 Table이 있으면 RowHeight가 변경되므로 문자열 출력이 항상 먼저 있어야 함.
                        //그러나 이번이 두번째 이상의 열이면 첫번째 열과 높이가 틀려진다는 버그 있음.
                        if (col.Values[0].Table != null)
                        {
                            //테이블이 안에 있으면 무조건 왼쪽 정렬, 위쪽 정렬로 설정함.
                            int Y2    = y + table.CellPadding + col.Style.BorderTop.WidthReal;
                            int Y2Old = Y2;
                            //수직선인 경우 가운데를 중심으로 양쪽의 공간을 차지함.
                            float X2 = x + (table.Border / 2f) + (col.Values[0].Table.Border / 2f);
                            PrintTable(g, col.Values[0].Table, X2, ref Y2, 0, col.Width);

                            int RowHeight2 = Y2 - Y2Old;
                            if (RowHeight2 > row.Height)
                            {
                                row.Height = RowHeight2;
                            }
                        }
                        else
                        {
                            if (col.Values.Count == 1)
                            {
                                //if (col.Values[0].Text == "구좌코드"){int xx=0;}
                                g.DrawString(col.Values[0].Text, col.Values[0].Style.Font, new SolidBrush(col.Values[0].Style.Color),
                                             new RectangleF(x, ytext, col.Width - table.Border, col.TextHeight),
                                             col.Values[0].Style.Format);
                            }
                            else if (col.Values.Count > 1)
                            {
                                DrawStringStep(g, col, Convert.ToSingle(x), ytext, col.Width - table.Border, col.TextHeight);
                            }
                        }
                    }

                    if (col.Style.BackgroundColor != Color.Transparent)
                    {
                        RectangleF rectBack = new RectangleF(
                            x + (table.Border / 2f), y,
                            col.Width - table.Border, row.Height);

                        g.FillRectangle(new SolidBrush(col.Style.BackgroundColor), rectBack);
                    }

                    if (table.Border > 0)
                    {
                        if (rw == 0)
                        {
                            //위쪽
                            g.DrawLine(PenTopLine,
                                       x - (table.Border / 2f), y - table.CellSpacing - (TopLineWidth / 2f),
                                       x + col.Width - (table.Border / 2f), y - table.CellSpacing - (TopLineWidth / 2f));
                        }
                        if (cl == 0)
                        {
                            //왼쪽
                            g.DrawLine(PenBorder,
                                       x, y - table.CellSpacing,
                                       x, y + row.Height + BottomLineWidth);
                        }

                        //오른쪽
                        g.DrawLine(PenBorder,
                                   x + col.Width, y - table.CellSpacing - TopLineWidth,
                                   x + col.Width, y + row.Height);
                        //아래쪽
                        g.DrawLine(PenBottomLine,
                                   x + (table.Border / 2f), y + row.Height + (BottomLineWidth / 2f),
                                   x + col.Width + (table.Border / 2f), y + row.Height + (BottomLineWidth / 2f));
                    }

                    //BORDER-TOP 등의 스타일 적용
                    if (col.Style.BorderTop.WidthReal > 0)
                    {
                        //위쪽
                        DrawBorder(g, col.Style.BorderTop.Color,
                                   x + (table.Border / 2f), y,
                                   col.Width - table.Border, col.Style.BorderTop.Width, BorderDirection.Top, col.Style.BorderTop.Style);
                    }
                    if (col.Style.BorderRight.WidthReal > 0)
                    {
                        //오른쪽
                        DrawBorder(g, col.Style.BorderRight.Color,
                                   x + col.Width - (table.Border / 2f), y,
                                   row.Height, col.Style.BorderRight.Width, BorderDirection.Right, col.Style.BorderRight.Style);
                    }
                    if (col.Style.BorderBottom.WidthReal > 0)
                    {
                        //아래쪽
                        DrawBorder(g, col.Style.BorderBottom.Color,
                                   x + (table.Border / 2f), y + row.Height,
                                   col.Width - table.Border, col.Style.BorderBottom.Width, BorderDirection.Bottom, col.Style.BorderBottom.Style);
                    }
                    if (col.Style.BorderLeft.WidthReal > 0)
                    {
                        //왼쪽
                        DrawBorder(g, col.Style.BorderLeft.Color,
                                   x + (table.Border / 2f), y,
                                   row.Height, col.Style.BorderLeft.Width, BorderDirection.Left, col.Style.BorderLeft.Style);
                    }

                    //다음 번 루프에선 span된 열은 건너뛰게 함.
                    if (col.ColSpan > 1)
                    {
                        cl += (col.ColSpan - 1);
                    }

                    x += col.Width;
                }                 //cl

                y += row.Height;
            }             //rw

            y += table.Border;
        }