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/>.
12 using System.Collections.Generic;
13 using Windows.Graphics.Display;
14 using Windows.UI.Xaml.Media;
15 using Windows.UI.Xaml.Media.Imaging;
18 using DXGI = SharpDX.DXGI;
19 using D2D = SharpDX.Direct2D1;
20 using D3D = SharpDX.Direct3D;
21 using D3D11 = SharpDX.Direct3D11;
22 using FooEditEngine.Metro;
23 using DotNetTextStore;
24 using DotNetTextStore.UnmanagedAPI.TSF;
25 using DotNetTextStore.UnmanagedAPI.WinDef;
27 namespace FooEditEngine
29 sealed class D2DPrintRender : D2DRenderBase, ITextRender, IPrintableTextRender
32 D2D.DeviceContext D2DContext;
33 D2D.PrintControl Control;
34 D2D.CommandList CommandList;
36 ImagingFactory WICFactory = new ImagingFactory();
39 public D2DPrintRender(string fontName,double fontSize, Size size, uint dpi, IPrintDocumentPackageTarget docPackageTarget)
42 base.ConstructDeviceResource(size.Width, size.Height);
43 base.InitTextFormat(fontName, (float)fontSize);
45 this.CreateSurface(size,dpi,docPackageTarget);
48 public override void GetDpi(out float dpix, out float dpiy)
54 public void DrawContent(PrintableView view)
56 this.CommandList = new D2D.CommandList(this.D2DContext);
57 this.D2DContext.Target = this.CommandList;
59 view.Draw(view.PageBound);
61 this.CommandList.Close();
62 this.Control.AddPage(this.CommandList, this.Size);
63 this.CommandList.Dispose();
66 void CreateSurface(Size size, uint dpi, IPrintDocumentPackageTarget docPackageTarget)
68 D2D.PrintControlProperties printControlProperties = new D2D.PrintControlProperties();
69 printControlProperties.RasterDPI = dpi;
70 printControlProperties.ColorSpace = D2D.ColorSpace.SRgb;
71 printControlProperties.FontSubset = D2D.PrintFontSubsetMode.Default;
73 this.Control = new D2D.PrintControl(this.D2DDevice, this.WICFactory, new ComObject(docPackageTarget), printControlProperties);
75 this.Size = new Size2F((float)size.Width, (float)size.Height);
80 protected override D2D.RenderTarget ConstructRender(D2D.Factory1 factory, D2D.RenderTargetProperties prop, double width, double height)
82 this.D2DDevice = new D2D.Device(factory,this.DXGIDevice);
83 this.D2DContext = new D2D.DeviceContext(this.D2DDevice, D2D.DeviceContextOptions.None);
84 return this.D2DContext;
87 protected override void ConstrctedResource()
91 protected override void DestructRender()
93 if (this.Control != null)
96 this.Control.Dispose();
98 if (this.WICFactory != null)
99 this.WICFactory.Dispose();
100 if (this.D2DDevice != null)
101 this.D2DDevice.Dispose();
102 if (this.D2DContext != null)
103 this.D2DContext.Dispose();
106 protected override void ReCreateTarget()
110 public float HeaderHeight
112 get { return (float)this.emSize.Height; }
115 public float FooterHeight
117 get { return (float)this.emSize.Height; }