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()
{
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;
}
}
- /// <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);
/// <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>
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>
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;
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;
//挿入範囲内のドキュメントから行を生成する
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;
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);
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; }
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) => { });
break;
}
}
-
- IList<LineToIndexTableData> LayoutLines_SpilitStringByChar(object sender, SpilitStringEventArgs e)
- {
- return this.Document.CreateLineList(e.index, e.length, Document.MaximumLineLength);
- }
}
}
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;
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();
</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>
{
}
- 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)
{
//タッチには対応していないので実装する必要はない