From: test Date: Mon, 4 Jan 2021 11:47:24 +0000 (+0900) Subject: 行を生成するメソッドをLineToIndexTableに移動した X-Git-Url: http://git.osdn.net/view?p=fooeditengine%2FFooEditEngine.git;a=commitdiff_plain;h=a7c04797c6dc821b47ba103e60b12c38d1c572d1;hp=94ac7fabf31808ac2cf533b62dee06cd9c5dbcaa 行を生成するメソッドをLineToIndexTableに移動した --- diff --git a/Core/Direct2D/D2DRenderCommon.cs b/Core/Direct2D/D2DRenderCommon.cs index c0c9ba9..fda591c 100644 --- a/Core/Direct2D/D2DRenderCommon.cs +++ b/Core/Direct2D/D2DRenderCommon.cs @@ -872,43 +872,6 @@ namespace FooEditEngine return newLayout; } - public List BreakLine(Document doc, LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth) - { - List output = new List(); - - this.format.WordWrapping = DW.WordWrapping.Wrap; - - foreach (string str in doc.GetLines(startIndex, endIndex)) - { - 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()) - { - if (metrics.Length == 0 && metrics.NewlineLength == 0) - continue; - - bool lineend = false; - if (metrics.NewlineLength > 0) - lineend = true; - - output.Add(layoutLineCollection.CreateLineToIndexTableData(i, (int)metrics.Length, lineend, null)); - i += Util.RoundUp(metrics.Length); - } - - layout.Dispose(); - - startIndex += str.Length; - } - - this.format.WordWrapping = DW.WordWrapping.NoWrap; - - if (output.Count > 0) - output.Last().LineEnd = true; - - return output; - } - bool _Disposed = false; public void Dispose() { diff --git a/Core/Document.cs b/Core/Document.cs index 526bfec..67fcf1f 100644 --- a/Core/Document.cs +++ b/Core/Document.cs @@ -189,9 +189,6 @@ namespace FooEditEngine this.Markers = new MarkerCollection(); this.UndoManager = new UndoManager(); this._LayoutLines = new LineToIndexTable(this); - this._LayoutLines.SpilitString = (s,e)=> { - return this.CreateLineList(e.index, e.length, MaximumLineLength); - }; this._LayoutLines.Clear(); this.MarkerPatternSet = new MarkerPatternSet(this._LayoutLines, this.Markers); this.MarkerPatternSet.Updated += WacthDogPattern_Updated; @@ -615,34 +612,6 @@ namespace FooEditEngine } } - /// - /// レイアウト行を返す - /// - /// 開始インデックス - /// 長さ - /// 1行当たりの最大文字数。-1で無制限 - /// レイアウト行リスト - internal IList CreateLineList(int index, int length, int lineLimitLength = -1) - { - int startIndex = index; - int endIndex = index + length - 1; - List output = new List(); - - foreach (Tuple range in this.ForEachLines(startIndex, endIndex, lineLimitLength)) - { - int lineHeadIndex = range.Item1; - int lineLength = range.Item2; - char c = this.buffer[lineHeadIndex + lineLength - 1]; - bool hasNewLine = c == Document.NewLine; - output.Add(this.LayoutLines.CreateLineToIndexTableData(lineHeadIndex, lineLength, hasNewLine, null)); - } - - if (output.Count > 0) - output.Last().LineEnd = true; - - return output; - } - internal void FireUpdate(DocumentUpdateEventArgs e) { this.buffer_Update(this.buffer, e); @@ -1057,15 +1026,19 @@ namespace FooEditEngine /// 行イテレーターが返される public IEnumerable GetLines(int startIndex, int endIndex, int maxCharCount = -1) { - return this.buffer.GetLines(startIndex, endIndex, maxCharCount); - } - - internal IEnumerable> ForEachLines(int startIndex, int endIndex, int maxCharCount = -1) - { - return this.buffer.ForEachLines(startIndex, endIndex, maxCharCount); + foreach (Tuple range in this.LayoutLines.ForEachLines(startIndex, endIndex, maxCharCount)) + { + StringBuilder temp = new StringBuilder(); + temp.Clear(); + int lineEndIndex = range.Item1; + if (range.Item2 > 0) + lineEndIndex += range.Item2 - 1; + for (int i = range.Item1; i <= lineEndIndex; i++) + temp.Append(this.buffer[i]); + yield return temp.ToString(); + } } - /// /// 文字列を追加する /// diff --git a/Core/ITextRender.cs b/Core/ITextRender.cs index 06613d1..0153f1f 100644 --- a/Core/ITextRender.cs +++ b/Core/ITextRender.cs @@ -622,17 +622,6 @@ namespace FooEditEngine void DrawOneLine(Document doc,LineToIndexTable lti, int row, double x, double y); /// - /// 行を折り返す - /// - /// ドキュメント - /// レイアウトライン - /// 開始インデックス - /// 終了インデックス - /// 折り返しの幅 - /// 行のリスト - List BreakLine(Document doc,LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth); - - /// /// レイアウトを生成する /// /// 文字列 diff --git a/Core/LineToIndex.cs b/Core/LineToIndex.cs index 484d9d2..605bc02 100644 --- a/Core/LineToIndex.cs +++ b/Core/LineToIndex.cs @@ -9,8 +9,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ using System; -using System.Text.RegularExpressions; -using System.Threading; +using System.Text; +using System.Globalization; using System.Linq; using System.Collections.Generic; using System.Diagnostics; @@ -412,12 +412,6 @@ namespace FooEditEngine return this.Lines[row].Index; } - internal LineToIndexTableData CreateLineToIndexTableData(int index, int length, bool lineend, SyntaxInfo[] syntax) - { - LineToIndexTableData result = new LineToIndexTableData(index, length, lineend,this.IsFrozneDirtyFlag == false, syntax); - return result; - } - internal void UpdateLineAsReplace(int row,int removedLength, int insertedLength) { int deltaLength = insertedLength - removedLength; @@ -447,7 +441,7 @@ namespace FooEditEngine //挿入範囲内のドキュメントから行を生成する SpilitStringEventArgs e = new SpilitStringEventArgs(this.Document, HeadIndex, analyzeLength, startRow); - IList newLines = SpilitString(this, e); + IList newLines = this.CreateLineList(e.index, e.length, Document.MaximumLineLength); //消すべき行が複数ある場合は消すが、そうでない場合は最適化のため長さを変えるだけにとどめておく int removeCount = endRow - startRow + 1; @@ -472,6 +466,56 @@ namespace FooEditEngine generator.Update(this.Document, index, insertedLength, removedLength); } + internal IEnumerable> ForEachLines(int startIndex, int endIndex, int maxCharCount = -1) + { + int currentLineHeadIndex = startIndex; + int currentLineLength = 0; + + for (int i = startIndex; i <= endIndex; i++) + { + currentLineLength++; + char c = this.Document[i]; + if (c == Document.NewLine || + (maxCharCount != -1 && currentLineLength >= maxCharCount)) + { + UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(c); + if (uc != UnicodeCategory.NonSpacingMark && + uc != UnicodeCategory.SpacingCombiningMark && + uc != UnicodeCategory.EnclosingMark && + uc != UnicodeCategory.Surrogate) + { + yield return new Tuple(currentLineHeadIndex, currentLineLength); + currentLineHeadIndex += currentLineLength; + currentLineLength = 0; + } + } + } + if (currentLineLength > 0) + yield return new Tuple(currentLineHeadIndex, currentLineLength); + } + + IList CreateLineList(int index, int length, int lineLimitLength = -1) + { + int startIndex = index; + int endIndex = index + length - 1; + List output = new List(); + + foreach (Tuple range in this.ForEachLines(startIndex, endIndex, lineLimitLength)) + { + int lineHeadIndex = range.Item1; + int lineLength = range.Item2; + char c = this.Document[lineHeadIndex + lineLength - 1]; + bool hasNewLine = c == Document.NewLine; + LineToIndexTableData result = new LineToIndexTableData(lineHeadIndex, lineLength, hasNewLine, this.IsFrozneDirtyFlag == false, null); + output.Add(result); + } + + if (output.Count > 0) + output.Last().LineEnd = true; + + return output; + } + void GetRemoveRange(int index,int length,out int startRow,out int endRow) { startRow = this.GetLineNumberFromIndex(index); diff --git a/Core/StringBuffer.cs b/Core/StringBuffer.cs index 58953ef..d96cc5e 100644 --- a/Core/StringBuffer.cs +++ b/Core/StringBuffer.cs @@ -76,49 +76,6 @@ namespace FooEditEngine return temp.ToString(); } - public IEnumerable GetLines(int startIndex, int endIndex, int maxCharCount = -1) - { - foreach (Tuple range in this.ForEachLines(startIndex, endIndex, maxCharCount)) - { - StringBuilder temp = new StringBuilder(); - temp.Clear(); - int lineEndIndex = range.Item1; - if (range.Item2 > 0) - lineEndIndex += range.Item2 - 1; - for (int i = range.Item1; i <= lineEndIndex; i++) - temp.Append(buf[i]); - yield return temp.ToString(); - } - } - - public IEnumerable> ForEachLines(int startIndex, int endIndex, int maxCharCount = -1) - { - int currentLineHeadIndex = startIndex; - int currentLineLength = 0; - - for (int i = startIndex; i <= endIndex; i++) - { - currentLineLength++; - char c = this.buf[i]; - if (c == Document.NewLine || - (maxCharCount != -1 && currentLineLength >= maxCharCount)) - { - UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(c); - if (uc != UnicodeCategory.NonSpacingMark && - uc != UnicodeCategory.SpacingCombiningMark && - uc != UnicodeCategory.EnclosingMark && - uc != UnicodeCategory.Surrogate) - { - yield return new Tuple(currentLineHeadIndex, currentLineLength); - currentLineHeadIndex += currentLineLength; - currentLineLength = 0; - } - } - } - if (currentLineLength > 0) - yield return new Tuple(currentLineHeadIndex, currentLineLength); - } - public int Length { get { return this.buf.Count; } diff --git a/Core/ViewBase.cs b/Core/ViewBase.cs index 846e60c..bd90b0e 100644 --- a/Core/ViewBase.cs +++ b/Core/ViewBase.cs @@ -87,7 +87,6 @@ namespace FooEditEngine this._Padding = padding; this.render = r; this.Document = doc; - this._LayoutLines.SpilitString = new SpilitStringEventHandler(LayoutLines_SpilitStringByChar); this.render.ChangedRenderResource += new ChangedRenderResourceEventHandler(render_ChangedRenderResource); this.render.ChangedRightToLeft += render_ChangedRightToLeft; this.SrcChanged += new EventHandler((s, e) => { }); @@ -453,10 +452,5 @@ namespace FooEditEngine break; } } - - IList LayoutLines_SpilitStringByChar(object sender, SpilitStringEventArgs e) - { - return this.Document.CreateLineList(e.index, e.length, Document.MaximumLineLength); - } } } diff --git a/WPF/FooEditEngine/WPF/WPFRender.cs b/WPF/FooEditEngine/WPF/WPFRender.cs index f0deeaf..18241c2 100644 --- a/WPF/FooEditEngine/WPF/WPFRender.cs +++ b/WPF/FooEditEngine/WPF/WPFRender.cs @@ -497,45 +497,6 @@ namespace FooEditEngine.WPF this.Context.Pop(); } - public List BreakLine(Document doc, LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth) - { - List output = new List(); - - foreach (string str in doc.GetLines(startIndex, endIndex)) - { - TextLayout layout = new TextLayout(str, this.FontFamily, this.FontSize, this.Brushes[this.Foreground], wrapwidth); - - int i = startIndex; - foreach (TextLine line in layout.Lines) - { - if (line.Length == 0 && line.NewlineLength == 0) - continue; - - int length = line.Length; - - IList> runs = line.GetTextRunSpans(); - if (runs.Last().Value is TextEndOfParagraph) - length--; - - bool lineend = false; - if (line.NewlineLength > 0) - lineend = true; - - output.Add(layoutLineCollection.CreateLineToIndexTableData(i, length, lineend, null)); - i += line.Length; - } - - layout.Dispose(); - - startIndex += str.Length; - } - - if (output.Count > 0) - output.Last().LineEnd = true; - - return output; - } - public ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable MarkerRanges, IEnumerable SelectRanges, double wrapwidth) { TextLayout layout; diff --git a/WPF/UnitTest/DummyRender.cs b/WPF/UnitTest/DummyRender.cs index abe65d6..114e894 100644 --- a/WPF/UnitTest/DummyRender.cs +++ b/WPF/UnitTest/DummyRender.cs @@ -125,11 +125,6 @@ namespace UnitTest throw new NotImplementedException(); } - public List BreakLine(Document doc,LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth) - { - throw new NotImplementedException(); - } - public void DrawGripper(Point p, double radius) { throw new NotImplementedException(); diff --git a/Windows/FooEditEngine/FooEditEngine.csproj b/Windows/FooEditEngine/FooEditEngine.csproj index 2aa7c4a..9bf50d9 100644 --- a/Windows/FooEditEngine/FooEditEngine.csproj +++ b/Windows/FooEditEngine/FooEditEngine.csproj @@ -55,7 +55,7 @@ - 5.0.0 + 5.1.0 4.0.1 diff --git a/Windows/FooEditEngine/PrintableTextRender.cs b/Windows/FooEditEngine/PrintableTextRender.cs index 72281c1..d4c666d 100644 --- a/Windows/FooEditEngine/PrintableTextRender.cs +++ b/Windows/FooEditEngine/PrintableTextRender.cs @@ -254,43 +254,6 @@ namespace FooEditEngine.Windows { } - public List BreakLine(Document doc, LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double maxwidth) - { - List output = new List(); - - foreach (string str in doc.GetLines(startIndex, endIndex)) - { - LineToIndexTableData info; - - if (str.Length == 0) - { - info = layoutLineCollection.CreateLineToIndexTableData(startIndex, 0, true, null); - output.Add(info); - return output; - } - - int fitlen, index = 0, x = 0, width; - do - { - int linesFilled; - SizeF metrics = g.MeasureString(str.Substring(index), this.font, new SizeF((float)maxwidth, this.font.Height + 1), this.sf, out fitlen, out linesFilled); - - x += width = (int)metrics.Width; - - info = layoutLineCollection.CreateLineToIndexTableData(index + startIndex, fitlen, false, null); - output.Add(info); - - index += fitlen; - } while (index < str.Length); - - output[output.Count - 1].LineEnd = true; - - startIndex += str.Length; - } - - return output; - } - public void DrawGripper(Point p, double radius) { //タッチには対応していないので実装する必要はない