当前位置: 首页>>代码示例>>C#>>正文


C# Mono.GetChunks方法代码示例

本文整理汇总了C#中Mono.GetChunks方法的典型用法代码示例。如果您正苦于以下问题:C# Mono.GetChunks方法的具体用法?C# Mono.GetChunks怎么用?C# Mono.GetChunks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono的用法示例。


在下文中一共展示了Mono.GetChunks方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: GenerateRtf

			static string GenerateRtf (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
			{
				StringBuilder rtfText = new StringBuilder ();
				List<Gdk.Color> colorList = new List<Gdk.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;
					foreach (Chunk 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);
						ChunkStyle chunkStyle = style.GetChunkStyle (chunk);
						if (start < end) {
							if (isBold != chunkStyle.Bold) {
								rtfText.Append (chunkStyle.Bold ? @"\b" : @"\b0");
								isBold = chunkStyle.Bold;
								appendSpace = true;
							}
							if (isItalic != chunkStyle.Italic) {
								rtfText.Append (chunkStyle.Italic ? @"\i" : @"\i0");
								isItalic = chunkStyle.Italic;
								appendSpace = true;
							}
							if (!colorList.Contains (chunkStyle.Color)) 
								colorList.Add (chunkStyle.Color);
							int color = colorList.IndexOf (chunkStyle.Color);
							if (curColor != color) {
								curColor = color;
								rtfText.Append (@"\cf" + (curColor + 1));
								appendSpace = true;
							}
							for (int i = start; i < end; i++) {
								char ch = doc.GetCharAt (i);
								
								switch (ch) {
								case '\\':
									rtfText.Append (@"\\");
									break;
								case '{':
									rtfText.Append (@"\{");
									break;
								case '}':
									rtfText.Append (@"\}");
									break;
								case '\t':
									rtfText.Append (@"\tab");
									appendSpace = true;
									break;
								default:
									if (appendSpace) {
										rtfText.Append (' ');
										appendSpace = false;
									}
									rtfText.Append (ch);
									break;
								}
							}
						}
					}
					rtfText.Append (@"\par");
					rtfText.AppendLine ();
				}
				
				// color table

				StringBuilder colorTable = new StringBuilder ();
				colorTable.Append (@"{\colortbl ;");
				for (int i = 0; i < colorList.Count; i++) {
					Gdk.Color color = colorList[i];
					colorTable.Append (@"\red");
					colorTable.Append (color.Red / 256);
					colorTable.Append (@"\green");
					colorTable.Append (color.Green / 256); 
					colorTable.Append (@"\blue");
					colorTable.Append (color.Blue / 256);
					colorTable.Append (";");
				}
				colorTable.Append ("}");
				
				StringBuilder 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 (colorTable.ToString ());
				
				rtf.Append (@"\viewkind4\uc1\pard");
//.........这里部分代码省略.........
开发者ID:gary-b,项目名称:monodevelop,代码行数:101,代码来源:ClipboardActions.cs


注:本文中的Mono.GetChunks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。