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 System.Drawing.Color Foreground
\r
169 public ParseCommandHandler ParseHF;
\r
171 void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
\r
173 if (this.Font == null || this.Document == null)
\r
174 throw new InvalidOperationException();
\r
178 this.render = new PrintableTextRender(this.Font, e.Graphics);
\r
179 this.render.Foreground = this.Foreground;
\r
180 this.render.RightToLeft = this.RightToLeft;
\r
181 this.view = new PrintableView(this.Document, this.render);
\r
182 this.view.DrawLineNumber = this.DrawLineNumber;
\r
183 this.view.TabStops = 4;
\r
184 this.view.PageBound = e.MarginBounds;
\r
185 this.view.LineBreak = this.LineBreakMethod;
\r
186 this.view.LineBreakCharCount = this.LineBreakCharCount;
\r
187 this.PageNumber = 1;
\r
188 this.view.PerfomLayouts();
\r
191 if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)
\r
193 for (; this.PageNumber < e.PageSettings.PrinterSettings.FromPage; this.PageNumber++)
\r
195 if (this.view.TryPageDown())
\r
200 this.view.Header = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings,this.Header));
\r
201 this.view.Footer = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings, this.Footer));
\r
203 this.render.BeginDraw(e.Graphics);
\r
205 this.view.Draw(e.MarginBounds);
\r
207 e.HasMorePages = !this.view.TryPageDown();
\r
209 this.render.EndDraw();
\r
213 if (e.HasMorePages && e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages && this.PageNumber > e.PageSettings.PrinterSettings.ToPage)
\r
214 e.HasMorePages = false;
\r
217 void PrintDocument_EndPrint(object sender, PrintEventArgs e)
\r
219 this.view.Dispose();
\r
221 this.render = null;
\r