本文整理汇总了C#中TextSegment类的典型用法代码示例。如果您正苦于以下问题:C# TextSegment类的具体用法?C# TextSegment怎么用?C# TextSegment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextSegment类属于命名空间,在下文中一共展示了TextSegment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GenerateHtml
public static string GenerateHtml (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
{
var htmlText = new StringBuilder ();
htmlText.AppendLine (@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
htmlText.AppendLine ("<HTML>");
htmlText.AppendLine ("<HEAD>");
htmlText.AppendLine ("<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=utf-8\">");
htmlText.AppendLine ("<META NAME=\"GENERATOR\" CONTENT=\"Mono Text Editor\">");
htmlText.AppendLine ("</HEAD>");
htmlText.AppendLine ("<BODY>");
var selection = new TextSegment (0, doc.TextLength);
int startLineNumber = doc.OffsetToLineNumber (selection.Offset);
int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset);
htmlText.AppendLine ("<FONT face = '" + options.Font.Family + "'>");
bool first = true;
if (mode is SyntaxMode) {
SyntaxModeService.StartUpdate (doc, (SyntaxMode)mode, selection.Offset, selection.EndOffset);
SyntaxModeService.WaitUpdate (doc);
}
foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) {
if (!first) {
htmlText.AppendLine ("<BR>");
} else {
first = false;
}
if (mode == null) {
AppendHtmlText (htmlText, doc, options, System.Math.Max (selection.Offset, line.Offset), System.Math.Min (line.EndOffset, selection.EndOffset));
continue;
}
int curSpaces = 0;
foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) {
int start = System.Math.Max (selection.Offset, chunk.Offset);
int end = System.Math.Min (chunk.EndOffset, selection.EndOffset);
var chunkStyle = style.GetChunkStyle (chunk);
if (start < end) {
htmlText.Append ("<SPAN style='");
if (chunkStyle.FontWeight != Xwt.Drawing.FontWeight.Normal)
htmlText.Append ("font-weight:" + ((int)chunkStyle.FontWeight) + ";");
if (chunkStyle.FontStyle != Xwt.Drawing.FontStyle.Normal)
htmlText.Append ("font-style:" + chunkStyle.FontStyle.ToString ().ToLower () + ";");
htmlText.Append ("color:" + ((HslColor)chunkStyle.Foreground).ToPangoString () + ";");
htmlText.Append ("'>");
AppendHtmlText (htmlText, doc, options, start, end);
htmlText.Append ("</SPAN>");
}
}
}
htmlText.AppendLine ("</FONT>");
htmlText.AppendLine ("</BODY></HTML>");
if (Platform.IsWindows)
return GenerateCFHtml (htmlText.ToString ());
return htmlText.ToString ();
}
开发者ID:handless,项目名称:monodevelop,代码行数:60,代码来源:HtmlWriter.cs
示例2: RefreshMarkers
void RefreshMarkers()
{
TypeReferencesResult res=null;
try
{
var ParseCache = DResolverWrapper.CreateCacheList(Document);
res = TypeReferenceFinder.Scan(SyntaxTree, ParseCache);
RemoveMarkers(false);
var txtDoc = Document.Editor.Document;
DocumentLine curLine=null;
int ln=-1;
int len = 0;
foreach (var id in res.TypeMatches)
{
var loc = DeepASTVisitor.ExtractIdLocation(id, out len);
if(ln!=loc.Line)
curLine = Document.Editor.GetLine(ln = loc.Line);
var segment = new TextSegment(curLine.Offset,len);
var m = new UnderlineTextSegmentMarker("keyword.semantic.type", loc.Column, TypeReferenceFinder.ExtractId(id));
txtDoc.AddMarker(m);
markers.Add(m);
}
}
catch
{
}
}
开发者ID:Geod24,项目名称:Mono-D,代码行数:34,代码来源:TypeHighlightingExtension.cs
示例3: GetSegmentsToRenameTest2
public void GetSegmentsToRenameTest2()
{
string text = "";
RenameProvider target;
TextSegment segment = new TextSegment ();
text = "<expr>!*some comments*! {myset}\r\n" +
"keyword = 'keyword' <expr>!another comment\r\n"+
"myterm = '<'{myset}'>'keyword";
//in <expr>
target = new RenameProvider (text, 1);
segment = target.SelectedTextSegment;
Assert.AreEqual ("expr".Length, segment.Length);
Assert.AreEqual (1, segment.Offset);
//in keyword - cursor is at 40, and item starts at 37
target = new RenameProvider (text, 40);
segment = target.SelectedTextSegment;
Assert.AreEqual ("keyword".Length, segment.Length);
Assert.AreEqual (37, segment.Offset);
//in {myset}
target = new RenameProvider (text, 29);
segment = target.SelectedTextSegment;
Assert.AreEqual ("myset".Length, segment.Length);
Assert.AreEqual (29, segment.Offset);
//in <expr> (2nd occurence)
target = new RenameProvider (text, 60);
segment = target.SelectedTextSegment;
Assert.AreEqual ("expr".Length, segment.Length);
Assert.AreEqual (58, segment.Offset);
}
开发者ID:rwbloc,项目名称:gold-addin,代码行数:33,代码来源:RenameProviderTest.cs
示例4: CreateTrackedSegment
protected override ISegment CreateTrackedSegment(int offset, int length)
{
var segment = new TextSegment();
segment.StartOffset = offset;
segment.Length = length;
textSegmentCollection.Add(segment);
return segment;
}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:8,代码来源:EditorScript.cs
示例5: Equals
public bool Equals (TextSegment other)
{
if (other == null)
return false;
return Equals (Text, other.Text) &&
StartLocation == other.StartLocation &&
EndLocation == other.EndLocation;
}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:9,代码来源:TextSegment.cs
示例6: CreateMarker
private UnderlineTextSegmentMarker CreateMarker(TextSegment segment,
Color color)
{
return new UnderlineTextSegmentMarker(color, segment)
{
IsVisible = true,
Wave = false
};
}
开发者ID:nomit007,项目名称:MonoDevelop.MouseJumper,代码行数:9,代码来源:JumperDecorator.cs
示例7: SpellSuggestMenuItem
private static MenuItem SpellSuggestMenuItem(string header, TextSegment segment)
{
return new MenuItem
{
Header = header,
FontWeight = FontWeights.Bold,
Command = EditingCommands.CorrectSpellingError,
CommandParameter = new Tuple<string, TextSegment>(header, segment)
};
}
开发者ID:foukation,项目名称:Markdown-Edit,代码行数:10,代码来源:EditorSpellCheck.cs
示例8: RenameProvider
/// <summary>
/// Initializes a new instance of the <see cref="GoldAddin.RenameProvider"/> class.
/// </summary>
/// <param name="text">The document text</param>
/// <param name="documentPosition">Position within the text</param>
public RenameProvider(string text, int documentPosition)
{
textSegmentList = new List<TextSegment> ();
primarySegment = new TextSegment ();
symbolType = DefinitionType.None;
if (!string.IsNullOrEmpty (text))
{
findSegmentsForRenaming (text, documentPosition);
}
}
开发者ID:rwbloc,项目名称:gold-addin,代码行数:15,代码来源:RenameProvider.cs
示例9: Run
public static void Run()
{
// ExStart:AddTOC
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Load an existing PDF files
Document doc = new Document(dataDir + "AddTOC.pdf");
// Get access to first page of PDF file
Page tocPage = doc.Pages.Insert(1);
// Create object to represent TOC information
TocInfo tocInfo = new TocInfo();
TextFragment title = new TextFragment("Table Of Contents");
title.TextState.FontSize = 20;
title.TextState.FontStyle = FontStyles.Bold;
// Set the title for TOC
tocInfo.Title = title;
tocPage.TocInfo = tocInfo;
// Create string objects which will be used as TOC elements
string[] titles = new string[4];
titles[0] = "First page";
titles[1] = "Second page";
titles[2] = "Third page";
titles[3] = "Fourth page";
for (int i = 0; i < 2; i++)
{
// Create Heading object
Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);
TextSegment segment2 = new TextSegment();
heading2.TocPage = tocPage;
heading2.Segments.Add(segment2);
// Specify the destination page for heading object
heading2.DestinationPage = doc.Pages[i + 2];
// Destination page
heading2.Top = doc.Pages[i + 2].Rect.Height;
// Destination coordinate
segment2.Text = titles[i];
// Add heading to page containing TOC
tocPage.Paragraphs.Add(heading2);
}
dataDir = dataDir + "TOC_out.pdf";
// Save the updated document
doc.Save(dataDir);
// ExEnd:AddTOC
Console.WriteLine("\nTOC added successfully to an existing PDF.\nFile saved at " + dataDir);
}
开发者ID:aspose-pdf,项目名称:Aspose.Pdf-for-.NET,代码行数:54,代码来源:AddTOC.cs
示例10: MoveToSegment
public static void MoveToSegment(MonoDevelop.Ide.Gui.Document doc, TextSegment segment)
{
if(segment.IsInvalid || segment.IsEmpty)
return;
TextEditorData data = doc.Editor;
data.Caret.Offset = segment.Offset;
data.Parent.ScrollTo(segment.EndOffset);
var loc = data.Document.OffsetToLocation(segment.EndOffset);
if(data.Parent.TextViewMargin.ColumnToX(data.Document.GetLine (loc.Line), loc.Column) < data.HAdjustment.PageSize)
data.HAdjustment.Value = 0;
}
开发者ID:hazama-yuinyan,项目名称:monodevelop-bvebinding,代码行数:13,代码来源:MoveToUsagesHandler.cs
示例11: Main
public static void Main(string[] args)
{
// The path to the documents directory.
string dataDir = Path.GetFullPath("../../../Data/");
// Load an existing PDF files
Document doc = new Document(dataDir + "input.pdf");
// Get access to first page of PDF file
Page tocPage = doc.Pages.Insert(1);
// Create object to represent TOC information
TocInfo tocInfo = new TocInfo();
TextFragment title = new TextFragment("Table Of Contents");
title.TextState.FontSize = 20;
title.TextState.FontStyle = FontStyles.Bold;
// Set the title for TOC
tocInfo.Title = title;
tocPage.TocInfo = tocInfo;
// Create string objects which will be used as TOC elements
string[] titles = new string[4];
titles[0] = "First page";
titles[1] = "Second page";
titles[2] = "Third page";
titles[3] = "Fourth page";
for (int i = 0; i < 2; i++)
{
// Create Heading object
Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);
TextSegment segment2 = new TextSegment();
heading2.TocPage = tocPage;
heading2.Segments.Add(segment2);
// Specify the destination page for heading object
heading2.DestinationPage = doc.Pages[i + 2];
// Destination page
heading2.Top = doc.Pages[i + 2].Rect.Height;
// Destination coordinate
segment2.Text = titles[i];
// Add heading to page containing TOC
tocPage.Paragraphs.Add(heading2);
}
// Save the updated document
doc.Save(dataDir + "TOC_Output.pdf");
}
开发者ID:Ravivishnubhotla,项目名称:Aspose_Pdf_NET,代码行数:50,代码来源:Program.cs
示例12: GetChunks
public static List<List<ColoredSegment>> GetChunks (TextEditorData data, TextSegment selectedSegment)
{
int startLineNumber = data.OffsetToLineNumber (selectedSegment.Offset);
int endLineNumber = data.OffsetToLineNumber (selectedSegment.EndOffset);
var copiedColoredChunks = new List<List<ColoredSegment>> ();
foreach (var line in data.Document.GetLinesBetween (startLineNumber, endLineNumber)) {
copiedColoredChunks.Add (
data.GetChunks (
line,
System.Math.Max (selectedSegment.Offset, line.Offset),
System.Math.Max (selectedSegment.EndOffset, line.EndOffset) - line.Offset
)
.Select (chunk => new ColoredSegment (chunk, data.Document))
.ToList ()
);
}
return copiedColoredChunks;
}
开发者ID:sturmrutsturm,项目名称:monodevelop,代码行数:18,代码来源:HtmlWriter.cs
示例13: GenerateHtml
public static string GenerateHtml (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
{
var htmlText = new StringBuilder ();
htmlText.Append (@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN""><HTML><BODY>");
var selection = new TextSegment (0, doc.TextLength);
int startLineNumber = doc.OffsetToLineNumber (selection.Offset);
int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset);
htmlText.Append ("<FONT face = '" + options.Font.Family + "'>");
bool first = true;
foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) {
if (!first) {
htmlText.Append ("<BR/>");
} else {
first = false;
}
if (mode == null) {
AppendHtmlText (htmlText, doc, options, System.Math.Max (selection.Offset, line.Offset), System.Math.Min (line.EndOffset, selection.EndOffset));
continue;
}
foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) {
int start = System.Math.Max (selection.Offset, chunk.Offset);
int end = System.Math.Min (chunk.EndOffset, selection.EndOffset);
var chunkStyle = style.GetChunkStyle (chunk);
if (start < end) {
htmlText.Append ("<SPAN style = '");
if (chunkStyle.Bold)
htmlText.Append ("font-weight:bold;");
if (chunkStyle.Italic)
htmlText.Append ("font-style:italic;");
htmlText.Append ("color:" + ((HslColor)chunkStyle.Foreground).ToPangoString () + ";");
htmlText.Append ("' >");
AppendHtmlText (htmlText, doc, options, start, end);
htmlText.Append ("</SPAN>");
}
}
}
htmlText.Append ("</FONT>");
htmlText.Append ("</BODY></HTML>");
return htmlText.ToString ();
}
开发者ID:kekekeks,项目名称:monodevelop,代码行数:44,代码来源:HtmlWriter.cs
示例14: Create
public static TextEditorData Create (string input, bool reverse)
{
TextEditorData data = new Mono.TextEditor.TextEditorData ();
int offset1 = input.IndexOf ('[');
int offset2 = input.IndexOf (']');
var selection = new TextSegment (offset1, offset2 - offset1 - 1);
data.Text = input.Substring (0, offset1) + input.Substring (offset1 + 1, (offset2 - offset1) - 1) + input.Substring (offset2 + 1);
if (reverse) {
data.Caret.Offset = selection.Offset;
data.SelectionAnchor = selection.EndOffset;
data.ExtendSelectionTo (selection.Offset);
} else {
data.Caret.Offset = selection.EndOffset;
data.SelectionAnchor = selection.Offset;
data.ExtendSelectionTo (selection.EndOffset);
}
return data;
}
开发者ID:ischyrus,项目名称:monodevelop,代码行数:20,代码来源:InsertTabTests.cs
示例15: CodeSegmentPreviewWindow
public CodeSegmentPreviewWindow (TextEditor editor, bool hideCodeSegmentPreviewInformString, TextSegment segment, int width, int height, bool removeIndent = true) : base (Gtk.WindowType.Popup)
{
this.HideCodeSegmentPreviewInformString = hideCodeSegmentPreviewInformString;
this.Segment = segment;
this.editor = editor;
this.AppPaintable = true;
this.SkipPagerHint = this.SkipTaskbarHint = true;
this.TypeHint = WindowTypeHint.Menu;
layout = PangoUtil.CreateLayout (this);
informLayout = PangoUtil.CreateLayout (this);
informLayout.SetText (CodeSegmentPreviewInformString);
fontDescription = Pango.FontDescription.FromString (editor.Options.FontName);
fontDescription.Size = (int)(fontDescription.Size * 0.8f);
layout.FontDescription = fontDescription;
layout.Ellipsize = Pango.EllipsizeMode.End;
// setting a max size for the segment (40 lines should be enough),
// no need to markup thousands of lines for a preview window
SetSegment (segment, removeIndent);
CalculateSize (width);
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:21,代码来源:CodeSegmentPreviewWindow.cs
示例16: DrawBox
// ExStart:DrawBox
private static void DrawBox(PdfContentEditor editor, int page, TextSegment segment, System.Drawing.Color color)
{
var lineInfo = new LineInfo();
lineInfo.VerticeCoordinate = new[] {
(float)segment.Rectangle.LLX, (float)segment.Rectangle.LLY,
(float)segment.Rectangle.LLX, (float)segment.Rectangle.URY,
(float)segment.Rectangle.URX, (float)segment.Rectangle.URY,
(float)segment.Rectangle.URX, (float)segment.Rectangle.LLY
};
lineInfo.Visibility = true;
lineInfo.LineColor = color;
editor.CreatePolygon(lineInfo, page, new System.Drawing.Rectangle(0, 0, 0, 0), null);
}
开发者ID:aspose-pdf,项目名称:Aspose.Pdf-for-.NET,代码行数:25,代码来源:SearchTextAndDrawRectangle.cs
示例17: Contains
public bool Contains (TextSegment segment)
{
return Offset <= segment.Offset && segment.EndOffset <= EndOffsetIncludingDelimiter;
}
开发者ID:txdv,项目名称:monodevelop,代码行数:4,代码来源:LineSegment.cs
示例18: GenerateRtf
public static string GenerateRtf (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
{
var rtfText = new StringBuilder ();
var colorList = new List<Cairo.Color> ();
var selection = new TextSegment (0, doc.TextLength);
int startLineNumber = doc.OffsetToLineNumber (selection.Offset);
int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset);
bool isItalic = false;
bool isBold = false;
int curColor = -1;
foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) {
bool appendSpace = false;
if (mode == null) {
AppendRtfText (rtfText, doc, System.Math.Max (selection.Offset, line.Offset), System.Math.Min (line.EndOffset, selection.EndOffset), ref appendSpace);
continue;
}
foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) {
int start = System.Math.Max (selection.Offset, chunk.Offset);
int end = System.Math.Min (chunk.EndOffset, selection.EndOffset);
var chunkStyle = style.GetChunkStyle (chunk);
if (start < end) {
if (isBold != (chunkStyle.FontWeight == Xwt.Drawing.FontWeight.Bold)) {
isBold = chunkStyle.FontWeight == Xwt.Drawing.FontWeight.Bold;
rtfText.Append (isBold ? @"\b" : @"\b0");
appendSpace = true;
}
if (isItalic != (chunkStyle.FontStyle == Xwt.Drawing.FontStyle.Italic)) {
isItalic = chunkStyle.FontStyle == Xwt.Drawing.FontStyle.Italic;
rtfText.Append (isItalic ? @"\i" : @"\i0");
appendSpace = true;
}
var foreground = style.GetForeground (chunkStyle);
if (!colorList.Contains (foreground))
colorList.Add (foreground);
int color = colorList.IndexOf (foreground);
if (curColor != color) {
curColor = color;
rtfText.Append (@"\cf" + (curColor + 1));
appendSpace = true;
}
AppendRtfText (rtfText, doc, start, end, ref appendSpace);
}
}
rtfText.Append (@"\par");
rtfText.AppendLine ();
}
var rtf = new StringBuilder();
rtf.Append (@"{\rtf1\ansi\deff0\adeflang1025");
// font table
rtf.Append (@"{\fonttbl");
rtf.Append (@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}");
rtf.Append ("}");
rtf.Append (CreateColorTable (colorList));
rtf.Append (@"\viewkind4\uc1\pard");
rtf.Append (@"\f0");
try {
string fontName = options.Font.ToString ();
double fontSize = Double.Parse (fontName.Substring (fontName.LastIndexOf (' ') + 1), System.Globalization.CultureInfo.InvariantCulture) * 2;
rtf.Append (@"\fs");
rtf.Append (fontSize);
} catch (Exception) {};
rtf.Append (@"\cf1");
rtf.Append (rtfText.ToString ());
rtf.Append("}");
return rtf.ToString ();
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:76,代码来源:RtfWriter.cs
示例19: GenericUnderlineMarker
public GenericUnderlineMarker (TextSegment segment, MonoDevelop.Ide.Editor.TextSegmentMarkerEffect effect) : base ("", segment)
{
this.effect = effect;
}
开发者ID:zenek-y,项目名称:monodevelop,代码行数:4,代码来源:WavedLineMarker.cs
示例20: SetSegment
public void SetSegment (TextSegment segment, bool removeIndent)
{
int startLine = editor.Document.OffsetToLineNumber (segment.Offset);
int endLine = editor.Document.OffsetToLineNumber (segment.EndOffset);
bool pushedLineLimit = endLine - startLine > maxLines;
if (pushedLineLimit)
segment = new TextSegment (segment.Offset, editor.Document.GetLine (startLine + maxLines).Offset - segment.Offset);
layout.Ellipsize = Pango.EllipsizeMode.End;
layout.SetMarkup (editor.GetTextEditorData ().GetMarkup (segment.Offset, segment.Length, removeIndent) + (pushedLineLimit ? Environment.NewLine + "..." : ""));
QueueDraw ();
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:12,代码来源:CodeSegmentPreviewWindow.cs
注:本文中的TextSegment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论