Example #1
0
        protected override void OnDrawPage(PrintContext context, int page_nr)
        {
            Context cairoContext;

            if (previewSurface != null)
            {
                var file   = System.IO.Path.GetTempFileName();
                var target = new SvgSurface(file,
                                            formArea.Width,
                                            formArea.Height);
                cairoContext = new Context(target);
                pageFiles.Add(file);
            }
            else
            {
                cairoContext = context.CairoContext;
            }

            pageContexts.Add(cairoContext);

            using (var dp = new DrawingProviderCairo(cairoContext, context.CreatePangoLayout())) {
                dp.DrawingScaleX            = drawingScaleX;
                dp.DrawingScaleY            = drawingScaleY;
                formToPrint.DrawingProvider = dp;

                formToPrint.Draw(page_nr, new PointD());
            }
        }
Example #2
0
        protected override void OnBeginPrint(PrintContext context)
        {
            cancelled = false;
            Cleanup();

            if (context == null)
            {
                throw new NullReferenceException("context is null");
            }

            if (context.PageSetup == null)
            {
                throw new NullReferenceException("context.PageSetup is null");
            }

            if (formToPrint == null)
            {
                throw new NullReferenceException("formToPrint is null");
            }

            if (formToPrint.PageMargins == null)
            {
                throw new NullReferenceException("formToPrint.PageMargins is null");
            }

            using (var dp = new DrawingProviderCairo(context.CairoContext, context.CreatePangoLayout())) {
                drawingScaleX               = (float)(context.Width / (context.PageSetup.GetPageWidth(Unit.Pixel) * SD_SCALE));
                drawingScaleY               = (float)(context.Height / (context.PageSetup.GetPageHeight(Unit.Pixel) * SD_SCALE));
                drawingScaleIsValid         = true;
                dp.DrawingScaleX            = drawingScaleX;
                dp.DrawingScaleY            = drawingScaleY;
                formToPrint.DrawingProvider = dp;

                if (formToPrint.PageMargins.Top == int.MaxValue)
                {
                    formToPrint.PageMargins.Top    = UseFullPage ? 0 : (int)Math.Round(context.PageSetup.GetTopMargin(Unit.Pixel) * SD_SCALE);
                    formToPrint.PageMargins.Bottom = UseFullPage ? 0 : (int)Math.Round(context.PageSetup.GetBottomMargin(Unit.Pixel) * SD_SCALE);
                    formToPrint.PageMargins.Left   = UseFullPage ? 0 : (int)Math.Round(context.PageSetup.GetLeftMargin(Unit.Pixel) * SD_SCALE);
                    formToPrint.PageMargins.Right  = UseFullPage ? 0 : (int)Math.Round(context.PageSetup.GetRightMargin(Unit.Pixel) * SD_SCALE);
                }

                if (formToPrint.PageWidth <= 0)
                {
                    formToPrint.PageWidth = pageWidth != null ?
                                            pageWidth.Value :
                                            (int)Math.Round(context.PageSetup.GetPageWidth(Unit.Pixel) * SD_SCALE);
                }

                if (formToPrint.PageHeight <= 0)
                {
                    formToPrint.PageHeight = (int)Math.Round(context.PageSetup.GetPageHeight(Unit.Pixel) * SD_SCALE);
                }

                formArea.X      = (int)(formToPrint.PageMargins.Left * drawingScaleX);
                formArea.Y      = (int)(formToPrint.PageMargins.Top * drawingScaleY);
                formArea.Width  = (int)(formToPrint.PageWidth * drawingScaleX);
                formArea.Height = (int)(formToPrint.PageHeight * drawingScaleY);
                paperWidth      = formArea.Width + (int)((formToPrint.PageMargins.Left + formToPrint.PageMargins.Right) * drawingScaleX);
                paperHeight     = formArea.Height + (int)((formToPrint.PageMargins.Top + formToPrint.PageMargins.Bottom) * drawingScaleY);
                ErrorHandling.LogError(string.Format("OnBeginPrint Paper: {0}x{1}, Form Area: {2}x{3}, Form Size: {4}x{5}, Orientation: {6}",
                                                     paperWidth,
                                                     paperHeight,
                                                     formArea.Width,
                                                     formArea.Height,
                                                     formToPrint.PageWidth,
                                                     formToPrint.PageHeight,
                                                     context.PageSetup.Orientation), ErrorSeverity.Information);

                totalPages  = formToPrint.GetTotalPages();
                pageColumns = formToPrint.GetPageColumns();
                pageRows    = formToPrint.GetPageRows();

                NPages = totalPages;
                formToPrint.DrawingProvider = null;
            }

            base.OnBeginPrint(context);
        }