Beispiel #1
0
        public CRow Add(CRow c)
        {
            mht.Add(c.Id, c);
            KeyIndex.Add(c.Id);

            return(c);
        }
Beispiel #2
0
        public static Table AppendRowCol(Table t, int Rows, int Cols)
        {
            for (int rw = 0; rw < Rows; rw++)
            {
                CRow row = t.Rows.Add(new CRow("r" + rw.ToString()));

                for (int cl = 0; cl < Cols; cl++)
                {
                    Column col = row.Columns.Add(new Column("c" + cl.ToString()));
                }
            }

            return(t);
        }
Beispiel #3
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);
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private int GetRowHeight(Graphics g, Table table, CRow row)
        {
            int Max = 0;

            Columns cols = row.Columns;

            for (int cl = 0, cl2 = cols.Count; cl < cl2; cl++)
            {
                Column col = cols[cl];
                Value  value;
                int    BorderWidth   = col.Style.BorderTop.WidthReal + col.Style.BorderBottom.WidthReal;
                float  drawableWidth = col.Width - table.Border;

                if (col.Values.Count > 0)
                {
                    if (col.Values.Count == 1)
                    {
                        value = col.Values[0];
                        if (value.Text != "")
                        {
                            SizeF textSize = g.MeasureString(value.Text, value.Style.Font,
                                                             Convert.ToInt32(drawableWidth), value.Style.Format);
                            col.TextHeight = textSize.Height;
                        }
                    }
                    else if (col.Values.Count > 1)
                    {
                        float textWidth     = 0;
                        float y             = 0;
                        float textHeightMax = 0;
                        for (int v = 0, v2 = col.Values.Count; v < v2; v++)
                        {
                            value = col.Values[v];
                            if (value.Text == "")
                            {
                                continue;
                            }

                            for (int c = 0, c2 = value.Text.Length; c < c2; c++)
                            {
                                string s = value.Text.Substring(c, 1);

                                SizeF textSize = g.MeasureString(s, value.Style.Font, 999999, value.Style.Format);
                                if (textSize.Height > textHeightMax)
                                {
                                    textHeightMax = textSize.Height;
                                }

                                float WidthRMargin = textSize.Width * WidthRate;
                                textWidth += WidthRMargin;

                                if ((textWidth + (textSize.Width * 0.277f) > drawableWidth) || s == "\n")
                                {
                                    if (textWidth + (textSize.Width * 0.277f) > drawableWidth)
                                    {
                                        c--;                                         //넘친 문자열은 다음 번 루핑에서 인쇄되게 함.
                                    }
                                    else if (s == "\n")
                                    {
                                    }

                                    y            += textHeightMax * HeightRate;
                                    textHeightMax = textSize.Height;
                                    textWidth     = 0;
                                }
                            }                     //c
                        }                         //v

                        col.TextHeight = y + textHeightMax;
                    }
                }

                int Cur = (table.CellPadding * 2) + BorderWidth + Convert.ToInt32(col.TextHeight);

                if (row.Height > Cur)
                {
                    Cur = row.Height;
                }

                if (Cur > Max)
                {
                    Max = Cur;
                }
            }

            return(Max);
        }
Beispiel #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;
        }