1 Star 0 Fork 1

Hesenjan/UyghurEditPP

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ImlaBoya.cs 2.68 KB
一键复制 编辑 原始数据 按行查看 历史
Uyghur 提交于 2021-04-09 12:18 . Add files via upload
/*
* 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);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/HesenjanJava/UyghurEditPP.git
git@gitee.com:HesenjanJava/UyghurEditPP.git
HesenjanJava
UyghurEditPP
UyghurEditPP
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385