public WPFRender(FooTextBox textbox, double width, double height, FrameworkElement image) { this.ChangedRenderResource += (s, e) => { }; this.ChangedRightToLeft += (s, e) => { }; this.FontFamily = textbox.FontFamily; this.FontSize = textbox.FontSize; this.ForegroundColor = textbox.Foreground; this.BackgroundColor = textbox.Background; this.ControlCharColor = textbox.ControlChar; this.HilightColor = textbox.Hilight; this.CommentColor = textbox.Comment; this.UrlColor = textbox.URL; this.Keyword1Color = textbox.Keyword1; this.Keyword2Color = textbox.Keyword2; this.LiteralColor = textbox.Literal; this.InsertCaretColor = textbox.InsertCaret; this.OverwriteCaretColor = textbox.OverwriteCaret; this.LineMarkerColor = textbox.LineMarker; this.host = (VisualHost)image; }
/// <summary> /// 印刷する /// </summary> /// <param name="pd">プリントダイアログ</param> public void Print(PrintDialog pd) { if (this.Font == null || this.Document == null) { throw new InvalidOperationException(); } WPFRender render = new WPFRender(this.Font, this.FontSize); render.Foreground = this.Foreground; render.Comment = this.Comment; render.Keyword1 = this.Keyword1; render.Keyword2 = this.Keyword2; render.Literal = this.Litral; render.Url = this.URL; render.RightToLeft = this.FlowDirection == System.Windows.FlowDirection.RightToLeft; render.Printing = true; Document documentSnap = new Document(this.Document); documentSnap.LayoutLines.Render = render; PrintableView view = new PrintableView(documentSnap, render, this.Padding); view.Header = this.Header; view.Footer = this.Footer; view.PageBound = this.PageRect; view.Hilighter = this.Hilighter; documentSnap.LineBreak = this.LineBreakMethod; documentSnap.LineBreakCharCount = this.LineBreakCharCount; documentSnap.DrawLineNumber = this.DrawLineNumber; documentSnap.UrlMark = this.MarkURL; documentSnap.PerformLayout(false); try { FixedDocument fd = new FixedDocument(); fd.DocumentPaginator.PageSize = this.PageRect.Size; int currentPage = 0; bool result = false; while (!result) { if (this.EndPage != -1 && currentPage > this.EndPage) { break; } if (this.StartPage == -1 || currentPage >= this.StartPage) { PageContent pc = new PageContent(); FixedPage fp = new FixedPage(); fp.Width = this.PageRect.Width; fp.Height = this.PageRect.Height; pc.Child = fp; view.Header = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.EndPage, this.Header)); view.Footer = this.ParseHF(this, new ParseCommandEventArgs(currentPage, this.EndPage, this.Footer)); DrawingVisual dv = new DrawingVisual(); using (DrawingContext dc = dv.RenderOpen()) { render.SetDrawingContext(dc); view.Draw(view.PageBound); } VisualHost host = new VisualHost(); host.AddVisual(dv); fp.Children.Add(host); fd.Pages.Add(pc); } result = view.TryPageDown(); currentPage++; } pd.PrintDocument(fd.DocumentPaginator, ""); } catch (PrintingCanceledException) { } finally { view.Dispose(); } }