{
sealed class CustomTextRenderer : CallbackBase, DW.TextRenderer
{
- D2D.RenderTarget render;
ColorBrushCollection brushes;
StrokeCollection strokes;
- public CustomTextRenderer(D2D.RenderTarget render, ColorBrushCollection brushes,StrokeCollection strokes,Color4 defalut)
+ public CustomTextRenderer(ColorBrushCollection brushes,StrokeCollection strokes,Color4 defalut)
{
- this.render = render;
this.DefaultFore = defalut;
this.brushes = brushes;
this.strokes = strokes;
public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, D2D.MeasuringMode measuringMode, DW.GlyphRun glyphRun, DW.GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
{
- D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+ D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+ if (render == null)
+ return SharpDX.Result.Ok;
+
+ D2D.SolidColorBrush foreBrush = this.brushes.Get(render, this.DefaultFore);
bool isDrawGlyphRun = true;
if (clientDrawingEffect != null)
{
}
else if(selectedEffect != null)
{
- foreBrush = this.brushes.Get(selectedEffect.Fore);
+ foreBrush = this.brushes.Get(render, selectedEffect.Fore);
}
else if (drawingEffect != null)
{
if (drawingEffect.Stroke == HilightType.Url)
- foreBrush = this.brushes.Get(drawingEffect.Fore);
+ foreBrush = this.brushes.Get(render, drawingEffect.Fore);
}
}
public Result DrawInlineObject(object clientDrawingContext, float originX, float originY, DW.InlineObject inlineObject, bool isSideways, bool isRightToLeft, ComObject clientDrawingEffect)
{
- inlineObject.Draw(this.render, this, originX, originY, isSideways, isRightToLeft, clientDrawingEffect);
+ D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+ if (render == null)
+ return SharpDX.Result.Ok;
+
+ inlineObject.Draw(render, this, originX, originY, isSideways, isRightToLeft, clientDrawingEffect);
return Result.Ok;
}
public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref DW.Strikethrough strikethrough, ComObject clientDrawingEffect)
{
- D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+ D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+ if (render == null)
+ return SharpDX.Result.Ok;
+
+ D2D.SolidColorBrush foreBrush = this.brushes.Get(render, this.DefaultFore);
DrawingEffect effect = clientDrawingEffect as DrawingEffect;
if (clientDrawingEffect != null && clientDrawingEffect != null)
{
- foreBrush = this.brushes.Get(effect.Fore);
+ foreBrush = this.brushes.Get(render, effect.Fore);
}
if (effect == null)
{
render.DrawLine(new Vector2(baselineOriginX, baselineOriginY + strikethrough.Offset),
new Vector2(baselineOriginX + strikethrough.Width - 1, baselineOriginY + strikethrough.Offset),
foreBrush,
- GetThickness(strikethrough.Thickness));
+ GetThickness(render, strikethrough.Thickness));
}
return Result.Ok;
}
public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref DW.Underline underline, ComObject clientDrawingEffect)
{
- D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+ D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+ if (render == null)
+ return SharpDX.Result.Ok;
+
+ D2D.SolidColorBrush foreBrush = this.brushes.Get(render, this.DefaultFore);
DrawingEffect effect = clientDrawingEffect as DrawingEffect;
if (clientDrawingEffect != null && effect != null)
{
- foreBrush = this.brushes.Get(effect.Fore);
+ foreBrush = this.brushes.Get(render, effect.Fore);
float thickness = effect.isBoldLine ? D2DRenderCommon.BoldThickness : D2DRenderCommon.NormalThickness;
if (effect.Stroke == HilightType.Squiggle)
{
- SquilleLineMarker marker = new D2DSquilleLineMarker(this.render, this.brushes.Get(effect.Fore), this.strokes.Get(this.render,effect.Stroke), 1);
+ SquilleLineMarker marker = new D2DSquilleLineMarker(render, this.brushes.Get(render, effect.Fore), this.strokes.Get(render,effect.Stroke), 1);
marker.Draw(
baselineOriginX, baselineOriginY + underline.Offset,
underline.Width, underline.RunHeight
}
else
{
- LineMarker marker = new LineMarker(this.render, this.brushes.Get(effect.Fore), this.strokes.Get(this.render,effect.Stroke), GetThickness(thickness));
+ LineMarker marker = new LineMarker(render, this.brushes.Get(render, effect.Fore), this.strokes.Get(render,effect.Stroke), GetThickness(render, thickness));
marker.Draw(
baselineOriginX, baselineOriginY + underline.Offset,
underline.Width, 0
render.DrawLine(new Vector2(baselineOriginX, baselineOriginY + underline.Offset),
new Vector2(baselineOriginX + underline.Width - 1, baselineOriginY + underline.Offset),
foreBrush,
- GetThickness(underline.Thickness));
+ GetThickness(render,underline.Thickness));
}
return SharpDX.Result.Ok;
public SharpDX.Mathematics.Interop.RawMatrix3x2 GetCurrentTransform(object clientDrawingContext)
{
+ D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+ if (render == null)
+ throw new InvalidOperationException("render is null");
+
SharpDX.Mathematics.Interop.RawMatrix3x2 d2Dmatrix = render.Transform;
return d2Dmatrix;
}
public float GetPixelsPerDip(object clientDrawingContext)
{
+ D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
+ if (render == null)
+ throw new InvalidOperationException("render is null");
+
return render.PixelSize.Width / 96f;
}
#endregion
- float GetThickness(float thickness)
+ float GetThickness(D2D.RenderTarget render,float thickness)
{
- if (this.render.AntialiasMode == D2D.AntialiasMode.Aliased)
+ if (render.AntialiasMode == D2D.AntialiasMode.Aliased)
return (int)(thickness + 0.5);
else
return thickness;
public event EventHandler RenderChanged;
- public D2D.RenderTarget Render
+ public D2D.SolidColorBrush Get(D2D.RenderTarget render,Color4 key)
{
- get
- {
- return this._render;
- }
- set
- {
- this._render = value;
- this.Clear();
- if (this.RenderChanged != null)
- this.RenderChanged(this, null);
- }
- }
-
- public D2D.SolidColorBrush Get(Color4 key)
- {
- if (this.Render == null || this.Render.IsDisposed)
- throw new InvalidOperationException();
D2D.SolidColorBrush brush;
bool result = cache.TryGetValue(key, out brush);
if (!result)
{
- brush = new D2D.SolidColorBrush(this.Render, key);
+ brush = new D2D.SolidColorBrush(render, key);
cache.Add(key, brush);
}
{
if (_D2DFactory == null)
{
- _D2DFactory = new D2D.Factory1(D2D.FactoryType.MultiThreaded);
+ _D2DFactory = new D2D.Factory1(D2D.FactoryType.SingleThreaded);
}
return _D2DFactory;
}
{
if (_D2DFactory == null)
{
- _D2DFactory = new D2D.Factory(D2D.FactoryType.MultiThreaded);
+ _D2DFactory = new D2D.Factory(D2D.FactoryType.SingleThreaded);
}
return _D2DFactory;
}
{
_render = value;
this.TextAntialiasMode = this._TextAntialiasMode;
- this.Brushes.Render = this.render;
}
}
if(this.format != null)
this.format.Dispose();
- if (this.HiddenChars != null)
- this.HiddenChars = null;
-
float dpix, dpiy;
this.GetDpi(out dpix, out dpiy);
ellipse.Point = p;
ellipse.RadiusX = (float)radius;
ellipse.RadiusY = (float)radius;
- this.render.FillEllipse(ellipse, this.Brushes.Get(this.Background));
- this.render.DrawEllipse(ellipse, this.Brushes.Get(this.Foreground));
+ this.render.FillEllipse(ellipse, this.Brushes.Get(this.render,this.Background));
+ this.render.DrawEllipse(ellipse, this.Brushes.Get(this.render, this.Foreground));
}
switch (colorType)
{
case StringColorType.Forground:
- brush = this.Brushes.Get(this.Foreground);
+ brush = this.Brushes.Get(this.render, this.Foreground);
break;
case StringColorType.LineNumber:
- brush = this.Brushes.Get(this.LineNumber);
+ brush = this.Brushes.Get(this.render, this.LineNumber);
break;
default:
throw new ArgumentOutOfRangeException();
switch(type)
{
case FillRectType.OverwriteCaret:
- brush = this.Brushes.Get(this.OverwriteCaret);
+ brush = this.Brushes.Get(this.render, this.OverwriteCaret);
this.render.FillRectangle(rect, brush);
break;
case FillRectType.InsertCaret:
- brush = this.Brushes.Get(this.InsertCaret);
+ brush = this.Brushes.Get(this.render, this.InsertCaret);
this.render.FillRectangle(rect, brush);
break;
case FillRectType.InsertPoint:
- brush = this.Brushes.Get(this.Hilight);
+ brush = this.Brushes.Get(this.render, this.Hilight);
this.render.FillRectangle(rect, brush);
break;
case FillRectType.LineMarker:
- brush = this.Brushes.Get(this.LineMarker);
+ brush = this.Brushes.Get(this.render, this.LineMarker);
this.render.DrawRectangle(rect, brush, EditView.LineMarkerThickness);
break;
case FillRectType.UpdateArea:
- brush = this.Brushes.Get(this.UpdateArea);
+ brush = this.Brushes.Get(this.render, this.UpdateArea);
this.render.FillRectangle(rect, brush);
break;
}
}
}
- layout.Draw(textRender, (float)x, (float)y);
+ layout.Draw(this.render,textRender, (float)x, (float)y);
}
{
if (color == null)
return;
- layout.SetDrawingEffect(this.Brushes.Get((Color4)color), new DW.TextRange(start, length));
+ layout.SetDrawingEffect(this.Brushes.Get(this.render, (Color4)color), new DW.TextRange(start, length));
}
public void DrawLine(Point from, Point to)
{
- D2D.Brush brush = this.Brushes.Get(this.Foreground);
+ D2D.Brush brush = this.Brushes.Get(this.render, this.Foreground);
D2D.StrokeStyle stroke = this.Strokes.Get(D2DRenderShared.D2DFactory,HilightType.Sold);
this.render.DrawLine(from, to, brush, 1.0f, stroke);
}
color = this.Foreground;
IMarkerEffecter effecter = null;
- D2D.SolidColorBrush brush = this.Brushes.Get(color);
+ D2D.SolidColorBrush brush = this.Brushes.Get(this.render, color);
if (type == HilightType.Squiggle)
effecter = new D2DSquilleLineMarker(this.render, brush, this.Strokes.Get(D2DRenderShared.D2DFactory, HilightType.Squiggle), thickness);
{
foreach (SyntaxInfo s in syntaxCollection)
{
- D2D.SolidColorBrush brush = this.Brushes.Get(this.Foreground);
+ D2D.SolidColorBrush brush = this.Brushes.Get(this.render, this.Foreground);
switch (s.type)
{
case TokenType.Comment:
- brush = this.Brushes.Get(this.Comment);
+ brush = this.Brushes.Get(this.render, this.Comment);
break;
case TokenType.Keyword1:
- brush = this.Brushes.Get(this.Keyword1);
+ brush = this.Brushes.Get(this.render, this.Keyword1);
break;
case TokenType.Keyword2:
- brush = this.Brushes.Get(this.Keyword2);
+ brush = this.Brushes.Get(this.render, this.Keyword2);
break;
case TokenType.Literal:
- brush = this.Brushes.Get(this.Literal);
+ brush = this.Brushes.Get(this.render, this.Literal);
break;
}
newLayout.SetDrawingEffect(brush, new DW.TextRange(s.index, s.length));
if (inlineObject != null)
{
layout.SetInlineObject(inlineObject, new DW.TextRange(i, 1));
- layout.SetDrawingEffect(this.Brushes.Get(this.ControlChar), new DW.TextRange(i, 1));
+ layout.SetDrawingEffect(this.Brushes.Get(this.render, this.ControlChar), new DW.TextRange(i, 1));
}
}
- layout.SetLineBreakBrush(this.Brushes.Get(this.ControlChar));
+ layout.SetLineBreakBrush(this.Brushes.Get(this.render, this.ControlChar));
}
}
}
if (render == null)
return;
- D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+ D2D.SolidColorBrush foreBrush = this.brushes.Get(render,this.DefaultFore);
if (clientDrawingEffect != null)
{
var drawingForeBrush = clientDrawingEffect as D2D.SolidColorBrush;
}
else if (selectedEffect != null)
{
- foreBrush = this.brushes.Get(selectedEffect.Fore);
+ foreBrush = this.brushes.Get(render, selectedEffect.Fore);
}
}
D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget;
if (render == null)
return;
- D2D.SolidColorBrush foreBrush = this.brushes.Get(this.DefaultFore);
+ D2D.SolidColorBrush foreBrush = this.brushes.Get(render, this.DefaultFore);
if (clientDrawingEffect != null)
{
var drawingForeBrush = clientDrawingEffect as D2D.SolidColorBrush;
}
else if (selectedEffect != null)
{
- foreBrush = this.brushes.Get(selectedEffect.Fore);
+ foreBrush = this.brushes.Get(render, selectedEffect.Fore);
}
}
DW.InlineObjectMetrics metrics = this.Metrics;
this._Format = format;
this._Fore = fore;
this.Brushes = brushes;
- this.Brushes.RenderChanged += Brushes_RenderChanged;
}
public bool ContainsSymbol(char c)
}
else
{
- D2D.SolidColorBrush brush = this.Brushes.Get(this.Fore);
for (int i = 0; i < DuplicateCount; i++)
{
this.InlineChars.Add(c, new InlineChar(this.Factory, this.Format, this.Brushes, this.Fore, alt));
if (!this.InlineTabs.TryGet(width, out collection))
{
collection = new List<InlineTab>();
- D2D.SolidColorBrush brush = this.Brushes.Get(this.Fore);
for (int i = 0; i < DuplicateCount; i++)
collection.Add(new InlineTab(this.Brushes, this.Fore, width, layout.Height));
this.InlineTabs.Add(width, collection);
this.InlineTabs.Clear();
- D2D.SolidColorBrush brush = this.Brushes.Get(this.Fore);
foreach (KeyValuePair<char, char> kv in list)
for (int i = 0; i < DuplicateCount; i++)
this.InlineChars.Add(kv.Key, new InlineChar(this.Factory, this.Format, this.Brushes, this.Fore, kv.Value));
}
- void Brushes_RenderChanged(object sender, EventArgs e)
- {
- this.ReGenerate();
- }
}
sealed class MultiSet<T, J>
where J : IDisposable
}
}
- public void Draw(DW.TextRenderer render, float x, float y)
+ public void Draw(D2D.RenderTarget d2drender, DW.TextRenderer render, float x, float y)
{
- this.layout.Draw(render, x, y);
+ this.layout.Draw(d2drender, render, x, y);
}
public void Draw(D2D.RenderTarget render, float x, float y, D2D.Brush brush)
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);
+ this.textRender = new CustomTextRenderer(this.Brushes, this.Strokes, this.Foreground);
}
public void ReinitTextFormat()
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.textRender = new CustomTextRenderer(this.Brushes, this.Strokes, this.Foreground);
this.renderSize = new Size(width, height);
}
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.textRender = new CustomTextRenderer(this.Brushes, this.Strokes, this.Foreground);
this.renderSize = new Size(width, height);