-/*\r
- * Copyright (C) 2013 FooProject\r
- * * 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
- * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of \r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
-\r
-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
- */\r
-using System;\r
-using System.Drawing;\r
-using System.Drawing.Printing;\r
-\r
-namespace FooEditEngine.Windows\r
-{\r
- /// <summary>\r
- /// イベントデータ\r
- /// </summary>\r
- public class ParseCommandEventArgs\r
- {\r
- /// <summary>\r
- /// ページ番号\r
- /// </summary>\r
- public int PageNumber;\r
- /// <summary>\r
- /// プリンターの設定\r
- /// </summary>\r
- public PrinterSettings PrinterSetting;\r
- /// <summary>\r
- /// 処理前の文字列\r
- /// </summary>\r
- public string Original;\r
- /// <summary>\r
- /// コンストラクター\r
- /// </summary>\r
- /// <param name="nowPage">印刷中のページ番号</param>\r
- /// <param name="setting">プリンターの設定</param>\r
- /// <param name="org">処理前の文字列</param>\r
- public ParseCommandEventArgs(int nowPage,PrinterSettings setting,string org)\r
- {\r
- this.PageNumber = nowPage;\r
- this.PrinterSetting = setting;\r
- this.Original = org;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// コマンド処理用デリゲート\r
- /// </summary>\r
- /// <param name="sender">送信元のクラス</param>\r
- /// <param name="e">イベントデータ</param>\r
- /// <returns>処理後の文字列</returns>\r
- public delegate string ParseCommandHandler(object sender,ParseCommandEventArgs e);\r
-\r
- /// <summary>\r
- /// 印刷用のクラス\r
- /// </summary>\r
- public class FooPrintText\r
- {\r
- PrintableView view;\r
- PrintableTextRender render;\r
- int PageNumber;\r
-\r
- /// <summary>\r
- /// コンストラクター\r
- /// </summary>\r
- public FooPrintText()\r
- {\r
- this.PrintDocument = new PrintDocument();\r
- this.PrintDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);\r
- this.PrintDocument.EndPrint += new PrintEventHandler(PrintDocument_EndPrint);\r
- this.ParseHF = new ParseCommandHandler((s, e) => { return e.Original; });\r
- }\r
-\r
- /// <summary>\r
- /// 対象となるドキュメント\r
- /// </summary>\r
- public Document Document\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// プリントドキュメント\r
- /// </summary>\r
- public PrintDocument PrintDocument\r
- {\r
- get;\r
- private set;\r
- }\r
-\r
- /// <summary>\r
- /// 右から左に表示するなら真\r
- /// </summary>\r
- public bool RightToLeft\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 行番号を表示するかどうか\r
- /// </summary>\r
- public bool DrawLineNumber\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 印刷に使用するフォント\r
- /// </summary>\r
- public Font Font\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 折り返しの方法を指定する\r
- /// </summary>\r
- public LineBreakMethod LineBreakMethod\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 折り返した時の文字数を指定する\r
- /// </summary>\r
- public int LineBreakCharCount\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// ヘッダー\r
- /// </summary>\r
- public string Header\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// フッター\r
- /// </summary>\r
- public string Footer\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// 前景色\r
- /// </summary>\r
- public System.Drawing.Color Foreground\r
- {\r
- get;\r
- set;\r
- }\r
-\r
- /// <summary>\r
- /// ヘッダーやフッターを処理する\r
- /// </summary>\r
- public ParseCommandHandler ParseHF;\r
-\r
- void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)\r
- {\r
- if (this.Font == null || this.Document == null)\r
- throw new InvalidOperationException();\r
-\r
- if (view == null)\r
- {\r
- this.render = new PrintableTextRender(this.Font, e.Graphics);\r
- this.render.Foreground = this.Foreground;\r
- this.render.RightToLeft = this.RightToLeft;\r
- this.view = new PrintableView(this.Document, this.render);\r
- this.view.DrawLineNumber = this.DrawLineNumber;\r
- this.view.TabStops = 4;\r
- this.view.PageBound = e.MarginBounds;\r
- this.view.LineBreak = this.LineBreakMethod;\r
- this.view.LineBreakCharCount = this.LineBreakCharCount;\r
- this.PageNumber = 1;\r
- }\r
-\r
- if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)\r
- {\r
- for (; this.PageNumber < e.PageSettings.PrinterSettings.FromPage; this.PageNumber++)\r
- {\r
- if (this.view.TryPageDown())\r
- return;\r
- }\r
- }\r
-\r
- this.view.Header = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings,this.Header));\r
- this.view.Footer = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings, this.Footer));\r
-\r
- this.render.BeginDraw(e.Graphics);\r
-\r
- this.view.Draw(e.MarginBounds);\r
-\r
- e.HasMorePages = !this.view.TryPageDown();\r
-\r
- this.render.EndDraw();\r
-\r
- this.PageNumber++;\r
-\r
- if (e.HasMorePages && e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages && this.PageNumber > e.PageSettings.PrinterSettings.ToPage)\r
- e.HasMorePages = false;\r
- }\r
-\r
- void PrintDocument_EndPrint(object sender, PrintEventArgs e)\r
- {\r
- this.view.Dispose();\r
- this.view = null;\r
- this.render = null;\r
- }\r
-\r
- }\r
-}\r
+/*
+ * Copyright (C) 2013 FooProject
+ * * 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
+ * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+using System;
+using System.Drawing;
+using System.Drawing.Printing;
+
+namespace FooEditEngine.Windows
+{
+ /// <summary>
+ /// イベントデータ
+ /// </summary>
+ public class ParseCommandEventArgs
+ {
+ /// <summary>
+ /// ページ番号
+ /// </summary>
+ public int PageNumber;
+ /// <summary>
+ /// プリンターの設定
+ /// </summary>
+ public PrinterSettings PrinterSetting;
+ /// <summary>
+ /// 処理前の文字列
+ /// </summary>
+ public string Original;
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ /// <param name="nowPage">印刷中のページ番号</param>
+ /// <param name="setting">プリンターの設定</param>
+ /// <param name="org">処理前の文字列</param>
+ public ParseCommandEventArgs(int nowPage,PrinterSettings setting,string org)
+ {
+ this.PageNumber = nowPage;
+ this.PrinterSetting = setting;
+ this.Original = org;
+ }
+ }
+
+ /// <summary>
+ /// コマンド処理用デリゲート
+ /// </summary>
+ /// <param name="sender">送信元のクラス</param>
+ /// <param name="e">イベントデータ</param>
+ /// <returns>処理後の文字列</returns>
+ public delegate string ParseCommandHandler(object sender,ParseCommandEventArgs e);
+
+ /// <summary>
+ /// 印刷用のクラス
+ /// </summary>
+ public class FooPrintText
+ {
+ PrintableView view;
+ PrintableTextRender render;
+ int PageNumber;
+
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ public FooPrintText()
+ {
+ this.PrintDocument = new PrintDocument();
+ this.PrintDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
+ this.PrintDocument.EndPrint += new PrintEventHandler(PrintDocument_EndPrint);
+ this.ParseHF = new ParseCommandHandler((s, e) => { return e.Original; });
+ }
+
+ /// <summary>
+ /// 対象となるドキュメント
+ /// </summary>
+ public Document Document
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// プリントドキュメント
+ /// </summary>
+ public PrintDocument PrintDocument
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// 右から左に表示するなら真
+ /// </summary>
+ public bool RightToLeft
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 行番号を表示するかどうか
+ /// </summary>
+ public bool DrawLineNumber
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 印刷に使用するフォント
+ /// </summary>
+ public Font Font
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 折り返しの方法を指定する
+ /// </summary>
+ public LineBreakMethod LineBreakMethod
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 折り返した時の文字数を指定する
+ /// </summary>
+ public int LineBreakCharCount
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// ヘッダー
+ /// </summary>
+ public string Header
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// フッター
+ /// </summary>
+ public string Footer
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 余白
+ /// </summary>
+ public Padding Padding
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// 前景色
+ /// </summary>
+ public System.Drawing.Color Foreground
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// ヘッダーやフッターを処理する
+ /// </summary>
+ public ParseCommandHandler ParseHF;
+
+ void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
+ {
+ if (this.Font == null || this.Document == null)
+ throw new InvalidOperationException();
+
+ if (view == null)
+ {
+ this.render = new PrintableTextRender(this.Font, e.Graphics);
+ this.render.Foreground = this.Foreground;
+ this.render.RightToLeft = this.RightToLeft;
+ Document documentSnap = new Document(this.Document);
+ documentSnap.LayoutLines.Render = render;
+ this.view = new PrintableView(documentSnap, this.render,this.Padding);
+ this.view.PageBound = e.MarginBounds;
+ this.PageNumber = 1;
+ documentSnap.LineBreak = this.LineBreakMethod;
+ documentSnap.LineBreakCharCount = this.LineBreakCharCount;
+ documentSnap.DrawLineNumber = this.DrawLineNumber;
+ documentSnap.UrlMark = this.Document.UrlMark;
+ documentSnap.PerformLayout(false);
+ }
+
+ if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages)
+ {
+ for (; this.PageNumber < e.PageSettings.PrinterSettings.FromPage; this.PageNumber++)
+ {
+ if (this.view.TryPageDown())
+ return;
+ }
+ }
+
+ this.view.Header = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings,this.Header));
+ this.view.Footer = this.ParseHF(this, new ParseCommandEventArgs(this.PageNumber, e.PageSettings.PrinterSettings, this.Footer));
+
+ this.render.BeginDraw(e.Graphics);
+
+ this.view.Draw(e.MarginBounds);
+
+ e.HasMorePages = !this.view.TryPageDown();
+
+ this.render.EndDraw();
+
+ this.PageNumber++;
+
+ if (e.HasMorePages && e.PageSettings.PrinterSettings.PrintRange == PrintRange.SomePages && this.PageNumber > e.PageSettings.PrinterSettings.ToPage)
+ e.HasMorePages = false;
+ }
+
+ void PrintDocument_EndPrint(object sender, PrintEventArgs e)
+ {
+ this.view.Dispose();
+ this.view = null;
+ this.render = null;
+ }
+
+ }
+}