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.Text;
15 using Windows.UI.Xaml.Media;
16 using Windows.UI.Xaml.Media.Imaging;
18 using DXGI = SharpDX.DXGI;
19 using D2D = SharpDX.Direct2D1;
20 using DW = SharpDX.DirectWrite;
21 using D3D = SharpDX.Direct3D;
22 using D3D11 = SharpDX.Direct3D11;
23 using FooEditEngine.UWP;
25 namespace FooEditEngine
27 class D2DRenderBase: D2DRenderCommon,IDisposable
29 public new const int MiniumeWidth = 40; //これ以上ないと誤操作が起こる
31 protected DXGI.Device DXGIDevice;
32 protected D3D11.Device1 D3DDevice;
33 FontFamily fontFamily;
34 FontStyle fontStyle = FontStyle.Normal;
35 FontWeight fontWeigth;
38 public D2DRenderBase()
40 var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport | SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;
41 D3D.FeatureLevel[] featureLevels ={D3D.FeatureLevel.Level_11_1,
42 D3D.FeatureLevel.Level_11_0,
43 D3D.FeatureLevel.Level_10_1,
44 D3D.FeatureLevel.Level_10_0,
45 D3D.FeatureLevel.Level_9_3,
46 D3D.FeatureLevel.Level_9_2,
47 D3D.FeatureLevel.Level_9_1};
48 using (var device = new D3D11.Device(D3D.DriverType.Hardware, creationFlags, featureLevels))
50 this.D3DDevice = device.QueryInterface<D3D11.Device1>();
52 this.DXGIDevice = this.D3DDevice.QueryInterface<DXGI.Device>();
55 public void InitTextFormat(string fontName, double size)
57 base.InitTextFormat(fontName, (float)size);
61 public void InitTextFormat(FontFamily font, double size)
63 base.InitTextFormat(font.Source, (float)size);
64 this.fontFamily = font;
68 public override void Dispose()
70 if (this.DXGIDevice != null)
71 this.DXGIDevice.Dispose();
72 if (this.D3DDevice != null)
73 this.D3DDevice.Dispose();
77 public FontFamily FontFamily
79 get { return this.fontFamily; }
82 this.fontFamily = value;
83 this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(this.fontWeigth), this.GetDWFontStyle(this.fontStyle));
84 this.TabWidthChar = this.TabWidthChar;
88 public double FontSize
90 get { return this.fontSize; }
93 this.fontSize = value;
94 this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(this.fontWeigth), this.GetDWFontStyle(this.fontStyle));
95 this.TabWidthChar = this.TabWidthChar;
99 public FontWeight FontWeigth
103 return this.fontWeigth;
107 this.fontWeigth = value;
108 this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(value), this.GetDWFontStyle(this.fontStyle));
112 public FontStyle FontStyle
116 return this.fontStyle;
120 this.fontStyle = value;
121 this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(this.fontWeigth), this.GetDWFontStyle(this.fontStyle));
125 DW.FontStyle GetDWFontStyle(FontStyle style)
127 return (DW.FontStyle)Enum.Parse(typeof(DW.FontStyle), style.ToString());
130 DW.FontWeight GetDWFontWeigth(FontWeight weigth)
132 if (weigth.Weight == 0)
133 return (DW.FontWeight)400;
135 return (DW.FontWeight)weigth.Weight;
138 public static Color4 ToColor4(Windows.UI.Color color)
140 return new Color4(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
143 public override void CacheContent()
147 public override void DrawCachedBitmap(Rectangle rect)
151 public override bool IsVaildCache()
156 public void DrawOneLine(Document doc,LineToIndexTable lti, int row, double x, double y)
158 this.DrawOneLine(doc,