示例#1
0
        void HandleM_printDrawPage(object o, DrawPageArgs args)
        {
            // Create a Print Context from the Print Operation
            PrintContext context = args.Context;

            // Create a Cairo Context from the Print Context
            Cairo.Context cr = context.CairoContext;

            // Get the width of the Print Context
            double width = context.Width;

            // Create a rectangle to be used for the Content
            cr.Rectangle(0, 0, width, headerHeight);
            cr.SetSourceRGB(0.95, 0.95, 0.95);
            cr.FillPreserve();

            // Create a Stroke to outline the Content
            cr.SetSourceRGB(0, 0, 0);
            cr.LineWidth = 1;
            cr.Stroke();

            // Create a Pango Layout for the Text
            Pango.Layout layout = context.CreatePangoLayout();
            // Get the Text Height fromt the Height of the layout and the Height of the Page
            int layoutWidth, layoutHeight;

            layout.GetSize(out layoutWidth, out layoutHeight);
            double textHeight = (double)layoutHeight / (double)pangoScale;

            cr.MoveTo(5, (headerHeight - textHeight) / 2);

            // Set the Font and Font Size desired
            Pango.FontDescription desc = Pango.FontDescription.FromString("sans 12");
            layout.FontDescription = desc;

            // Create a Header with the FileName and center it on the page
            layout.SetText(m_cache.Name + " : " + m_cache.CacheName);
            //layout.Width = (int) width *3;
            layout.Alignment = Pango.Alignment.Left;
            Pango.CairoHelper.ShowLayout(cr, layout);


            // cr.MoveTo (width/2, (headerHeight - textHeight) / 2);


            // Set the Page Number in the Footer with a right alignment
            string pageStr = String.Format(Catalog.GetString("Page {0} of {1}"), args.PageNr + 1, m_numPages);

            layout.SetText(pageStr);
            layout.Alignment = Pango.Alignment.Right;

            cr.MoveTo(width - 75, (headerHeight - textHeight) / 2);
            Pango.CairoHelper.ShowLayout(cr, layout);

            // Create a new Pango Layout for the Content
            layout = null;
            layout = context.CreatePangoLayout();

            // Set the Description of the Content
            desc      = Pango.FontDescription.FromString("sans");
            desc.Size = (int)(m_fontSize * pangoScale);
            layout.FontDescription = desc;

            // Move to the beginning of the Content, which is after the Header Height and Gap
            cr.MoveTo(0, headerHeight + headerGap);

            int line = args.PageNr * m_linesPerPage;

            // Draw the lines on the page according to how many lines there are left and how many lines can fit on the page
            for (int i = 0; i < m_linesPerPage && line < m_numLines; i++)
            {
                layout.SetMarkup(m_Lines[line].TrimStart());
                Pango.CairoHelper.ShowLayout(cr, layout);
                cr.RelMoveTo(0, m_fontSize + 0.5);
                line++;
            }

            layout = null;
            context.Dispose();
        }