本文整理汇总了C#中Mono.TextEditor.DocumentLine.GetLogicalColumn方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentLine.GetLogicalColumn方法的具体用法?C# DocumentLine.GetLogicalColumn怎么用?C# DocumentLine.GetLogicalColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.DocumentLine
的用法示例。
在下文中一共展示了DocumentLine.GetLogicalColumn方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawLinePortion
int DrawLinePortion(Context cr, ChunkStyle style, TextLayout layout, DocumentLine line, int visualOffset, int logicalLength)
{
int logicalColumn = line.GetLogicalColumn(editor, visualOffset);
int logicalEndColumn = logicalColumn + logicalLength;
int visualEndOffset = line.GetVisualColumn(editor, logicalEndColumn);
int visualLength = visualEndOffset - visualOffset;
int indexOffset = visualOffset - 1;
layout.SetFontStyle(style.FontStyle, indexOffset, visualLength);
layout.SetFontWeight(style.FontWeight, indexOffset, visualLength);
if (style.Underline)
layout.SetUnderline(indexOffset, visualLength);
layout.SetForeground(style.Foreground, indexOffset, visualLength);
return visualEndOffset;
}
示例2: CreateLinePartLayout
public LayoutWrapper CreateLinePartLayout (ISyntaxMode mode, DocumentLine line, int logicalRulerColumn, int offset, int length, int selectionStart, int selectionEnd)
{
bool containsPreedit = textEditor.ContainsPreedit (offset, length);
LayoutDescriptor descriptor;
if (!containsPreedit && layoutDict.TryGetValue (line, out descriptor)) {
bool isInvalid;
if (descriptor.Equals (line, offset, length, selectionStart, selectionEnd, out isInvalid) && descriptor.Layout != null) {
return descriptor.Layout;
}
descriptor.Dispose ();
layoutDict.Remove (line);
}
var wrapper = new LayoutWrapper (PangoUtil.CreateLayout (textEditor));
wrapper.IsUncached = containsPreedit;
if (logicalRulerColumn < 0)
logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn);
var atts = new FastPangoAttrList ();
wrapper.Layout.Alignment = Pango.Alignment.Left;
wrapper.Layout.FontDescription = textEditor.Options.Font;
wrapper.Layout.Tabs = tabArray;
if (textEditor.Options.WrapLines) {
wrapper.Layout.Wrap = Pango.WrapMode.WordChar;
wrapper.Layout.Width = (int)((textEditor.Allocation.Width - XOffset - TextStartPosition) * Pango.Scale.PangoScale);
}
StringBuilder textBuilder = new StringBuilder ();
var chunks = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, offset, length);
wrapper.Chunks = chunks;
foreach (var chunk in chunks) {
try {
textBuilder.Append (Document.GetTextAt (chunk));
} catch {
Console.WriteLine (chunk);
}
}
int lineOffset = line.Offset;
string lineText = textBuilder.ToString ();
uint preeditLength = 0;
if (containsPreedit) {
if (textEditor.GetTextEditorData ().IsCaretInVirtualLocation) {
lineText = textEditor.GetTextEditorData ().GetIndentationString (textEditor.Caret.Location) + textEditor.preeditString;
} else {
lineText = lineText.Insert (textEditor.preeditOffset - offset, textEditor.preeditString);
}
preeditLength = (uint)textEditor.preeditString.Length;
}
char[] lineChars = lineText.ToCharArray ();
//int startOffset = offset, endOffset = offset + length;
uint curIndex = 0, byteIndex = 0;
uint curChunkIndex = 0, byteChunkIndex = 0;
uint oldEndIndex = 0;
foreach (Chunk chunk in chunks) {
ChunkStyle chunkStyle = chunk != null ? textEditor.ColorStyle.GetChunkStyle (chunk) : null;
foreach (TextLineMarker marker in line.Markers)
chunkStyle = marker.GetStyle (chunkStyle);
if (chunkStyle != null) {
//startOffset = chunk.Offset;
//endOffset = chunk.EndOffset;
uint startIndex = (uint)(oldEndIndex);
uint endIndex = (uint)(startIndex + chunk.Length);
oldEndIndex = endIndex;
var markers = Document.GetTextSegmentMarkersAt (line).Where (m => m.IsVisible).ToArray ();
HandleSelection (lineOffset, logicalRulerColumn, selectionStart, selectionEnd, chunk.Offset, chunk.EndOffset, delegate(int start, int end) {
if (containsPreedit) {
if (textEditor.preeditOffset < start)
start += (int)preeditLength;
if (textEditor.preeditOffset < end)
end += (int)preeditLength;
}
var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
var color = ColorStyle.GetForeground (chunkStyle);
foreach (var marker in markers) {
var chunkMarker = marker as IChunkMarker;
if (chunkMarker == null)
continue;
chunkMarker.ChangeForeColor (textEditor, chunk, ref color);
}
atts.AddForegroundAttribute ((HslColor)color, si, ei);
if (!chunkStyle.TransparentBackground && GetPixel (ColorStyle.PlainText.Background) != GetPixel (chunkStyle.Background)) {
wrapper.AddBackground (chunkStyle.Background, (int)si, (int)ei);
} else if (chunk.SpanStack != null && ColorStyle != null) {
foreach (var span in chunk.SpanStack) {
if (span == null || string.IsNullOrEmpty (span.Color))
continue;
var spanStyle = ColorStyle.GetChunkStyle (span.Color);
if (spanStyle != null && !spanStyle.TransparentBackground && GetPixel (ColorStyle.PlainText.Background) != GetPixel (spanStyle.Background)) {
wrapper.AddBackground (spanStyle.Background, (int)si, (int)ei);
break;
}
}
}
}, delegate(int start, int end) {
if (containsPreedit) {
if (textEditor.preeditOffset < start)
start += (int)preeditLength;
//.........这里部分代码省略.........
示例3: GetSelectionOffsets
void GetSelectionOffsets (DocumentLine line, out int selectionStart, out int selectionEnd)
{
selectionStart = -1;
selectionEnd = -1;
if (textEditor.IsSomethingSelected) {
TextSegment segment = textEditor.SelectionRange;
selectionStart = segment.Offset;
selectionEnd = segment.EndOffset;
if (textEditor.SelectionMode == SelectionMode.Block) {
DocumentLocation start = textEditor.MainSelection.Anchor;
DocumentLocation end = textEditor.MainSelection.Lead;
DocumentLocation visStart = textEditor.LogicalToVisualLocation (start);
DocumentLocation visEnd = textEditor.LogicalToVisualLocation (end);
int lineOffset = line.Offset;
int lineNumber = line.LineNumber;
if (textEditor.MainSelection.MinLine <= lineNumber && lineNumber <= textEditor.MainSelection.MaxLine) {
selectionStart = lineOffset + line.GetLogicalColumn (this.textEditor.GetTextEditorData (), System.Math.Min (visStart.Column, visEnd.Column)) - 1;
selectionEnd = lineOffset + line.GetLogicalColumn (this.textEditor.GetTextEditorData (), System.Math.Max (visStart.Column, visEnd.Column)) - 1;
}
}
}
}
示例4: ColumnToX
public double ColumnToX (DocumentLine line, int column)
{
column--;
// calculate virtual indentation
if (column > 0 && line.Length == 0 && textEditor.GetTextEditorData ().HasIndentationTracker) {
using (var l = PangoUtil.CreateLayout (textEditor, textEditor.GetTextEditorData ().IndentationTracker.GetIndentationString (line.Offset))) {
l.Alignment = Pango.Alignment.Left;
l.FontDescription = textEditor.Options.Font;
l.Tabs = tabArray;
Pango.Rectangle ink_rect, logical_rect;
l.GetExtents (out ink_rect, out logical_rect);
return (logical_rect.Width + Pango.Scale.PangoScale - 1) / Pango.Scale.PangoScale;
}
}
if (line == null || line.Length == 0 || column < 0)
return 0;
int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn);
int lineOffset = line.Offset;
StringBuilder textBuilder = new StringBuilder ();
ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document);
var startChunk = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, lineOffset, line.Length);
foreach (Chunk chunk in startChunk) {
try {
textBuilder.Append (Document.GetTextAt (chunk));
} catch (Exception e) {
Console.WriteLine (e);
return 0;
}
}
string lineText = textBuilder.ToString ();
char[] lineChars = lineText.ToCharArray ();
bool containsPreedit = textEditor.ContainsPreedit (lineOffset, line.Length);
uint preeditLength = 0;
if (containsPreedit) {
lineText = lineText.Insert (textEditor.preeditOffset - lineOffset, textEditor.preeditString);
preeditLength = (uint)textEditor.preeditString.Length;
}
if (column < lineText.Length)
lineText = lineText.Substring (0, column);
var layout = PangoUtil.CreateLayout (textEditor, lineText);
layout.Alignment = Pango.Alignment.Left;
layout.FontDescription = textEditor.Options.Font;
layout.Tabs = tabArray;
int startOffset = lineOffset, endOffset = lineOffset + line.Length;
uint curIndex = 0, byteIndex = 0;
uint curChunkIndex = 0, byteChunkIndex = 0;
List<Pango.Attribute> attributes = new List<Pango.Attribute> ();
uint oldEndIndex = 0;
Cairo.Color curFgColor = textEditor.ColorStyle.PlainText.Foreground;
Cairo.Color curBgColor = textEditor.ColorStyle.PlainText.Background;
var curWeight = Xwt.Drawing.FontWeight.Normal;
var curStyle = Xwt.Drawing.FontStyle.Normal;
foreach (Chunk chunk in startChunk) {
ChunkStyle chunkStyle = chunk != null ? textEditor.ColorStyle.GetChunkStyle (chunk) : null;
foreach (TextLineMarker marker in line.Markers)
chunkStyle = marker.GetStyle (chunkStyle);
if (chunkStyle != null) {
startOffset = chunk.Offset;
endOffset = chunk.EndOffset;
uint startIndex = (uint)(oldEndIndex);
uint endIndex = (uint)(startIndex + chunk.Length);
oldEndIndex = endIndex;
if (containsPreedit) {
if (textEditor.preeditOffset < startOffset)
startIndex += preeditLength;
if (textEditor.preeditOffset < endOffset)
endIndex += preeditLength;
}
HandleSelection (lineOffset, logicalRulerColumn, - 1, -1, chunk.Offset, chunk.EndOffset, delegate(int start, int end) {
var color = textEditor.ColorStyle.GetForeground (chunkStyle);
var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
if (!color.Equals (curFgColor)) {
curFgColor = color;
var foreGround = new Pango.AttrForeground (
(ushort)(color.R * ushort.MaxValue),
(ushort)(color.G * ushort.MaxValue),
(ushort)(color.B * ushort.MaxValue));
foreGround.StartIndex = si;
foreGround.EndIndex = ei;
attributes.Add (foreGround);
}
if (!chunkStyle.TransparentBackground) {
color = chunkStyle.Background;
if (!color.Equals (curBgColor)) {
var background = new Pango.AttrBackground (
(ushort)(color.R * ushort.MaxValue),
(ushort)(color.G * ushort.MaxValue),
//.........这里部分代码省略.........
示例5: PointToLocation
public DocumentLocation PointToLocation (double xp, double yp, bool endAtEol = false)
{
lineNumber = System.Math.Min (margin.YToLine (yp + margin.textEditor.VAdjustment.Value), margin.Document.LineCount);
line = lineNumber <= margin.Document.LineCount ? margin.Document.GetLine (lineNumber) : null;
if (line == null)
return DocumentLocation.Empty;
int offset = line.Offset;
xp -= margin.TextStartPosition;
xp += margin.textEditor.HAdjustment.Value;
xp *= Pango.Scale.PangoScale;
if (xp < 0)
return new DocumentLocation (lineNumber, DocumentLocation.MinColumn);
int column = DocumentLocation.MinColumn;
ISyntaxMode mode = margin.Document.SyntaxMode != null && margin.textEditor.Options.EnableSyntaxHighlighting ? margin.Document.SyntaxMode : new SyntaxMode (margin.Document);
IEnumerable<FoldSegment> foldings = margin.Document.GetStartFoldings (line);
bool done = false;
Pango.Layout measueLayout = null;
try {
restart:
int logicalRulerColumn = line.GetLogicalColumn (margin.textEditor.GetTextEditorData (), margin.textEditor.Options.RulerColumn);
foreach (FoldSegment folding in foldings.Where(f => f.IsFolded)) {
int foldOffset = folding.StartLine.Offset + folding.Column - 1;
if (foldOffset < offset)
continue;
layoutWrapper = margin.CreateLinePartLayout (mode, line, logicalRulerColumn, line.Offset, foldOffset - offset, -1, -1);
done |= ConsumeLayout ((int)(xp - xPos), 0);
if (done)
break;
int height, width;
layoutWrapper.Layout.GetPixelSize (out width, out height);
xPos += width * (int)Pango.Scale.PangoScale;
if (measueLayout == null) {
measueLayout = PangoUtil.CreateLayout (margin.textEditor, folding.Description);
measueLayout.FontDescription = margin.textEditor.Options.Font;
}
int delta;
measueLayout.GetPixelSize (out delta, out height);
delta *= (int)Pango.Scale.PangoScale;
xPos += delta;
if (xPos - delta / 2 >= xp) {
index = foldOffset - offset;
done = true;
break;
}
offset = folding.EndLine.Offset + folding.EndColumn - 1;
DocumentLocation foldingEndLocation = margin.Document.OffsetToLocation (offset);
lineNumber = foldingEndLocation.Line;
column = foldingEndLocation.Column;
if (xPos >= xp) {
index = 0;
done = true;
break;
}
if (folding.EndLine != line) {
line = folding.EndLine;
foldings = margin.Document.GetStartFoldings (line);
goto restart;
}
}
if (!done) {
layoutWrapper = margin.CreateLinePartLayout (mode, line, logicalRulerColumn, offset, line.Offset + line.Length - offset, -1, -1);
if (!ConsumeLayout ((int)(xp - xPos), 0)) {
if (endAtEol)
return DocumentLocation.Empty;
}
}
} finally {
if (measueLayout != null)
measueLayout.Dispose ();
}
return new DocumentLocation (lineNumber, column + index);
}
示例6: Draw
protected internal override void Draw (Cairo.Context cr, Cairo.Rectangle area, DocumentLine line, int lineNr, double x, double y, double _lineHeight)
{
// double xStart = System.Math.Max (area.X, XOffset);
// xStart = System.Math.Max (0, xStart);
var correctedXOffset = System.Math.Floor (XOffset) - 1;
var lineArea = new Cairo.Rectangle (correctedXOffset, y, textEditor.Allocation.Width - correctedXOffset, _lineHeight);
int width, height;
double pangoPosition = (x - textEditor.HAdjustment.Value + TextStartPosition) * Pango.Scale.PangoScale;
defaultBgColor = Document.ReadOnly ? ColorStyle.BackgroundReadOnly.Color : ColorStyle.PlainText.Background;
// Draw the default back color for the whole line. Colors other than the default
// background will be drawn when rendering the text chunks.
if (BackgroundRenderer == null)
DrawRectangleWithRuler (cr, x, lineArea, defaultBgColor, true);
bool isSelectionDrawn = false;
// Check if line is beyond the document length
if (line == null) {
var marker = Document.GetExtendingTextMarker (lineNr);
if (marker != null)
marker.Draw (textEditor, cr, lineNr, lineArea);
return;
}
IEnumerable<FoldSegment> foldings = Document.GetStartFoldings (line);
int offset = line.Offset;
int caretOffset = Caret.Offset;
bool isEolFolded = false;
restart:
int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn);
if ((HighlightCaretLine || textEditor.Options.HighlightCaretLine) && Caret.Line == lineNr)
DrawCaretLineMarker (cr, x, y, TextStartPosition, _lineHeight);
foreach (FoldSegment folding in foldings) {
int foldOffset = folding.StartLine.Offset + folding.Column - 1;
if (foldOffset < offset)
continue;
if (folding.IsFolded) {
DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, foldOffset - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width, _lineHeight);
offset = folding.EndLine.Offset + folding.EndColumn - 1;
markerLayout.SetText (folding.Description);
markerLayout.GetSize (out width, out height);
bool isFoldingSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (folding.Segment);
double pixelX = 0.5 + System.Math.Floor (pangoPosition / Pango.Scale.PangoScale);
double foldXMargin = foldMarkerXMargin * textEditor.Options.Zoom;
double pixelWidth = System.Math.Floor ((pangoPosition + width) / Pango.Scale.PangoScale - pixelX + foldXMargin * 2);
var foldingRectangle = new Cairo.Rectangle (
pixelX,
y,
pixelWidth,
this.LineHeight);
if (BackgroundRenderer == null && isFoldingSelected) {
cr.Color = SelectionColor.Background;
cr.Rectangle (foldingRectangle);
cr.Fill ();
}
if (isFoldingSelected && SelectionColor.TransparentForeground) {
cr.Color = ColorStyle.CollapsedText.Foreground;
} else {
cr.Color = isFoldingSelected ? SelectionColor.Foreground : ColorStyle.CollapsedText.Foreground;
}
var boundingRectangleHeight = foldingRectangle.Height - 1;
var boundingRectangleY = System.Math.Floor (foldingRectangle.Y + (foldingRectangle.Height - boundingRectangleHeight) / 2);
RoundedRectangle (cr,
System.Math.Floor (foldingRectangle.X) + 0.5,
boundingRectangleY + 0.5,
System.Math.Floor (foldingRectangle.Width - cr.LineWidth),
System.Math.Floor (boundingRectangleHeight - cr.LineWidth),
LineHeight / 8, CairoCorners.All, false);
cr.Stroke ();
cr.Save ();
cr.Translate (
pangoPosition / Pango.Scale.PangoScale + foldXMargin,
System.Math.Floor (boundingRectangleY + (boundingRectangleHeight - System.Math.Floor (height / Pango.Scale.PangoScale)) / 2));
cr.ShowLayout (markerLayout);
cr.Restore ();
if (caretOffset == foldOffset && !string.IsNullOrEmpty (folding.Description)) {
var cx = (int)(pangoPosition / Pango.Scale.PangoScale);
SetVisibleCaretPosition (cx, y, cx, y);
}
pangoPosition += foldingRectangle.Width * Pango.Scale.PangoScale;
if (caretOffset == foldOffset + folding.Length && !string.IsNullOrEmpty (folding.Description)) {
var cx = (int)(pangoPosition / Pango.Scale.PangoScale);
SetVisibleCaretPosition (cx, y, cx, y);
}
if (folding.EndLine != line) {
line = folding.EndLine;
lineNr = line.LineNumber;
foldings = Document.GetStartFoldings (line);
//.........这里部分代码省略.........
示例7: CreateLinePartLayout
public LayoutWrapper CreateLinePartLayout (ISyntaxMode mode, DocumentLine line, int logicalRulerColumn, int offset, int length, int selectionStart, int selectionEnd)
{
bool containsPreedit = textEditor.ContainsPreedit (offset, length);
LayoutDescriptor descriptor;
if (!containsPreedit && layoutDict.TryGetValue (line, out descriptor)) {
bool isInvalid;
if (descriptor.Equals (line, offset, length, selectionStart, selectionEnd, out isInvalid) && descriptor.Layout != null) {
return descriptor.Layout;
}
descriptor.Dispose ();
layoutDict.Remove (line);
}
var wrapper = new LayoutWrapper (PangoUtil.CreateLayout (textEditor));
wrapper.IsUncached = containsPreedit;
if (logicalRulerColumn < 0)
logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn);
var atts = new FastPangoAttrList ();
wrapper.Layout.Alignment = Pango.Alignment.Left;
wrapper.Layout.FontDescription = textEditor.Options.Font;
wrapper.Layout.Tabs = tabArray;
StringBuilder textBuilder = new StringBuilder ();
var chunks = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, offset, length);
foreach (var chunk in chunks) {
try {
textBuilder.Append (Document.GetTextAt (chunk));
} catch {
Console.WriteLine (chunk);
}
}
int lineOffset = line.Offset;
string lineText = textBuilder.ToString ();
uint preeditLength = 0;
if (containsPreedit) {
lineText = lineText.Insert (textEditor.preeditOffset - offset, textEditor.preeditString);
preeditLength = (uint)textEditor.preeditString.Length;
}
char[] lineChars = lineText.ToCharArray ();
//int startOffset = offset, endOffset = offset + length;
uint curIndex = 0, byteIndex = 0;
uint curChunkIndex = 0, byteChunkIndex = 0;
uint oldEndIndex = 0;
foreach (Chunk chunk in chunks) {
ChunkStyle chunkStyle = chunk != null ? textEditor.ColorStyle.GetChunkStyle (chunk) : null;
foreach (TextMarker marker in line.Markers)
chunkStyle = marker.GetStyle (chunkStyle);
if (chunkStyle != null) {
//startOffset = chunk.Offset;
//endOffset = chunk.EndOffset;
uint startIndex = (uint)(oldEndIndex);
uint endIndex = (uint)(startIndex + chunk.Length);
oldEndIndex = endIndex;
HandleSelection (lineOffset, logicalRulerColumn, selectionStart, selectionEnd, chunk.Offset, chunk.EndOffset, delegate(int start, int end) {
if (containsPreedit) {
if (textEditor.preeditOffset < start)
start += (int)preeditLength;
if (textEditor.preeditOffset < end)
end += (int)preeditLength;
}
var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
atts.AddForegroundAttribute (chunkStyle.Color, si, ei);
if (!chunkStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (chunkStyle.BackgroundColor)) {
wrapper.AddBackground (chunkStyle.CairoBackgroundColor, (int)si, (int)ei);
} else if (chunk.SpanStack != null && ColorStyle != null) {
foreach (var span in chunk.SpanStack) {
if (span == null)
continue;
var spanStyle = ColorStyle.GetChunkStyle (span.Color);
if (!spanStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (spanStyle.BackgroundColor)) {
wrapper.AddBackground (spanStyle.CairoBackgroundColor, (int)si, (int)ei);
break;
}
}
}
}, delegate(int start, int end) {
if (containsPreedit) {
if (textEditor.preeditOffset < start)
start += (int)preeditLength;
if (textEditor.preeditOffset < end)
end += (int)preeditLength;
}
var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
atts.AddForegroundAttribute (SelectionColor.Color, si, ei);
if (!wrapper.StartSet)
wrapper.SelectionStartIndex = (int)si;
wrapper.SelectionEndIndex = (int)ei;
});
var translatedStartIndex = TranslateToUTF8Index (lineChars, (uint)startIndex, ref curChunkIndex, ref byteChunkIndex);
var translatedEndIndex = TranslateToUTF8Index (lineChars, (uint)endIndex, ref curChunkIndex, ref byteChunkIndex);
if (chunkStyle.Bold)
//.........这里部分代码省略.........
示例8: ColumnToX
public double ColumnToX (DocumentLine line, int column)
{
column--;
if (line == null || line.Length == 0 || column < 0)
return 0;
int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn);
int lineOffset = line.Offset;
StringBuilder textBuilder = new StringBuilder ();
ISyntaxMode mode = Document.SyntaxMode != null && textEditor.Options.EnableSyntaxHighlighting ? Document.SyntaxMode : new SyntaxMode (Document);
var startChunk = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, lineOffset, line.Length);
foreach (Chunk chunk in startChunk) {
try {
textBuilder.Append (Document.GetTextAt (chunk));
} catch (Exception e) {
Console.WriteLine (e);
return 0;
}
}
string lineText = textBuilder.ToString ();
char[] lineChars = lineText.ToCharArray ();
bool containsPreedit = textEditor.ContainsPreedit (lineOffset, line.Length);
uint preeditLength = 0;
if (containsPreedit) {
lineText = lineText.Insert (textEditor.preeditOffset - lineOffset, textEditor.preeditString);
preeditLength = (uint)textEditor.preeditString.Length;
}
if (column < lineText.Length)
lineText = lineText.Substring (0, column);
var layout = PangoUtil.CreateLayout (textEditor, lineText);
layout.Alignment = Pango.Alignment.Left;
layout.FontDescription = textEditor.Options.Font;
layout.Tabs = tabArray;
int startOffset = lineOffset, endOffset = lineOffset + line.Length;
uint curIndex = 0, byteIndex = 0;
uint curChunkIndex = 0, byteChunkIndex = 0;
List<Pango.Attribute> attributes = new List<Pango.Attribute> ();
uint oldEndIndex = 0;
foreach (Chunk chunk in startChunk) {
ChunkStyle chunkStyle = chunk != null ? textEditor.ColorStyle.GetChunkStyle (chunk) : null;
foreach (TextMarker marker in line.Markers)
chunkStyle = marker.GetStyle (chunkStyle);
if (chunkStyle != null) {
startOffset = chunk.Offset;
endOffset = chunk.EndOffset;
uint startIndex = (uint)(oldEndIndex);
uint endIndex = (uint)(startIndex + chunk.Length);
oldEndIndex = endIndex;
if (containsPreedit) {
if (textEditor.preeditOffset < startOffset)
startIndex += preeditLength;
if (textEditor.preeditOffset < endOffset)
endIndex += preeditLength;
}
HandleSelection (lineOffset, logicalRulerColumn, - 1, -1, chunk.Offset, chunk.EndOffset, delegate(int start, int end) {
Pango.AttrForeground foreGround = new Pango.AttrForeground (chunkStyle.Color.Red, chunkStyle.Color.Green, chunkStyle.Color.Blue);
foreGround.StartIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
foreGround.EndIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
attributes.Add (foreGround);
if (!chunkStyle.TransparentBackround) {
var background = new Pango.AttrBackground (chunkStyle.BackgroundColor.Red, chunkStyle.BackgroundColor.Green, chunkStyle.BackgroundColor.Blue);
background.StartIndex = foreGround.StartIndex;
background.EndIndex = foreGround.EndIndex;
attributes.Add (background);
}
}, delegate(int start, int end) {
Pango.AttrForeground selectedForeground = new Pango.AttrForeground (SelectionColor.Color.Red, SelectionColor.Color.Green, SelectionColor.Color.Blue);
selectedForeground.StartIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex);
selectedForeground.EndIndex = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex);
attributes.Add (selectedForeground);
});
var translatedStartIndex = TranslateToUTF8Index (lineChars, (uint)startIndex, ref curChunkIndex, ref byteChunkIndex);
var translatedEndIndex = TranslateToUTF8Index (lineChars, (uint)endIndex, ref curChunkIndex, ref byteChunkIndex);
if (chunkStyle.Bold) {
Pango.AttrWeight attrWeight = new Pango.AttrWeight (Pango.Weight.Bold);
attrWeight.StartIndex = translatedStartIndex;
attrWeight.EndIndex = translatedEndIndex;
attributes.Add (attrWeight);
}
if (chunkStyle.Italic) {
Pango.AttrStyle attrStyle = new Pango.AttrStyle (Pango.Style.Italic);
attrStyle.StartIndex = translatedStartIndex;
attrStyle.EndIndex = translatedEndIndex;
attributes.Add (attrStyle);
}
if (chunkStyle.Underline) {
Pango.AttrUnderline attrUnderline = new Pango.AttrUnderline (Pango.Underline.Single);
attrUnderline.StartIndex = translatedStartIndex;
//.........这里部分代码省略.........
示例9: Draw
protected internal override void Draw (Cairo.Context cr, Cairo.Rectangle area, DocumentLine line, int lineNr, double x, double y, double _lineHeight)
{
// double xStart = System.Math.Max (area.X, XOffset);
// xStart = System.Math.Max (0, xStart);
var lineArea = new Cairo.Rectangle (XOffset - 1, y, textEditor.Allocation.Width - XOffset + 1, _lineHeight);
int width, height;
double pangoPosition = (x - textEditor.HAdjustment.Value + TextStartPosition) * Pango.Scale.PangoScale;
defaultBgColor = Document.ReadOnly ? ColorStyle.ReadOnlyTextBg : ColorStyle.Default.CairoBackgroundColor;
// Draw the default back color for the whole line. Colors other than the default
// background will be drawn when rendering the text chunks.
DrawRectangleWithRuler (cr, x, lineArea, defaultBgColor, true);
bool isSelectionDrawn = false;
if (BackgroundRenderer != null)
BackgroundRenderer.Draw (cr, area, line, x, y, _lineHeight);
// Check if line is beyond the document length
if (line == null) {
if (textEditor.Options.ShowInvalidLines)
DrawInvalidLineMarker (cr, pangoPosition / Pango.Scale.PangoScale, y);
var marker = Document.GetExtendingTextMarker (lineNr);
if (marker != null)
marker.Draw (textEditor, cr, lineNr, lineArea);
return;
}
IEnumerable<FoldSegment> foldings = Document.GetStartFoldings (line);
int offset = line.Offset;
int caretOffset = Caret.Offset;
bool isEolFolded = false;
restart:
int logicalRulerColumn = line.GetLogicalColumn (textEditor.GetTextEditorData (), textEditor.Options.RulerColumn);
foreach (FoldSegment folding in foldings) {
int foldOffset = folding.StartLine.Offset + folding.Column - 1;
if (foldOffset < offset)
continue;
if (folding.IsFolded) {
DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, foldOffset - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width);
offset = folding.EndLine.Offset + folding.EndColumn;
markerLayout.SetText (folding.Description);
markerLayout.GetSize (out width, out height);
bool isFoldingSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (folding.Segment);
double pixelX = pangoPosition / Pango.Scale.PangoScale;
double pixelWidth = (pangoPosition + width) / Pango.Scale.PangoScale - pixelX;
var foldingRectangle = new Cairo.Rectangle (pixelX + 0.5, y + 0.5, pixelWidth - cr.LineWidth, this.LineHeight - cr.LineWidth);
if (BackgroundRenderer == null) {
cr.Color = isFoldingSelected ? SelectionColor.CairoBackgroundColor : defaultBgColor;
cr.Rectangle (foldingRectangle);
cr.Fill ();
}
cr.Color = isFoldingSelected ? SelectionColor.CairoColor : ColorStyle.FoldLine.CairoColor;
cr.Rectangle (foldingRectangle);
cr.Stroke ();
cr.Save ();
cr.Translate (pangoPosition / Pango.Scale.PangoScale, y);
cr.Color = isFoldingSelected ? SelectionColor.CairoColor : ColorStyle.FoldLine.CairoColor;
cr.ShowLayout (markerLayout);
cr.Restore ();
if (caretOffset == foldOffset && !string.IsNullOrEmpty (folding.Description))
SetVisibleCaretPosition ((int)(pangoPosition / Pango.Scale.PangoScale), y);
pangoPosition += width;
if (caretOffset == foldOffset + folding.Length && !string.IsNullOrEmpty (folding.Description))
SetVisibleCaretPosition ((int)(pangoPosition / Pango.Scale.PangoScale), y);
if (folding.EndLine != line) {
line = folding.EndLine;
lineNr = line.LineNumber;
foldings = Document.GetStartFoldings (line);
isEolFolded = line.Length <= folding.EndColumn;
goto restart;
}
isEolFolded = line.Length <= folding.EndColumn;
}
}
// Draw remaining line - must be called for empty line parts as well because the caret may be at this positon
// and the caret position is calculated in DrawLinePart.
if (line.EndOffsetIncludingDelimiter - offset >= 0)
DrawLinePart (cr, line, lineNr, logicalRulerColumn, offset, line.Offset + line.Length - offset, ref pangoPosition, ref isSelectionDrawn, y, area.X + area.Width);
bool isEolSelected = !this.HideSelection && textEditor.IsSomethingSelected && textEditor.SelectionMode == SelectionMode.Normal && textEditor.SelectionRange.Contains (line.Offset + line.Length);
lineArea = new Cairo.Rectangle (pangoPosition / Pango.Scale.PangoScale,
lineArea.Y,
textEditor.Allocation.Width - pangoPosition / Pango.Scale.PangoScale,
lineArea.Height);
if (textEditor.SelectionMode == SelectionMode.Block && textEditor.IsSomethingSelected && textEditor.SelectionRange.Contains (line.Offset + line.Length)) {
DocumentLocation start = textEditor.MainSelection.Anchor;
DocumentLocation end = textEditor.MainSelection.Lead;
//.........这里部分代码省略.........
示例10: XToColumn
public int XToColumn(DocumentLine line, double x)
{
int visualColumn = (int)(x / CharWidth) + 1;
return line.GetLogicalColumn(editor, visualColumn);
}