{
ResourceManager<HilightType, D2D.StrokeStyle> cache = new ResourceManager<HilightType, D2D.StrokeStyle>();
- public D2D.Factory Factory;
-
public D2D.StrokeStyle Get(D2D.RenderTarget render,HilightType type)
{
return this.Get(render.Factory, type);
[Obsolete]
public D2D.StrokeStyle Get(HilightType type)
{
- return this.Get(this.Factory, type);
+ return this.Get(D2DRenderShared.D2DFactory, type);
}
public D2D.StrokeStyle Get(D2D.Factory factory,HilightType type)
{
- if(this.Factory == null || this.Factory.IsDisposed)
- throw new InvalidOperationException();
D2D.StrokeStyle stroke;
if (this.cache.TryGetValue(type, out stroke))
return stroke;
prop.DashStyle = D2D.DashStyle.Dot;
break;
}
- stroke = new D2D.StrokeStyle(this.Factory, prop);
+ stroke = new D2D.StrokeStyle(D2DRenderShared.D2DFactory, prop);
this.cache.Add(type, stroke);
return stroke;
}
}
}
+ class D2DRenderShared
+ {
+ static DW.Factory _DWFactory;
+ static public DW.Factory DWFactory
+ {
+ get
+ {
+ if(_DWFactory == null)
+ {
+ _DWFactory = new DW.Factory(DW.FactoryType.Shared);
+ }
+ return _DWFactory;
+ }
+ }
+#if METRO || WINDOWS_UWP
+ static D2D.Factory1 _D2DFactory;
+
+ static public D2D.Factory1 D2DFactory
+ {
+ get
+ {
+ if (_D2DFactory == null)
+ {
+ _D2DFactory = new D2D.Factory1(D2D.FactoryType.SingleThreaded);
+ }
+ return _D2DFactory;
+ }
+ }
+#else
+ static D2D.Factory _D2DFactory;
+ static public D2D.Factory D2DFactory
+ {
+ get
+ {
+ if (_D2DFactory == null)
+ {
+ _D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded);
+ }
+ return _D2DFactory;
+ }
+ }
+#endif
+
+ }
+
class D2DRenderCommon : IDisposable
{
InlineManager HiddenChars;
TextAntialiasMode _TextAntialiasMode;
Color4 _ControlChar,_Forground,_URL,_Hilight;
- DW.Factory DWFactory;
DW.TextFormat format;
protected CustomTextRenderer textRender;
protected D2D.Bitmap cachedBitMap;
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 ColorBrushCollection Brushes
{
get;
public D2DRenderCommon()
{
- this.DWFactory = new DW.Factory(DW.FactoryType.Shared);
-#if METRO || WINDOWS_UWP
- this.D2DFactory = new D2D.Factory1(D2D.FactoryType.SingleThreaded);
-#else
- this.D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded);
-#endif
this.Brushes = new ColorBrushCollection();
this.Strokes = new StrokeCollection();
- this.Strokes.Factory = this.D2DFactory;
this.ChangedRenderResource += (s, e) => { };
this.ChangedRightToLeft += (s, e) => { };
this.renderSize = new Size();
float dpix, dpiy;
this.GetDpi(out dpix, out dpiy);
- this.format = new DW.TextFormat(this.DWFactory, fontName, fontWeigth, fontStyle, fontSize);
+ this.format = new DW.TextFormat(D2DRenderShared.DWFactory, fontName, fontWeigth, fontStyle, fontSize);
this.format.WordWrapping = DW.WordWrapping.NoWrap;
this.format.ReadingDirection = GetDWRightDirect(_RightToLeft);
if (this.HiddenChars == null)
- this.HiddenChars = new InlineManager(this.DWFactory, this.format, this.ControlChar, this.Brushes);
+ this.HiddenChars = new InlineManager(D2DRenderShared.DWFactory, this.format, this.ControlChar, this.Brushes);
else
this.HiddenChars.Format = this.format;
this.hasCache = false;
- MyTextLayout layout = new MyTextLayout(this.DWFactory, "0", this.format, float.MaxValue, float.MaxValue, dpix, false);
+ MyTextLayout layout = new MyTextLayout(D2DRenderShared.DWFactory, "0", this.format, float.MaxValue, float.MaxValue, dpix, false);
layout.RightToLeft = false;
this.emSize = new Size(layout.Width, layout.Height);
layout.Dispose();
- layout = new MyTextLayout(this.DWFactory, "+", this.format, float.MaxValue, float.MaxValue, dpix, false);
+ layout = new MyTextLayout(D2DRenderShared.DWFactory, "+", this.format, float.MaxValue, float.MaxValue, dpix, false);
layout.RightToLeft = false;
#if METRO
this.FoldingWidth = Math.Max(D2DRenderCommon.MiniumeWidth, layout.Width);
if (value == 0)
return;
this.tabLength = value;
- DW.TextLayout layout = new DW.TextLayout(this.DWFactory, "0", this.format, float.MaxValue, float.MaxValue);
+ DW.TextLayout layout = new DW.TextLayout(D2DRenderShared.DWFactory, "0", this.format, float.MaxValue, float.MaxValue);
float width = (float)(layout.Metrics.Width * value);
this.HiddenChars.TabWidth = width;
this.format.IncrementalTabStop = width;
throw new ArgumentOutOfRangeException();
}
this.GetDpi(out dpix, out dpiy);
- MyTextLayout layout = new MyTextLayout(this.DWFactory, str, this.format, (float)layoutRect.Width, (float)layoutRect.Height,dpix,false);
+ MyTextLayout layout = new MyTextLayout(D2DRenderShared.DWFactory, str, this.format, (float)layoutRect.Width, (float)layoutRect.Height,dpix,false);
layout.StringAlignment = align;
layout.Draw(this.render, (float)x, (float)y, brush);
layout.Dispose();
public void DrawLine(Point from, Point to)
{
D2D.Brush brush = this.Brushes.Get(this.Foreground);
- D2D.StrokeStyle stroke = this.Strokes.Get(this.D2DFactory,HilightType.Sold);
+ D2D.StrokeStyle stroke = this.Strokes.Get(D2DRenderShared.D2DFactory,HilightType.Sold);
this.render.DrawLine(from, to, brush, 1.0f, stroke);
}
D2D.SolidColorBrush brush = this.Brushes.Get(color);
if (type == HilightType.Squiggle)
- effecter = new D2DSquilleLineMarker(this.render, brush, this.Strokes.Get(this.D2DFactory, HilightType.Squiggle), thickness);
+ effecter = new D2DSquilleLineMarker(this.render, brush, this.Strokes.Get(D2DRenderShared.D2DFactory, HilightType.Squiggle), thickness);
else if (type == HilightType.Select)
effecter = new HilightMarker(this.render, brush);
else if (type == HilightType.None)
effecter = null;
else
- effecter = new LineMarker(this.render, brush, this.Strokes.Get(this.D2DFactory,type), thickness);
+ effecter = new LineMarker(this.render, brush, this.Strokes.Get(D2DRenderShared.D2DFactory,type), thickness);
if (effecter != null)
{
this.GetDpi(out dpix,out dpiy);
bool hasNewLine = str.Length > 0 && str[str.Length - 1] == Document.NewLine;
- MyTextLayout newLayout = new MyTextLayout(this.DWFactory,
+ MyTextLayout newLayout = new MyTextLayout(D2DRenderShared.DWFactory,
str,
this.format,
this.TextArea.Width,
foreach (string str in doc.GetLines(startIndex, endIndex))
{
- DW.TextLayout layout = new DW.TextLayout(this.DWFactory, str, this.format, (float)wrapwidth, float.MaxValue);
+ DW.TextLayout layout = new DW.TextLayout(D2DRenderShared.DWFactory, str, this.format, (float)wrapwidth, float.MaxValue);
int i = startIndex;
foreach (DW.LineMetrics metrics in layout.GetLineMetrics())
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;
}