OSDN Git Service

フォルダー名を変更した
[fooeditengine/FooEditEngine.git] / Metro / FooEditEngine / Print / D2DPrintRender.cs
1 /*
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.
5
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.
8
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/>.
10  */
11 using System;
12 using System.Collections.Generic;
13 using Windows.Graphics.Display;
14 using Windows.UI.Xaml.Media;
15 using Windows.UI.Xaml.Media.Imaging;
16 using SharpDX;
17 using SharpDX.WIC;
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;
26
27 namespace FooEditEngine
28 {
29     class D2DPrintRender : D2DRenderBase,ITextRender,IPrintableTextRender
30     {
31         D2D.Device D2DDevice;
32         D2D.DeviceContext D2DContext;
33         D2D.PrintControl Control;
34         D2D.CommandList CommandList;
35         Size2F Size;
36         ImagingFactory WICFactory = new ImagingFactory();
37         int dpi;
38
39         public D2DPrintRender(string fontName,double fontSize, Size size, uint dpi, IPrintDocumentPackageTarget docPackageTarget)
40             : base()
41         {
42             base.ConstructRender = this.ConstructRenderHandler;
43             base.ConstrctedResource = this.ConstructedResourceHandler;
44             base.DestructRender = this.DestructRenderHandler;
45             base.ReCreateTarget = this.ReCreateTargetHandler;
46             base.GetDpi = this.GetDpi;
47             base.ConstructDeviceResource(size.Width, size.Height);
48             base.InitTextFormat(fontName, (float)fontSize);
49
50             this.CreateSurface(size,dpi,docPackageTarget);
51         }
52
53         new void GetDpi(out float dpix, out float dpiy)
54         {
55             dpix = this.dpi;
56             dpiy = this.dpi;
57         }
58
59         public override void BeginDraw()
60         {
61             this.CommandList = new D2D.CommandList(this.D2DContext);
62             this.D2DContext.Target = this.CommandList;
63             base.BeginDraw();
64         }
65
66         public override void EndDraw()
67         {
68             base.EndDraw();
69             this.CommandList.Close();
70             this.Control.AddPage(this.CommandList, this.Size);
71             this.CommandList.Dispose();
72         }
73
74         void CreateSurface(Size size, uint dpi, IPrintDocumentPackageTarget docPackageTarget)
75         {
76             D2D.PrintControlProperties printControlProperties = new D2D.PrintControlProperties();
77             printControlProperties.RasterDPI = dpi;
78             printControlProperties.ColorSpace = D2D.ColorSpace.SRgb;
79             printControlProperties.FontSubset = D2D.PrintFontSubsetMode.Default;
80
81             this.Control = new D2D.PrintControl(this.D2DDevice, this.WICFactory, new ComObject(docPackageTarget), printControlProperties);
82
83             this.Size = new Size2F((float)size.Width, (float)size.Height);
84
85             this.dpi = (int)dpi;
86         }
87
88         D2D.RenderTarget ConstructRenderHandler(D2D.Factory1 factory, D2D.RenderTargetProperties prop, double width, double height)
89         {
90             this.D2DDevice = new D2D.Device(factory,this.DXGIDevice);
91             this.D2DContext = new D2D.DeviceContext(this.D2DDevice, D2D.DeviceContextOptions.None);
92             return this.D2DContext;
93         }
94
95         void ConstructedResourceHandler()
96         {
97         }
98
99         void DestructRenderHandler()
100         {
101             if (this.Control != null)
102             {
103                 this.Control.Close();
104                 this.Control.Dispose();
105             }
106             if (this.WICFactory != null)
107                 this.WICFactory.Dispose();
108             if (this.D2DDevice != null)
109                 this.D2DDevice.Dispose();
110             if (this.D2DContext != null)
111                 this.D2DContext.Dispose();
112         }
113
114         void ReCreateTargetHandler()
115         {
116         }
117
118         public float HeaderHeight
119         {
120             get { return (float)this.emSize.Height; }
121         }
122
123         public float FooterHeight
124         {
125             get { return (float)this.emSize.Height; }
126         }
127     }
128 }