2 * Copyright (C) 2013 FooProject
3 * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
13 using System.Drawing.Printing;
15 namespace FooEditEngine.Windows
20 public class ParseCommandEventArgs
25 public int PageNumber;
29 public PrinterSettings PrinterSetting;
33 public string Original;
37 /// <param name="nowPage">印刷中のページ番号</param>
38 /// <param name="setting">プリンターの設定</param>
39 /// <param name="org">処理前の文字列</param>
40 public ParseCommandEventArgs(int nowPage,PrinterSettings setting,string org)
42 this.PageNumber = nowPage;
43 this.PrinterSetting = setting;
51 /// <param name="sender">送信元のクラス</param>
52 /// <param name="e">イベントデータ</param>
53 /// <returns>処理後の文字列</returns>
54 public delegate string ParseCommandHandler(object sender,ParseCommandEventArgs e);
59 public class FooPrintText
62 PrintableTextRender render;
70 this.PrintDocument = new PrintDocument();
71 this.PrintDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
72 this.PrintDocument.EndPrint += new PrintEventHandler(PrintDocument_EndPrint);
73 this.ParseHF = new ParseCommandHandler((s, e) => { return e.Original; });
79 public Document Document
88 public PrintDocument PrintDocument
97 public bool RightToLeft
106 public bool DrawLineNumber
124 public LineBreakMethod LineBreakMethod
133 public int LineBreakCharCount
160 public Padding Padding
169 public System.Drawing.Color Foreground
178 public ParseCommandHandler ParseHF;
180 void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
182 if (this.Font == null || this.Document == null)
183 throw new InvalidOperationException();
187 this.render = new PrintableTextRender(this.Font, e.Graphics);
188 this.render.Foreground = this.Foreground;
189 this.render.RightToLeft = this.RightToLeft;
190 Document documentSnap = new Document(this.Document);
191 documentSnap.LayoutLines.Render = render;
192 this.view = new PrintableView(documentSnap, this.render,this.Padding);
193 this.view.PageBound = e.MarginBounds;
195 documentSnap.LineBreak = this.LineBreakMethod;
196 documentSnap.LineBreakCharCount = this.LineBreakCharCount;
197 documentSnap.DrawLineNumber = this.DrawLineNumber;
198 documentSnap.UrlMark = this.Document.UrlMark;
199 this.view.PerfomLayouts();
202 if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)
204 for (; this.PageNumber < e.PageSettings.PrinterSettings.FromPage; this.PageNumber++)
206 if (this.view.TryPageDown())
211 this.view.Header = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings,this.Header));
212 this.view.Footer = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings, this.Footer));
214 this.render.BeginDraw(e.Graphics);
216 this.view.Draw(e.MarginBounds);
218 e.HasMorePages = !this.view.TryPageDown();
220 this.render.EndDraw();
224 if (e.HasMorePages && e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages && this.PageNumber > e.PageSettings.PrinterSettings.ToPage)
225 e.HasMorePages = false;
228 void PrintDocument_EndPrint(object sender, PrintEventArgs e)