OSDN Git Service

行を生成するメソッドをLineToIndexTableに移動した
authortest <test@yahoo.co.jp>
Mon, 4 Jan 2021 11:47:24 +0000 (20:47 +0900)
committertest <test@yahoo.co.jp>
Mon, 4 Jan 2021 11:47:24 +0000 (20:47 +0900)
Core/Direct2D/D2DRenderCommon.cs
Core/Document.cs
Core/ITextRender.cs
Core/LineToIndex.cs
Core/StringBuffer.cs
Core/ViewBase.cs
WPF/FooEditEngine/WPF/WPFRender.cs
WPF/UnitTest/DummyRender.cs
Windows/FooEditEngine/FooEditEngine.csproj
Windows/FooEditEngine/PrintableTextRender.cs

index c0c9ba9..fda591c 100644 (file)
@@ -872,43 +872,6 @@ namespace FooEditEngine
             return newLayout;
        }
 
-        public List<LineToIndexTableData> BreakLine(Document doc, LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth)
-        {
-            List<LineToIndexTableData> output = new List<LineToIndexTableData>();
-
-            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()
         {
index 526bfec..67fcf1f 100644 (file)
@@ -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
             }
         }
 
-        /// <summary>
-        /// レイアウト行を返す
-        /// </summary>
-        /// <param name="index">開始インデックス</param>
-        /// <param name="length">長さ</param>
-        /// <param name="lineLimitLength">1行当たりの最大文字数。-1で無制限</param>
-        /// <returns>レイアウト行リスト</returns>
-        internal IList<LineToIndexTableData> CreateLineList(int index, int length, int lineLimitLength = -1)
-        {
-            int startIndex = index;
-            int endIndex = index + length - 1;
-            List<LineToIndexTableData> output = new List<LineToIndexTableData>();
-
-            foreach (Tuple<int, int> 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
         /// <returns>行イテレーターが返される</returns>
         public IEnumerable<string> GetLines(int startIndex, int endIndex, int maxCharCount = -1)
         {
-            return this.buffer.GetLines(startIndex, endIndex, maxCharCount);
-        }
-
-        internal IEnumerable<Tuple<int, int>> ForEachLines(int startIndex, int endIndex, int maxCharCount = -1)
-        {
-            return this.buffer.ForEachLines(startIndex, endIndex, maxCharCount);
+            foreach (Tuple<int, int> 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();
+            }
         }
 
-
         /// <summary>
         /// 文字列を追加する
         /// </summary>
index 06613d1..0153f1f 100644 (file)
@@ -622,17 +622,6 @@ namespace FooEditEngine
         void DrawOneLine(Document doc,LineToIndexTable lti, int row, double x, double y);
 
         /// <summary>
-        /// 行を折り返す
-        /// </summary>
-        /// <param name="doc">ドキュメント</param>
-        /// <param name="layoutLineCollection">レイアウトライン</param>
-        /// <param name="startIndex">開始インデックス</param>
-        /// <param name="endIndex">終了インデックス</param>
-        /// <param name="wrapwidth">折り返しの幅</param>
-        /// <returns>行のリスト</returns>
-        List<LineToIndexTableData> BreakLine(Document doc,LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth);
-
-        /// <summary>
         /// レイアウトを生成する
         /// </summary>
         /// <param name="str">文字列</param>
index 484d9d2..605bc02 100644 (file)
@@ -9,8 +9,8 @@
 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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<LineToIndexTableData> newLines = SpilitString(this, e);
+            IList<LineToIndexTableData> 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<Tuple<int, int>> 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<int, int>(currentLineHeadIndex, currentLineLength);
+                        currentLineHeadIndex += currentLineLength;
+                        currentLineLength = 0;
+                    }
+                }
+            }
+            if (currentLineLength > 0)
+                yield return new Tuple<int, int>(currentLineHeadIndex, currentLineLength);
+        }
+
+        IList<LineToIndexTableData> CreateLineList(int index, int length, int lineLimitLength = -1)
+        {
+            int startIndex = index;
+            int endIndex = index + length - 1;
+            List<LineToIndexTableData> output = new List<LineToIndexTableData>();
+
+            foreach (Tuple<int, int> 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);
index 58953ef..d96cc5e 100644 (file)
@@ -76,49 +76,6 @@ namespace FooEditEngine
             return temp.ToString();
         }
 
-        public IEnumerable<string> GetLines(int startIndex, int endIndex, int maxCharCount = -1)
-        {
-            foreach (Tuple<int, int> 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<Tuple<int, int>> 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<int, int>(currentLineHeadIndex, currentLineLength);
-                        currentLineHeadIndex += currentLineLength;
-                        currentLineLength = 0;
-                    }
-                }
-            }
-            if (currentLineLength > 0)
-                yield return new Tuple<int, int>(currentLineHeadIndex, currentLineLength);
-        }
-
         public int Length
         {
             get { return this.buf.Count; }
index 846e60c..bd90b0e 100644 (file)
@@ -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<LineToIndexTableData> LayoutLines_SpilitStringByChar(object sender, SpilitStringEventArgs e)
-        {
-            return this.Document.CreateLineList(e.index, e.length, Document.MaximumLineLength);
-        }
     }
 }
index f0deeaf..18241c2 100644 (file)
@@ -497,45 +497,6 @@ namespace FooEditEngine.WPF
             this.Context.Pop();
         }
 
-        public List<LineToIndexTableData> BreakLine(Document doc, LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth)
-        {
-            List<LineToIndexTableData> output = new List<LineToIndexTableData>();
-
-            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<TextSpan<TextRun>> 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<Marker> MarkerRanges, IEnumerable<Selection> SelectRanges, double wrapwidth)
         {
             TextLayout layout;
index abe65d6..114e894 100644 (file)
@@ -125,11 +125,6 @@ namespace UnitTest
             throw new NotImplementedException();
         }
 
-        public List<LineToIndexTableData> BreakLine(Document doc,LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth)
-        {
-            throw new NotImplementedException();
-        }
-
         public void DrawGripper(Point p, double radius)
         {
             throw new NotImplementedException();
index 2aa7c4a..9bf50d9 100644 (file)
@@ -55,7 +55,7 @@
   </ItemGroup>
   <ItemGroup>
     <PackageReference Include="Nito.AsyncEx">
-      <Version>5.0.0</Version>
+      <Version>5.1.0</Version>
     </PackageReference>
     <PackageReference Include="SharpDX.Direct2D1">
       <Version>4.0.1</Version>
index 72281c1..d4c666d 100644 (file)
@@ -254,43 +254,6 @@ namespace FooEditEngine.Windows
         {
         }
 
-        public List<LineToIndexTableData> BreakLine(Document doc, LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double maxwidth)
-        {
-            List<LineToIndexTableData> output = new List<LineToIndexTableData>();
-
-            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)
         {
             //タッチには対応していないので実装する必要はない