public void DrawMarkerEffect(MyTextLayout layout, HilightType type, int start, int length, double x, double y, bool isBold, Color4?effectColor = null) { if (type == HilightType.None) { return; } float thickness = isBold ? BoldThickness : NormalThickness; Color4 color; if (effectColor != null) { color = (Color4)effectColor; } else if (type == HilightType.Select) { color = this.Hilight; } else { color = this.Foreground; } IMarkerEffecter effecter = null; D2D.SolidColorBrush brush = this._factory.GetSolidColorBrush(color); if (type == HilightType.Squiggle) { effecter = new D2DSquilleLineMarker(this.render, brush, this._factory.GetStroke(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._factory.GetStroke(type), thickness); } if (effecter != null) { bool isUnderline = type != HilightType.Select; DW.HitTestMetrics[] metrics = layout.HitTestTextRange(start, length, (float)x, (float)y); foreach (DW.HitTestMetrics metric in metrics) { float offset = isUnderline ? metric.Height : 0; effecter.Draw(metric.Left, metric.Top + offset, metric.Width, metric.Height); } } }
public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref DW.Underline underline, ComObject clientDrawingEffect) { D2D.RenderTarget render = clientDrawingContext as D2D.RenderTarget; if (render == null) { return(SharpDX.Result.Ok); } D2D.SolidColorBrush foreBrush = this.factory.GetSolidColorBrush(this.DefaultFore); DrawingEffect effect = clientDrawingEffect as DrawingEffect; if (clientDrawingEffect != null && effect != null) { foreBrush = this.factory.GetSolidColorBrush(effect.Fore); float thickness = effect.isBoldLine ? D2DRenderCommon.BoldThickness : D2DRenderCommon.NormalThickness; if (effect.Stroke == HilightType.Squiggle) { SquilleLineMarker marker = new D2DSquilleLineMarker(render, this.factory.GetSolidColorBrush(effect.Fore), this.factory.GetStroke(effect.Stroke), 1); marker.Draw( baselineOriginX, baselineOriginY + underline.Offset, underline.Width, underline.RunHeight ); } else { LineMarker marker = new LineMarker(render, this.factory.GetSolidColorBrush(effect.Fore), this.factory.GetStroke(effect.Stroke), GetThickness(render, thickness)); marker.Draw( baselineOriginX, baselineOriginY + underline.Offset, underline.Width, 0 ); } } if (effect == null) { render.DrawLine(new Vector2(baselineOriginX, baselineOriginY + underline.Offset), new Vector2(baselineOriginX + underline.Width - 1, baselineOriginY + underline.Offset), foreBrush, GetThickness(render, underline.Thickness)); } return(SharpDX.Result.Ok); }