代码拉取完成,页面将自动刷新
/*
* Created by SharpDevelop.
* User: Gheyret Kenji
* Date: 2020/12/07
* Time: 10:20
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using UyghurEditPP.Rendering;
using UyghurEditPP.Document;
using System.Windows.Media;
using System.Windows;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace UyghurEditPP
{
/// <summary>
/// Description of SinaqReng.
/// </summary>
public class ImlaBoya:DocumentColorizingTransformer
{
readonly TextDecorationCollection gCollection;
public ImlaBoya(){
SpellCheker = null;
gCollection = new TextDecorationCollection();
TextDecoration dec = new TextDecoration();
dec.Pen = new Pen { Thickness = 2, DashStyle = DashStyles.Dash, Brush = new SolidColorBrush(Colors.Red) };
dec.PenThicknessUnit = TextDecorationUnit.FontRecommended;
gCollection.Add(dec);
gCollection.Freeze();
FindReplace=false;
}
public IEnumerable<Match> FindWords(string text)
{
if(WordFinder==null) yield return null;
foreach (Match m in WordFinder.Matches(text))
{
yield return m;
}
}
public string Selection{
get;
set;
}
public int SelectionOffset{
get;
set;
}
public Regex WordFinder{
get;
set;
}
public UyghurSpell SpellCheker{
get;
set;
}
public bool FindReplace{
get;
set;
}
protected override void ColorizeLine(DocumentLine line)
{
if (line.Length == 0)
return;
int lineStartOffset = line.Offset;
string text = CurrentContext.Document.GetText(line).ToLower();
if(WordFinder!=null && SpellCheker!=null)
{
foreach(Match soz in FindWords(text))
{
if(soz!=null && SpellCheker.IsListed(soz.Value.Replace(Uyghur.Sozghuch,""))==false)
{
ChangeLinePart(lineStartOffset + soz.Index,lineStartOffset + soz.Index +soz.Value.Length ,ApplyChanges);
}
}
}
if(!FindReplace && !string.IsNullOrEmpty(Selection) && Selection.Length>0){
int start = 0;
int index;
while ((index = text.IndexOf(Selection, start, StringComparison.Ordinal)) >= 0)
{
if((lineStartOffset + index)!=SelectionOffset){
ChangeLinePart(lineStartOffset + index, lineStartOffset + index + Selection.Length, HilightSelection);
}
start = index + 1; // search for next occurrence
}
}
}
void ApplyChanges(VisualLineElement element)
{
element.TextRunProperties.SetTextDecorations(gCollection);
}
void HilightSelection(VisualLineElement element)
{
element.TextRunProperties.SetBackgroundBrush(Brushes.Yellow);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。