Beispiel #1
0
        int DoPrintPage(Graphics g,
            float x0,
            float y0,
            Page page,
            out string strError)
        {
            strError = "";

            /*
            StringFormat format = new StringFormat();
            format.LineAlignment = StringAlignment.Far;
             * */

            for (int i = 0; i < page.Lines.Count; i++)
            {
                PrintLine line = page.Lines[i];
                Debug.Assert(string.IsNullOrEmpty(line.FontDef) == false, "string.IsNullOrEmpty(line.FontDef) == false 不满足");

                Font font = Global.BuildFont(line.FontDef);
                Color color = GetColor(line.ColorDef);

                try
                {
                    float x = line.X + x0 + line.Indent;
                    float y = line.Y + y0;

                    float per_sep = 0;

                    if (line.HorzAlign == HorzAlign.Right
                        && line.Boxes.Count > 0)
                    {
                        float right_blank = line.Width - line.Indent - GetLineWidth(line);
                        if (right_blank > 0)
                            x += right_blank;
                    }
                    else if (line.HorzAlign == HorzAlign.Center
                        && line.Boxes.Count > 0)
                    {
                        float right_blank = line.Width - line.Indent - GetLineWidth(line);
                        // x += line.Indent;   // - 2012/4/23 change
                        x += right_blank/2;
                    }
                    else if (line.HorzAlign == HorzAlign.LeftRight
                        && line.Boxes.Count > 1
                        && line.IsParagraphTail == false)
                    {
                        float right_blank = line.Width - line.Indent - GetLineWidth(line);
                        if (right_blank > 0)
                            per_sep = right_blank / ( line.Boxes.Count - 1);
                    }

                    for (int j = 0; j < line.Boxes.Count; j++)
                    {
                        Box box = line.Boxes[j];

                        //  如果中间有字体变化
                        string strFontString = box.FontDef;
                        if (String.IsNullOrEmpty(strFontString) == false)
                        {
                            font.Dispose();
                            font = Global.BuildFont(strFontString);
                        }

                        //  如果中间有颜色变化
                        string strColorString = box.ColorDef;
                        if (String.IsNullOrEmpty(strColorString) == false)
                        {
                            color = GetColor(strColorString);
                        }

                        using (Brush brush = new SolidBrush(color))
                        {
                            g.DrawString(box.Text,
                                font,
                                brush,
                                new PointF(x, y + (line.Height * line.BaseRatio) - box.Base));
                        }
                        x += box.Width + box.LeftBlank + per_sep;
                    }
                }
                finally
                {
                    font.Dispose();
                }
            }

            return 0;
        }
Beispiel #2
0
        // 处理一个矩形区域
        int DoRect(
            Graphics g,
            XmlNode nodeContainer,
            RectParam rect_def,
            bool bRemainPage,
            Hashtable macro_table,
            RectGroup rect_group,
            ref List<Page> pages,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            Padding padding = new Padding(0, 0, 0, 0);
            string strPadding = DomUtil.GetAttr(nodeContainer,
                "padding");
            if (String.IsNullOrEmpty(strPadding) == false)
            {
                nRet = GetPadding(strPadding,
                out padding,
                out strError);
                if (nRet == -1)
                {
                    strError = "元素<" + nodeContainer.Name + ">中padding属性值 '" + strPadding + "' 格式错误: " + strError;
                    return -1;
                }
            }

            rect_def.Padding = padding;


            List<PrintLine> lines = new List<PrintLine>();

            // 将一个容器元素下级的全部内容切割为Line数组
            nRet = Process(g,
                rect_def,
                nodeContainer,
                macro_table,
                rect_group,
        ref lines,
        out strError);
            if (nRet == -1)
                return -1;

            SetLastLine(lines);

            // 组装到Page中
            int iPage = 0;
            Page current_page = null;
            if (pages.Count > iPage)
                current_page = pages[iPage];
            else
            {
                current_page = new Page();
                pages.Add(current_page);
            }
            float current_height = 0;
            for (int i = 0; i < lines.Count; i++)
            {
                PrintLine line = lines[i];

                if (current_height + line.Height > rect_def.Height - rect_def.Padding.Vertical
                    && current_page.Lines.Count > 0    // 至少有一个行
                    && bRemainPage == false)
                {
                    // 新增一页
                    current_height = 0;
                    iPage++;
                    if (pages.Count > iPage)
                        current_page = pages[iPage];
                    else
                    {
                        current_page = new Page();
                        pages.Add(current_page);
                    }

                }

                // 
                line.X += rect_def.X + rect_def.Padding.Left;
                line.Y += rect_def.Y + rect_def.Padding.Top + current_height;
                current_page.Lines.Add(line);

                current_height += line.Height;
            }

            return iPage;
        }