本文整理汇总了C#中Mono.GetForeground方法的典型用法代码示例。如果您正苦于以下问题:C# Mono.GetForeground方法的具体用法?C# Mono.GetForeground怎么用?C# Mono.GetForeground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono
的用法示例。
在下文中一共展示了Mono.GetForeground方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 ();
}
示例2: GenerateRtf
public static string GenerateRtf (List<List<ColoredSegment>> chunks, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
{
var rtfText = new StringBuilder ();
var colorList = new List<Cairo.Color> ();
bool isItalic = false;
bool isBold = false;
int curColor = -1;
foreach (var line in chunks) {
bool appendSpace = false;
foreach (var chunk in line) {
var chunkStyle = style.GetChunkStyle (chunk.Style);
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, chunk.Text, ref appendSpace);
}
rtfText.AppendLine (@"\line");
}
var rtf = new StringBuilder();
rtf.AppendLine (@"{\rtf1\ansi\deff0\adeflang1025");
rtf.AppendLine (@"{\fonttbl");
rtf.AppendLine (@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}");
rtf.AppendLine ("}");
rtf.Append (CreateColorTable (colorList));
rtf.AppendLine (@"\viewkind4\uc1\pard");
rtf.AppendLine (@"\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.AppendLine (@"\cf1");
rtf.Append (rtfText.ToString ());
rtf.Append("}");
return rtf.ToString ();
}