2 * Copyright (C) 2013 FooProject
\r
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
\r
4 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
\r
6 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
\r
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/>.
\r
12 using System.Drawing;
\r
13 using System.Drawing.Printing;
\r
15 namespace FooEditEngine.Windows
\r
20 public class ParseCommandEventArgs
\r
25 public int PageNumber;
\r
29 public PrinterSettings PrinterSetting;
\r
33 public string Original;
\r
37 /// <param name="nowPage">印刷中のページ番号</param>
\r
38 /// <param name="setting">プリンターの設定</param>
\r
39 /// <param name="org">処理前の文字列</param>
\r
40 public ParseCommandEventArgs(int nowPage,PrinterSettings setting,string org)
\r
42 this.PageNumber = nowPage;
\r
43 this.PrinterSetting = setting;
\r
44 this.Original = org;
\r
51 /// <param name="sender">送信元のクラス</param>
\r
52 /// <param name="e">イベントデータ</param>
\r
53 /// <returns>処理後の文字列</returns>
\r
54 public delegate string ParseCommandHandler(object sender,ParseCommandEventArgs e);
\r
59 public class FooPrintText
\r
62 PrintableTextRender render;
\r
68 public FooPrintText()
\r
70 this.PrintDocument = new PrintDocument();
\r
71 this.PrintDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
\r
72 this.PrintDocument.EndPrint += new PrintEventHandler(PrintDocument_EndPrint);
\r
73 this.ParseHF = new ParseCommandHandler((s, e) => { return e.Original; });
\r
79 public Document Document
\r
88 public PrintDocument PrintDocument
\r
97 public bool RightToLeft
\r
106 public bool DrawLineNumber
\r
124 public LineBreakMethod LineBreakMethod
\r
131 /// 折り返した時の文字数を指定する
\r
133 public int LineBreakCharCount
\r
142 public string Header
\r
151 public string Footer
\r
160 public Padding Padding
\r
169 public System.Drawing.Color Foreground
\r
178 public ParseCommandHandler ParseHF;
\r
180 void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
\r
182 if (this.Font == null || this.Document == null)
\r
183 throw new InvalidOperationException();
\r
187 this.render = new PrintableTextRender(this.Font, e.Graphics);
\r
188 this.render.Foreground = this.Foreground;
\r
189 this.render.RightToLeft = this.RightToLeft;
\r
190 this.view = new PrintableView(this.Document, this.render,this.Padding);
\r
191 this.view.DrawLineNumber = this.DrawLineNumber;
\r
192 this.view.TabStops = 4;
\r
193 this.view.PageBound = e.MarginBounds;
\r
194 this.view.LineBreak = this.LineBreakMethod;
\r
195 this.view.LineBreakCharCount = this.LineBreakCharCount;
\r
196 this.PageNumber = 1;
\r
197 this.view.PerfomLayouts();
\r
200 if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)
\r
202 for (; this.PageNumber < e.PageSettings.PrinterSettings.FromPage; this.PageNumber++)
\r
204 if (this.view.TryPageDown())
\r
209 this.view.Header = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings,this.Header));
\r
210 this.view.Footer = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings, this.Footer));
\r
212 this.render.BeginDraw(e.Graphics);
\r
214 this.view.Draw(e.MarginBounds);
\r
216 e.HasMorePages = !this.view.TryPageDown();
\r
218 this.render.EndDraw();
\r
222 if (e.HasMorePages && e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages && this.PageNumber > e.PageSettings.PrinterSettings.ToPage)
\r
223 e.HasMorePages = false;
\r
226 void PrintDocument_EndPrint(object sender, PrintEventArgs e)
\r
228 this.view.Dispose();
\r
230 this.render = null;
\r