private void PushRenderStates() { // Push current transform var transform = new System.Windows.Media.MatrixTransform(_transform.XX, _transform.XY, _transform.YX, _transform.YY, _transform.TX, _transform.TY); _drawingContext.PushTransform(transform); }
private bool PushRenderStates() { var clipped = !_activeGroup.Bound.IsEmpty; // Push clipping rect if (clipped) { var clipTransform = new Transform(_activeGroup.Transform); // Push clipping transform { var transform = new System.Windows.Media.MatrixTransform(clipTransform.XX, clipTransform.XY, clipTransform.YX, clipTransform.YY, clipTransform.TX, clipTransform.TY); _drawingContext.PushTransform(transform); } // Push clipping rect { var geometry = new System.Windows.Media.RectangleGeometry(_activeGroup.Bound); _drawingContext.PushClip(geometry); } // Push inverse clipping transform { clipTransform.Invert(); var transform = new System.Windows.Media.MatrixTransform(clipTransform.XX, clipTransform.XY, clipTransform.YX, clipTransform.YY, clipTransform.TX, clipTransform.TY); _drawingContext.PushTransform(transform); } } // Push current transform { var transform = new System.Windows.Media.MatrixTransform(_transform.XX, _transform.XY, _transform.YX, _transform.YY, _transform.TX, _transform.TY); _drawingContext.PushTransform(transform); } return(clipped); }
public override DocumentPage GetPage(int pageNumber) { // This is called starting at zero, but we are really starting at the given page. pageNumber += startingPage; if (showProgressDialog) { if (outer.controller.UpdateProgressDialog(string.Format(MiscText.PrintingPage, pageNumber + 1, outer.totalPages), (double)pageNumber / (double)outer.totalPages)) { throw new Exception(MiscText.CancelledByUser); } } Margins margins = new Margins(this.margins.Left, this.margins.Right, this.margins.Top, this.margins.Bottom); bool landscape = outer.pageSettings.Landscape; PaperSize paperSize = outer.pageSettings.PaperSize; bool rotate; outer.ChangePageSettings(pageNumber, ref landscape, ref paperSize, margins); rotate = (landscape != outer.pageSettings.Landscape); this.pageSize = new System.Windows.Size(HundrethsToPoints(paperSize.Width), HundrethsToPoints(paperSize.Height)); if (outer.pageSettings.Landscape) { this.pageSize = new System.Windows.Size(this.pageSize.Height, this.pageSize.Width); } // Get margins in terms of normal page orientation, in points. double leftMargin = HundrethsToPoints(rotate ? margins.Bottom : margins.Left); double rightMargin = HundrethsToPoints(rotate ? margins.Top : margins.Right); double topMargin = HundrethsToPoints(rotate ? margins.Left : margins.Top); double bottomMargin = HundrethsToPoints(rotate ? margins.Right : margins.Bottom); System.Windows.Rect contentRect = new System.Windows.Rect(leftMargin, topMargin, pageSize.Width - leftMargin - rightMargin, pageSize.Height - topMargin - bottomMargin); System.Windows.Rect boundingRect = new System.Windows.Rect(0, 0, pageSize.Width - leftMargin - rightMargin, pageSize.Height - topMargin - bottomMargin); System.Windows.Media.DrawingVisual visual = new System.Windows.Media.DrawingVisual(); using (System.Windows.Media.DrawingContext dc = visual.RenderOpen()) { if (outer.printingToBitmaps) { // This is kind of hacky way to get the printing to bitmaps white, but much easier than the alternative. dc.DrawRectangle(System.Windows.Media.Brushes.White, null, new System.Windows.Rect(-1, -1, pageSize.Width + 2, pageSize.Height + 2)); } // Clip to the bounding rect within margins. dc.PushClip(new System.Windows.Media.RectangleGeometry(boundingRect)); if (rotate) { // Rotate and translate to handle landscape mode. dc.PushTransform(new System.Windows.Media.TranslateTransform(0, boundingRect.Height)); dc.PushTransform(new System.Windows.Media.RotateTransform(-90)); } // Scale to hundreths of an inch instead of points (1/96 of inch). dc.PushTransform(new System.Windows.Media.ScaleTransform(96.0 / 100.0, 96.0 / 100.0)); IGraphicsTarget graphicsTarget; if (outer.colorModel == ColorModel.RGB) { graphicsTarget = new WPF_GraphicsTarget(dc); } else if (outer.colorModel == ColorModel.CMYK) { graphicsTarget = new WPF_GraphicsTarget(dc, new WPFSwopColorConverter()); } else { throw new NotImplementedException(); } using (graphicsTarget) { outer.DrawPage(graphicsTarget, pageNumber, new SizeF((float)contentRect.Width, (float)contentRect.Height), dpi); } graphicsTarget = null; } return(new DocumentPage(visual, pageSize, contentRect, contentRect)); }