<Compile Include="Print\D2DPrintRender.cs" />
<Compile Include="Print\DocumentSource.cs" />
<Compile Include="Print\D2DPrintPreviewRender.cs" />
+ <Compile Include="Print\PrintOptionBuilder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
using Windows.UI.Core;\r
using Windows.Foundation;\r
using Windows.Graphics.Printing;\r
+using Windows.Graphics.Printing.OptionDetails;\r
\r
namespace FooEditEngine.Metro\r
{\r
source.Header = Header;\r
source.Fotter = Fotter;\r
\r
- PrintTask task = req.CreatePrintTask(title, (e) =>\r
+ PrintTask task = null;\r
+ task = req.CreatePrintTask(title, (e) =>\r
{\r
e.SetSource(source);\r
});\r
this.PrintComplete(this, null);\r
});\r
};\r
+ PrintOptionBuilder<DocumentSource> builder = new PrintOptionBuilder<DocumentSource>(source);\r
+ builder.BuildPrintOption(PrintTaskOptionDetails.GetFromPrintTaskOptions(task.Options));\r
});\r
Task t = WindowsRuntimeSystemExtensions.AsTask(async);\r
t.Wait();\r
/// <returns>処理後の文字列</returns>\r
public delegate string ParseCommandHandler(object sender, ParseCommandEventArgs e);\r
\r
+\r
sealed class PrintableViewFactory\r
{\r
Windows.UI.Color foreground, comment, keyword1, keyword2, literal, url;\r
Document document;\r
LineBreakMethod lineBreakMethod;\r
int lineBreakCharCount, tabCount;\r
- bool drawLineNumber, urlMark;\r
+ bool urlMark;\r
IHilighter hilighter;\r
float displayDpi;\r
Padding padding;\r
this.hilighter = textbox.Hilighter;\r
this.displayDpi = DisplayInformation.GetForCurrentView().LogicalDpi;\r
this.padding = padding;\r
+ this.EnableHilight = true;\r
}\r
public D2DRenderBase CreateRender(PrintPageDescription pagedesc, IPrintDocumentPackageTarget docPackageTarget)\r
{\r
view.Footer = footer;\r
view.UrlMark = this.urlMark;\r
view.PageBound = new Rectangle(pagedesc.ImageableRect.X, pagedesc.ImageableRect.Y, pagedesc.ImageableRect.Width, pagedesc.ImageableRect.Height);\r
- view.Hilighter = this.hilighter;\r
+ view.Hilighter = this.EnableHilight ? this.hilighter : null;\r
view.PerfomLayouts();\r
\r
return view;\r
}\r
+\r
+ public bool drawLineNumber\r
+ {\r
+ get;\r
+ set;\r
+ }\r
+\r
+ public bool EnableHilight\r
+ {\r
+ get;\r
+ set;\r
+ }\r
}\r
\r
- sealed class DocumentSource : IPrintDocumentPageSource, IPrintPreviewPageCollection, IPrintDocumentSource\r
+ sealed class DocumentSource : IPrintDocumentPageSource, IPrintPreviewPageCollection, IPrintDocumentSource,IPrintPreviewSource\r
{\r
IPrintPreviewDxgiPackageTarget dxgiPreviewTarget;\r
bool paginateCalled = false;\r
this.factory = new PrintableViewFactory(textbox, padding);\r
}\r
\r
- public void GetPreviewPageCollection(IPrintDocumentPackageTarget docPackageTarget,out IPrintPreviewPageCollection docPageCollection)\r
+ internal enum SyntaxHilightApplibility\r
+ {\r
+ Apply,\r
+ NoApply,\r
+ }\r
+\r
+ [DisplayPrintOptionResourceID("SyntaxHilight")]\r
+ internal SyntaxHilightApplibility EnableHilight\r
+ {\r
+ get\r
+ {\r
+ return this.factory.EnableHilight ? SyntaxHilightApplibility.Apply : SyntaxHilightApplibility.NoApply;\r
+ }\r
+ set\r
+ {\r
+ this.factory.EnableHilight = value == SyntaxHilightApplibility.Apply;\r
+ }\r
+ }\r
+\r
+ internal enum LineNumberVisiblity\r
+ {\r
+ Visible,\r
+ Hidden\r
+ }\r
+\r
+ [DisplayPrintOptionResourceID("ShowLineNumber")]\r
+ internal LineNumberVisiblity ShowLineNumber\r
+ {\r
+ get\r
+ {\r
+ return this.factory.drawLineNumber ? LineNumberVisiblity.Visible : LineNumberVisiblity.Hidden;\r
+ }\r
+ set\r
+ {\r
+ this.factory.drawLineNumber = value == LineNumberVisiblity.Visible;\r
+ }\r
+ }\r
+\r
+ public void GetPreviewPageCollection(IPrintDocumentPackageTarget docPackageTarget, out IPrintPreviewPageCollection docPageCollection)\r
{\r
Guid guid = new Guid(PreviewPackageIds.IID_PREVIEWPACKAGETARGET_DXGI);\r
IntPtr target;\r
this.paginateCalled = true;\r
}\r
\r
+ public void InvalidatePreview()\r
+ {\r
+ this.dxgiPreviewTarget.InvalidatePreview();\r
+ }\r
+\r
public void MakePage(uint desiredJobPage, float width, float height)\r
{\r
if (width <= 0 || height <= 0)\r
--- /dev/null
+/*
+ * 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 Windows.Graphics.Printing.OptionDetails;
+using System.Reflection;
+using Windows.ApplicationModel.Resources.Core;
+
+namespace FooEditEngine
+{
+ /// <summary>
+ /// 表示に使用するリソースID
+ /// </summary>
+ class DisplayPrintOptionResourceIDAttribute : Attribute
+ {
+ public string ResourceID
+ {
+ get;
+ private set;
+ }
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ /// <param name="resourceID">リソースID</param>
+ public DisplayPrintOptionResourceIDAttribute(string resourceID)
+ {
+ this.ResourceID = resourceID;
+ }
+ }
+ /// <summary>
+ /// IPrintPreviewSourceインターフェイス
+ /// </summary>
+ interface IPrintPreviewSource
+ {
+ /// <summary>
+ /// 再描写する
+ /// </summary>
+ void InvalidatePreview();
+ }
+ /// <summary>
+ /// 印刷プレビューのカスタムオプションリストビルダー
+ /// <para>
+ /// 印刷プレビューに表示させたいプロパティには「DisplayPrintOptionResourceID」属性を付ける必要があります。
+ /// また、このプロパティはenumを継承した型でなければならず、リソースに「型名.値」という形で印刷プレビューに表示される名前を定義する必要があります。
+ /// 定義しない場合、値がそのまま表示されます
+ /// </para>
+ /// </summary>
+ /// <typeparam name="T">IPrintPreviewSourceを継承したクラス</typeparam>
+ class PrintOptionBuilder<T> where T : IPrintPreviewSource
+ {
+ T PrintDocument;
+ /// <summary>
+ /// コンストラクター
+ /// </summary>
+ /// <param name="source">対象となるオブジェクト</param>
+ public PrintOptionBuilder(T source)
+ {
+ this.PrintDocument = source;
+ }
+
+ /// <summary>
+ /// 印刷プレビューのオプションを作成する
+ /// </summary>
+ /// <param name="details">PrintTaskOptionDetailsオブジェクト</param>
+ public void BuildPrintOption(PrintTaskOptionDetails details)
+ {
+ ResourceMap map = ResourceManager.Current.MainResourceMap.GetSubtree("FooEditEngine.Metro/Resources");
+ ResourceContext context = ResourceContext.GetForCurrentView();
+
+ var properties = this.PrintDocument.GetType().GetRuntimeProperties();
+ foreach(PropertyInfo property in properties)
+ {
+ DisplayPrintOptionResourceIDAttribute attr = property.GetCustomAttribute<DisplayPrintOptionResourceIDAttribute>();
+ if (attr == null)
+ continue;
+ string resourceName;
+ if(property.PropertyType.GetTypeInfo().IsEnum)
+ {
+ PrintCustomItemListOptionDetails iteminfo = details.CreateItemListOption(property.Name, map.GetValue(attr.ResourceID, context).ValueAsString);
+ foreach (var enumvalue in Enum.GetValues(property.PropertyType))
+ {
+ string enumvalueStr = enumvalue.ToString();
+ //リソース内部の"."は"/"に変換される
+ resourceName = property.PropertyType.Name + "/" + enumvalueStr;
+ ResourceCandidate resValue = map.GetValue(resourceName, context);
+#if DEBUG
+ if(resValue == null)
+ System.Diagnostics.Debug.WriteLine("{0} is not defined by resource",resourceName.Replace('/','.'));
+#endif
+ iteminfo.AddItem(enumvalueStr, resValue != null ? resValue.ValueAsString : enumvalueStr);
+ }
+ iteminfo.TrySetValue(property.GetValue(this.PrintDocument).ToString());
+ details.DisplayedOptions.Add(property.Name);
+ }
+ }
+
+ details.OptionChanged += details_OptionChanged;
+ }
+
+ void details_OptionChanged(PrintTaskOptionDetails sender, PrintTaskOptionChangedEventArgs args)
+ {
+ string optionID = args.OptionId as string;
+ if (optionID == null)
+ return;
+ string optionValue = sender.Options[optionID].Value as string;
+ var property = this.GetRuntimeProperty(this.PrintDocument.GetType(),optionID);
+ if (property == null)
+ return;
+ if (property.PropertyType.GetTypeInfo().IsEnum)
+ {
+ Enum output = (Enum)Enum.Parse(property.PropertyType, optionValue);
+ property.SetMethod.Invoke(this.PrintDocument, new object[] { output });
+ }
+
+ this.PrintDocument.InvalidatePreview();
+ }
+
+ PropertyInfo GetRuntimeProperty(Type t,string name)
+ {
+ foreach(PropertyInfo property in t.GetRuntimeProperties())
+ {
+ if (property.Name == name)
+ return property;
+ }
+ return null;
+ }
+ }
+}
<data name="CutMenuName" xml:space="preserve">
<value>Cut</value>
</data>
+ <data name="LineNumberVisiblity.Hidden" xml:space="preserve">
+ <value>Hidden</value>
+ </data>
+ <data name="LineNumberVisiblity.Visible" xml:space="preserve">
+ <value>Visible</value>
+ </data>
<data name="LineSelectMenuName" xml:space="preserve">
<value>LineSelect</value>
</data>
<data name="RectSelectMenuName" xml:space="preserve">
<value>RectangleSelect</value>
</data>
+ <data name="ShowLineNumber" xml:space="preserve">
+ <value>LineNumber</value>
+ </data>
+ <data name="SyntaxHilight" xml:space="preserve">
+ <value>SyntaxHilight</value>
+ </data>
+ <data name="SyntaxHilightApplibility.Apply" xml:space="preserve">
+ <value>Apply</value>
+ </data>
+ <data name="SyntaxHilightApplibility.NoApply" xml:space="preserve">
+ <value>Not Apply</value>
+ </data>
</root>
\ No newline at end of file
<data name="CutMenuName" xml:space="preserve">
<value>切り取り</value>
</data>
+ <data name="LineNumberVisiblity.Hidden" xml:space="preserve">
+ <value>表示しない</value>
+ </data>
+ <data name="LineNumberVisiblity.Visible" xml:space="preserve">
+ <value>表示する</value>
+ </data>
<data name="LineSelectMenuName" xml:space="preserve">
<value>行選択</value>
</data>
<data name="RectSelectMenuName" xml:space="preserve">
<value>矩形選択</value>
</data>
+ <data name="ShowLineNumber" xml:space="preserve">
+ <value>行番号</value>
+ </data>
+ <data name="SyntaxHilight" xml:space="preserve">
+ <value>シンタックスハイライト</value>
+ </data>
+ <data name="SyntaxHilightApplibility.Apply" xml:space="preserve">
+ <value>反映させる</value>
+ </data>
+ <data name="SyntaxHilightApplibility.NoApply" xml:space="preserve">
+ <value>反映させない</value>
+ </data>
</root>
\ No newline at end of file