OSDN Git Service

初期化の仕方はプラットフォームによって違うので共通化しないことにした
authorgdkhd812 <test@yahoo.co.jp>
Thu, 6 Apr 2017 14:54:04 +0000 (23:54 +0900)
committergdkhd812 <test@yahoo.co.jp>
Thu, 6 Apr 2017 14:54:04 +0000 (23:54 +0900)
Core/Direct2D/D2DRenderCommon.cs
UWP/FooEditEngine.UWP/Direct2D/D2DRender.cs
UWP/FooEditEngine.UWP/Direct2D/D2DRenderBase.cs
UWP/FooEditEngine.UWP/Print/D2DPrintPreviewRender.cs
UWP/FooEditEngine.UWP/Print/D2DPrintRender.cs
WPF/FooEditEngine/Direct2D/D2DRender.cs
Windows/FooEditEngine/D2DTextRender.cs

index f4f67c8..2aeb8e4 100644 (file)
@@ -144,37 +144,57 @@ namespace FooEditEngine
 
     class D2DRenderCommon : IDisposable
     {
-        ColorBrushCollection Brushes = new ColorBrushCollection();
-        StrokeCollection Strokes = new StrokeCollection();
         InlineManager HiddenChars;
         TextAntialiasMode _TextAntialiasMode;
         Color4 _ControlChar,_Forground,_URL,_Hilight;
         DW.Factory DWFactory;
-#if METRO || WINDOWS_UWP
-        D2D.Factory1 D2DFactory;
-#else
-        D2D.Factory D2DFactory;
-#endif
         DW.TextFormat format;
+        protected CustomTextRenderer textRender;
         protected D2D.Bitmap cachedBitMap;
-        CustomTextRenderer textRender;
         int tabLength = 8;
         bool _ShowLineBreak;
         Color4 _Comment, _Literal, _Keyword1, _Keyword2;
         protected bool hasCache = false;
+        protected Size renderSize;
+
+#if METRO || WINDOWS_UWP
+        protected D2D.Factory1 D2DFactory
+        {
+            get;
+            private set;
+        }
+#else
+        protected D2D.Factory D2DFactory
+        {
+            get;
+            private set;
+        }
+#endif
 
-        protected Size renderSize
+        protected ColorBrushCollection Brushes
         {
             get;
             private set;
         }
 
-        protected D2D.RenderTarget render
+        protected StrokeCollection Strokes
         {
             get;
             private set;
         }
 
+        D2D.RenderTarget _render;
+        protected D2D.RenderTarget render
+        {
+            get { return _render; }
+            set
+            {
+                _render = value;
+                this.TextAntialiasMode = this._TextAntialiasMode;
+                this.Brushes.Render = this.render;
+            }
+        }
+
         public D2DRenderCommon()
         {
             this.DWFactory = new DW.Factory(DW.FactoryType.Shared);
@@ -183,6 +203,8 @@ namespace FooEditEngine
 #else
             this.D2DFactory = new D2D.Factory(D2D.FactoryType.MultiThreaded);
 #endif
+            this.Brushes = new ColorBrushCollection();
+            this.Strokes = new StrokeCollection();
             this.Strokes.Factory = this.D2DFactory;
             this.ChangedRenderResource += (s, e) => { };
             this.ChangedRightToLeft += (s, e) => { };
@@ -536,16 +558,6 @@ namespace FooEditEngine
             this.render.DrawEllipse(ellipse, this.Brushes.Get(this.Foreground));
         }
 
-        public void ReConstructDeviceResource()
-        {
-            this.ReConstructDeviceResource(this.renderSize.Width, this.renderSize.Height);
-        }
-
-        public void ReConstructDeviceResource(double width, double height)
-        {
-            this.DestructDeviceResource();
-            this.ConstructDeviceResource(width, height);
-        }
 
         public virtual void DrawCachedBitmap(Rectangle rect)
         {
@@ -852,62 +864,25 @@ namespace FooEditEngine
             return output;
         }
 
-        public virtual void Dispose()
-        {
-            this.DestructDeviceResource();
-            this.HiddenChars.Clear();
-            if (this.format != null)
-                this.format.Dispose();
-            if(this.DWFactory != null)
-                this.DWFactory.Dispose();
-            if(this.D2DFactory != null)
-                this.D2DFactory.Dispose();
-        }
-
-        public void ConstructDeviceResource(double width, double height)
-        {
-            float dpiX, dpiY;
-            this.GetDpi(out dpiX, out dpiY);
-            D2D.RenderTargetProperties prop = new D2D.RenderTargetProperties(
-                D2D.RenderTargetType.Default,
-                new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
-                dpiX,
-                dpiY,
-                D2D.RenderTargetUsage.None,
-                D2D.FeatureLevel.Level_DEFAULT);
-
-            this.render = this.ConstructRender(this.D2DFactory,prop,width,height);
-
-            this.Brushes.Render = this.render;
-
-            D2D.BitmapProperties bmpProp = new D2D.BitmapProperties();
-            bmpProp.DpiX = dpiX;
-            bmpProp.DpiY = dpiY;
-            bmpProp.PixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);
-            this.cachedBitMap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
-            this.hasCache = false;
-
-            this.ConstrctedResource();
-
-            this.textRender = new CustomTextRenderer(this.render, this.Brushes,this.Strokes, this.Foreground);
-
-            this.renderSize = new Size(width,height);
-
-            this.TextAntialiasMode = this._TextAntialiasMode;
-        }
-
-#if METRO || WINDOWS_UWP
-        protected virtual D2D.RenderTarget ConstructRender(D2D.Factory1 factory, D2D.RenderTargetProperties prop, double width, double height)
-#else
-        protected virtual D2D.RenderTarget ConstructRender(D2D.Factory factory, D2D.RenderTargetProperties prop, double width, double height)
-#endif
+        bool _Disposed = false;
+        public void Dispose()
         {
-            throw new NotImplementedException();
+            if (!_Disposed)
+            {
+                this.Dispose(true);
+                this.HiddenChars.Clear();
+                if (this.format != null)
+                    this.format.Dispose();
+                if (this.DWFactory != null)
+                    this.DWFactory.Dispose();
+                if (this.D2DFactory != null)
+                    this.D2DFactory.Dispose();
+            }
+            this._Disposed = true;
         }
 
-        protected virtual void ConstrctedResource()
+        protected virtual void Dispose(bool dispose)
         {
-            throw new NotImplementedException();
         }
 
         public virtual void GetDpi(out float dpix,out float dpiy)
@@ -922,29 +897,6 @@ namespace FooEditEngine
             return dpi / 96.0;
         }
 
-        protected virtual void DestructRender()
-        {
-            throw new NotImplementedException();
-
-        }
-
-        protected virtual void ReCreateTarget()
-        {
-            throw new NotImplementedException();
-        }
-
-        public void DestructDeviceResource()
-        {
-            this.hasCache = false;
-            if (this.cachedBitMap != null)
-                this.cachedBitMap.Dispose();
-            this.Brushes.Clear();
-            this.Strokes.Clear();
-            if (this.textRender != null)
-                this.textRender.Dispose();
-            this.DestructRender();
-        }
-
         void ParseLayout(MyTextLayout layout, string str)
         {
             for (int i = 0; i < str.Length; i++)
index 0e98eee..18294e8 100644 (file)
@@ -28,8 +28,6 @@ namespace FooEditEngine
     {
         SurfaceImageSource SurfaceImage;
         DXGI.ISurfaceImageSourceNative SurfaceImageNative;
-        D2D.Device D2DDevice;
-        D2D.DeviceContext D2DContext;
         D2D.Bitmap1 Bitmap;
         Size Size = new Size();
         DXGI.Surface Surface;
@@ -39,7 +37,7 @@ namespace FooEditEngine
         public D2DRender(FooTextBox textbox, Windows.UI.Xaml.Shapes.Rectangle rect)
             : base()
         {
-            this.ConstructDeviceResource(rect.ActualWidth, rect.ActualHeight);
+            this.ConstructRenderAndResoruce(rect.ActualWidth, rect.ActualHeight);
             this.InitTextFormat(textbox.FontFamily, textbox.FontSize);
 
             this.Size.Width = rect.ActualWidth;
@@ -73,7 +71,7 @@ namespace FooEditEngine
         {
             if (this.Size.Width == width && this.Size.Height == height)
                 return false;
-            this.ReConstructDeviceResource(width, height);
+            this.ReConstructRenderAndResource(width, height);
             this.CreateSurface(rect, width, height);
             return true;
         }
@@ -89,11 +87,6 @@ namespace FooEditEngine
             //デバイス依存の座標を渡さないといけない
             this.Surface = this.SurfaceImageNative.BeginDraw(
                 new SharpDX.Rectangle(0, 0, (int)(this.Size.Width * this.GetScale()), (int)(this.Size.Height * this.GetScale())), out offset);
-            var prop = new D2D.BitmapProperties1();
-            prop.BitmapOptions = D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw | D2D.BitmapOptions.GdiCompatible;
-            prop.PixelFormat = this._RenderTargetProperties.PixelFormat;
-            //prop.DpiX = this._RenderTargetProperties.DpiX;
-            //prop.DpiY = this._RenderTargetProperties.DpiY;
             this.Bitmap = new D2D.Bitmap1(this.D2DContext, this.Surface, null);
             this.D2DContext.Target = this.Bitmap;
             //こっちはDirect2Dなのでデバイス非依存の座標を渡す
@@ -128,30 +121,10 @@ namespace FooEditEngine
             rect.Fill = brush;
         }
 
-        D2D.RenderTargetProperties _RenderTargetProperties;
-        protected override D2D.RenderTarget ConstructRender(D2D.Factory1 factory, D2D.RenderTargetProperties prop, double width, double height)
-        {
-            this.D2DDevice = new D2D.Device(factory,this.DXGIDevice);
-            this.D2DContext = new D2D.DeviceContext(this.D2DDevice, D2D.DeviceContextOptions.None);
-            this.D2DContext.DotsPerInch = new Size2F(prop.DpiX, prop.DpiY);
-            this._RenderTargetProperties = prop;
-            return this.D2DContext;
-        }
-
-        protected override void ConstrctedResource()
-        {
-        }
-
-        protected override void DestructRender()
-        {
-            if (this.D2DDevice != null)
-                this.D2DDevice.Dispose();
-            if (this.D2DContext != null)
-                this.D2DContext.Dispose();
-        }
-
-        protected override void ReCreateTarget()
+        public void ReConstructRenderAndResource(double width, double height)
         {
+            this.DestructRenderAndResource();
+            this.ConstructRenderAndResoruce(width, height);
         }
     }
 }
index 2706f6a..71d4753 100644 (file)
@@ -30,6 +30,8 @@ namespace FooEditEngine
 
         protected DXGI.Device DXGIDevice;
         protected D3D11.Device1 D3DDevice;
+        protected D2D.Device D2DDevice;
+        protected D2D.DeviceContext D2DContext;
         FontFamily fontFamily;
         FontStyle fontStyle = FontStyle.Normal;
         FontWeight fontWeigth;
@@ -65,13 +67,38 @@ namespace FooEditEngine
             this.fontSize = size;
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool dispose)
         {
+            base.Dispose(dispose);
+            this.DestructRenderAndResource();
             if (this.DXGIDevice != null)
                 this.DXGIDevice.Dispose();
             if (this.D3DDevice != null)
                 this.D3DDevice.Dispose();
-            base.Dispose();
+        }
+
+        public virtual void ConstructRenderAndResoruce(double width, double height)
+        {
+            this.D2DDevice = new D2D.Device(this.D2DFactory, this.DXGIDevice);
+            this.D2DContext = new D2D.DeviceContext(this.D2DDevice, D2D.DeviceContextOptions.None);
+            float dpiX, dpiY;
+            this.GetDpi(out dpiX, out dpiY);
+            this.D2DContext.DotsPerInch = new Size2F(dpiX, dpiY);
+            this.render = this.D2DContext;
+            this.renderSize = new Size(width, height);
+            this.textRender = new CustomTextRenderer(this.render, this.Brushes, this.Strokes, this.Foreground);
+        }
+
+        public virtual void DestructRenderAndResource()
+        {
+            this.Brushes.Clear();
+            this.Strokes.Clear();
+            if (this.textRender != null)
+                this.textRender.Dispose();
+            if (this.D2DDevice != null)
+                this.D2DDevice.Dispose();
+            if (this.D2DContext != null)
+                this.D2DContext.Dispose();
         }
 
         public FontFamily FontFamily
index 1ea0c64..bfffead 100644 (file)
@@ -27,8 +27,6 @@ namespace FooEditEngine
     {
         DXGI.Surface Surface;
         D3D11.Texture2D Texture;
-        D2D.Device D2DDevice;
-        D2D.DeviceContext D2DContext;
         D2D.Bitmap1 Bitmap;
         Size Size;
         float dpi;
@@ -39,7 +37,7 @@ namespace FooEditEngine
             this.Size = size;
             this.dpi = dpi;
 
-            base.ConstructDeviceResource(size.Width, size.Height);
+            base.ConstructRenderAndResoruce(size.Width, size.Height);
             base.InitTextFormat(fontName, (float)fontSize);
         }
 
@@ -59,7 +57,8 @@ namespace FooEditEngine
 
         public void Resize(float width,float height)
         {
-            this.ReConstructDeviceResource(width, height);
+            this.DestructRenderAndResource();
+            this.ConstructRenderAndResoruce(width, height);
         }
 
         public void SetScale(float scale)
@@ -67,7 +66,7 @@ namespace FooEditEngine
             this.D2DContext.Transform = Matrix3x2.Scaling(1/scale);
         }
 
-        protected override D2D.RenderTarget ConstructRender(D2D.Factory1 factory, D2D.RenderTargetProperties prop, double width, double height)
+        public override void ConstructRenderAndResoruce(double width, double height)
         {
             D3D11.Texture2DDescription desc = new D3D11.Texture2DDescription();
             desc.Width = (int)(width * this.dpi / 96);
@@ -83,11 +82,7 @@ namespace FooEditEngine
 
             this.Surface = this.Texture.QueryInterface<DXGI.Surface>();
 
-            this.D2DDevice = new D2D.Device(factory, this.DXGIDevice);
-            
-            this.D2DContext = new D2D.DeviceContext(this.D2DDevice, D2D.DeviceContextOptions.None);
-
-            this.D2DContext.DotsPerInch = new Size2F(this.dpi, this.dpi);
+            base.ConstructRenderAndResoruce(width, height);
 
             D2D.BitmapProperties1 bmpProp = new D2D.BitmapProperties1();
             bmpProp.BitmapOptions = D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw;
@@ -96,32 +91,20 @@ namespace FooEditEngine
             this.Bitmap = new D2D.Bitmap1(this.D2DContext, this.Surface, bmpProp);
 
             this.D2DContext.Target = this.Bitmap;
-
-            return this.D2DContext;
-        }
-
-        protected override void ConstrctedResource()
-        {
+            this.D2DContext.DotsPerInch = new Size2F(this.dpi, this.dpi);
         }
 
-        protected override void DestructRender()
+        protected override void Dispose(bool dispose)
         {
             if (this.Bitmap != null)
                 this.Bitmap.Dispose();
-            if (this.D2DContext != null)
-                this.D2DContext.Dispose();
-            if (this.D2DDevice != null)
-                this.D2DDevice.Dispose();
+            base.Dispose(dispose);
             if (this.Surface != null)
                 this.Surface.Dispose();
             if (this.Texture != null)
                 this.Texture.Dispose();
         }
 
-        protected override void ReCreateTarget()
-        {
-        }
-
         public float HeaderHeight
         {
             get { return (float)this.emSize.Height; }
index 5f2914b..39a78c9 100644 (file)
@@ -16,8 +16,6 @@ namespace FooEditEngine
 {
     sealed class D2DPrintRender : D2DRenderBase, ITextRender, IPrintableTextRender
     {
-        D2D.Device D2DDevice;
-        D2D.DeviceContext D2DContext;
         D2D.PrintControl Control;
         D2D.CommandList CommandList;
         Size2F Size;
@@ -29,7 +27,7 @@ namespace FooEditEngine
             : base()
         {
             this.WICFactory = new ImagingFactory();
-            base.ConstructDeviceResource(size.Width, size.Height);
+            base.ConstructRenderAndResoruce(size.Width, size.Height);
             base.InitTextFormat(fontName, (float)fontSize);
 
             this.docPackageTarget = new ComObject(docPackageTarget);    //あとで廃棄する必要がある
@@ -69,38 +67,20 @@ namespace FooEditEngine
             this.dpi = (int)dpi;
         }
 
-        protected override D2D.RenderTarget ConstructRender(D2D.Factory1 factory, D2D.RenderTargetProperties prop, double width, double height)
-        {
-            this.D2DDevice = new D2D.Device(factory,this.DXGIDevice);
-            this.D2DContext = new D2D.DeviceContext(this.D2DDevice, D2D.DeviceContextOptions.None);
-            return this.D2DContext;
-        }
-
-        protected override void ConstrctedResource()
-        {
-        }
-
-        protected override void DestructRender()
+        public override void DestructRenderAndResource()
         {
             if (this.Control != null)
             {
                 this.Control.Close();
                 this.Control.Dispose();
             }
-            if (this.D2DDevice != null)
-                this.D2DDevice.Dispose();
-            if (this.D2DContext != null)
-                this.D2DContext.Dispose();
+            base.DestructRenderAndResource();
             if (this.docPackageTarget != null)
                 this.docPackageTarget.Dispose();
             if (this.WICFactory != null)
                 this.WICFactory.Dispose();
         }
 
-        protected override void ReCreateTarget()
-        {
-        }
-
         public float HeaderHeight
         {
             get { return (float)this.emSize.Height; }
index 7ed0412..4bb0c50 100644 (file)
@@ -38,7 +38,6 @@ namespace FooEditEngine.WPF
         D3D11.Device device;
         D3D9.Device device9;
         D3D9.Surface surface9;
-        new D2D.RenderTarget render;
         double fontSize;
         FontFamily fontFamily;
         FontWeight fontWeigth;
@@ -70,7 +69,7 @@ namespace FooEditEngine.WPF
 
             this.CreateDevice();
 
-            this.ConstructDeviceResource(width, height);
+            this.ConstructRenderAndResource(width, height);
             this.InitTextFormat(this.fontFamily.Source, (float)this.fontSize, this.GetDWFontWeigth(this.fontWeigth), this.GetDWFontStyle(this.fontStyle));
 
             this.imageSource = new D3DImage();
@@ -138,7 +137,7 @@ namespace FooEditEngine.WPF
         {
             if (Math.Floor(width) != Math.Floor(this.imageSource.Width) || Math.Floor(height) != Math.Floor(this.imageSource.Height))
             {
-                this.ReConstructDeviceResource(width, height);
+                this.ReConstructRenderAndResource(width, height);
                 this.imageSource.Lock();
                 this.imageSource.SetBackBuffer(D3DResourceType.IDirect3DSurface9, this.surface9.NativePointer);
                 this.imageSource.Unlock();
@@ -147,6 +146,12 @@ namespace FooEditEngine.WPF
             return false;
         }
 
+        public void ReConstructRenderAndResource(double width, double height)
+        {
+            this.DestructRenderAndResource();
+            this.ConstructRenderAndResource(width, height);
+        }
+
         public void DrawContent(EditView view,bool IsEnabled,Rectangle updateRect)
         {
             if (this.imageSource.IsFrontBufferAvailable)
@@ -254,12 +259,6 @@ namespace FooEditEngine.WPF
             return new Color4(colorref.R / 255.0f, colorref.G / 255.0f, colorref.B / 255.0f, 1);
         }
 
-        public override void Dispose()
-        {
-            base.Dispose();
-            this.DestructDevice();
-        }
-
         DW.FontStyle GetDWFontStyle(FontStyle style)
         {
             return (DW.FontStyle)Enum.Parse(typeof(DW.FontStyle), style.ToString());
@@ -366,16 +365,18 @@ namespace FooEditEngine.WPF
             }
         }
 
-        protected override void ReCreateTarget()
+        public void ConstructRenderAndResource(double width, double height)
         {
-            System.Diagnostics.Debug.WriteLine("ReCreatedDevice");
-            this.DestructDevice();
-            this.CreateDevice();
-            this.ReConstructDeviceResource();
-        }
+            float dpiX, dpiY;
+            this.GetDpi(out dpiX, out dpiY);
+            D2D.RenderTargetProperties prop = new D2D.RenderTargetProperties(
+                D2D.RenderTargetType.Default,
+                new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
+                dpiX,
+                dpiY,
+                D2D.RenderTargetUsage.None,
+                D2D.FeatureLevel.Level_DEFAULT);
 
-        protected override D2D.RenderTarget ConstructRender(D2D.Factory factory, D2D.RenderTargetProperties prop, double width, double height)
-        {
             D3D11.Texture2DDescription desc = new D3D11.Texture2DDescription();
             desc.Width = (int)width;
             desc.Height = (int)height;
@@ -406,12 +407,37 @@ namespace FooEditEngine.WPF
             resource.Dispose();
             texture.Dispose();
 
-            this.render = new D2D.RenderTarget(factory, this.surface, prop);
-            return this.render;
+            this.render = new D2D.RenderTarget(this.D2DFactory, this.surface, prop);
+
+            D2D.BitmapProperties bmpProp = new D2D.BitmapProperties();
+            bmpProp.DpiX = dpiX;
+            bmpProp.DpiY = dpiY;
+            bmpProp.PixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);
+            this.cachedBitMap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
+            this.hasCache = false;
+
+            this.textRender = new CustomTextRenderer(this.render, this.Brushes, this.Strokes, this.Foreground);
+
+            this.renderSize = new Size(width, height);
         }
 
-        protected override void ConstrctedResource()
+        public void DestructRenderAndResource()
         {
+            this.hasCache = false;
+            if (this.cachedBitMap != null)
+                this.cachedBitMap.Dispose();
+            this.Brushes.Clear();
+            this.Strokes.Clear();
+            if (this.textRender != null)
+                this.textRender.Dispose();
+            if (this.texture != null)
+                this.texture.Dispose();
+            if (this.surface != null)
+                this.surface.Dispose();
+            if (this.surface9 != null)
+                this.surface9.Dispose();
+            if (this.render != null)
+                this.render.Dispose();
         }
 
         public override void GetDpi(out float dpix, out float dpiy)
@@ -423,16 +449,12 @@ namespace FooEditEngine.WPF
             dpiy = (int)dpiYProperty.GetValue(null, null);
         }
 
-        protected override void DestructRender()
+        protected override void Dispose(bool dispose)
         {
-            if (this.texture != null)
-                this.texture.Dispose();
-            if (this.surface != null)
-                this.surface.Dispose();
-            if (this.surface9 != null)
-                this.surface9.Dispose();
-            if (this.render != null)
-                this.render.Dispose();
+            base.Dispose(dispose);
+            this.DestructRenderAndResource();
+            this.DestructDevice();
         }
+
     }
 }
index 8d123ce..faa8aca 100644 (file)
@@ -42,7 +42,7 @@ namespace FooEditEngine.Windows
             this.fontSize = textbox.Font.Size;
             this.InitTextFormat(textbox.Font.Name, (float)textbox.Font.Size);
             //初期化ができないので適当なサイズで作る
-            this.ReConstructDeviceResource(100, 100);
+            this.ReConstructRenderAndResource(100, 100);
         }
 
         public override void GetDpi(out float dpix, out float dpiy)
@@ -67,7 +67,7 @@ namespace FooEditEngine.Windows
         void textbox_SizeChanged(object sender, EventArgs e)
         {
             FooTextBox textbox = (FooTextBox)sender;
-            this.ReConstructDeviceResource(this.TextBox.Width, this.TextBox.Height);
+            this.ReConstructRenderAndResource(this.TextBox.Width, this.TextBox.Height);
         }
 
         public static Color4 ToColor4(System.Drawing.Color color)
@@ -109,20 +109,41 @@ namespace FooEditEngine.Windows
             base.EndDraw();
         }
 
-        D2D.WindowRenderTarget WindowRender;
+        public void ReConstructRenderAndResource(double width, double height)
+        {
+            this.DestructRenderAndResource();
+            this.ConstructRenderAndResource(width, height);
+        }
 
-        protected override D2D.RenderTarget ConstructRender(D2D.Factory factory, D2D.RenderTargetProperties prop, double width, double height)
+        public void ConstructRenderAndResource(double width, double height)
         {
+            float dpiX, dpiY;
+            this.GetDpi(out dpiX, out dpiY);
+            D2D.RenderTargetProperties prop = new D2D.RenderTargetProperties(
+                D2D.RenderTargetType.Default,
+                new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
+                dpiX,
+                dpiY,
+                D2D.RenderTargetUsage.None,
+                D2D.FeatureLevel.Level_DEFAULT);
+
             D2D.HwndRenderTargetProperties hwndProp = new D2D.HwndRenderTargetProperties();
             hwndProp.Hwnd = this.TextBox.Handle;
-            hwndProp.PixelSize = new SharpDX.Size2(this.TextBox.Size.Width,this.TextBox.Size.Height);
+            hwndProp.PixelSize = new SharpDX.Size2(this.TextBox.Size.Width, this.TextBox.Size.Height);
             hwndProp.PresentOptions = D2D.PresentOptions.Immediately;
-            this.WindowRender = new D2D.WindowRenderTarget(factory,prop,hwndProp);
-            return this.WindowRender;
-        }
+            this.render = new D2D.WindowRenderTarget(this.D2DFactory, prop, hwndProp);
+
+            D2D.BitmapProperties bmpProp = new D2D.BitmapProperties();
+            bmpProp.DpiX = dpiX;
+            bmpProp.DpiY = dpiY;
+            bmpProp.PixelFormat = new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied);
+            this.cachedBitMap = new D2D.Bitmap(this.render, new SharpDX.Size2((int)width, (int)height), bmpProp);
+            this.hasCache = false;
+
+            this.textRender = new CustomTextRenderer(this.render, this.Brushes, this.Strokes, this.Foreground);
+
+            this.renderSize = new Size(width, height);
 
-        protected override void ConstrctedResource()
-        {
             //デフォルト値を反映させる
             this.Foreground = ToColor4(this.TextBox.Foreground);
             this.Background = ToColor4(this.TextBox.Background);
@@ -140,10 +161,17 @@ namespace FooEditEngine.Windows
             this.HilightForeground = ToColor4(this.TextBox.HilightForeground);
         }
 
-        protected override void DestructRender()
+        public void DestructRenderAndResource()
         {
-            if (this.WindowRender != null)
-                this.WindowRender.Dispose();
+            this.hasCache = false;
+            if (this.cachedBitMap != null)
+                this.cachedBitMap.Dispose();
+            this.Brushes.Clear();
+            this.Strokes.Clear();
+            if (this.textRender != null)
+                this.textRender.Dispose();
+            if (this.render != null)
+                this.render.Dispose();
         }
     }