本文整理汇总了C#中Range.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Range.Normalize方法的具体用法?C# Range.Normalize怎么用?C# Range.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Range
的用法示例。
在下文中一共展示了Range.Normalize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRtf
public string GetRtf(Range r)
{
this.tb = r.tb;
var styles = new Dictionary<StyleIndex, object>();
var sb = new StringBuilder();
var tempSB = new StringBuilder();
var currentStyleId = StyleIndex.None;
r.Normalize();
int currentLine = r.Start.iLine;
styles[currentStyleId] = null;
colorTable.Clear();
//
var lineNumberColor = GetColorTableNumber(r.tb.LineNumberColor);
if (IncludeLineNumbers)
tempSB.AppendFormat(@"{{\cf{1} {0}}}\tab", currentLine + 1, lineNumberColor);
//
foreach (Place p in r)
{
Char c = r.tb[p.iLine][p.iChar];
if (c.style != currentStyleId)
{
Flush(sb, tempSB, currentStyleId);
currentStyleId = c.style;
styles[currentStyleId] = null;
}
if (p.iLine != currentLine)
{
for (int i = currentLine; i < p.iLine; i++)
{
tempSB.AppendLine(@"\line");
if (IncludeLineNumbers)
tempSB.AppendFormat(@"{{\cf{1} {0}}}\tab", i + 2, lineNumberColor);
}
currentLine = p.iLine;
}
switch (c.c)
{
case '\\':
tempSB.Append(@"\\");
break;
case '{':
tempSB.Append(@"\{");
break;
case '}':
tempSB.Append(@"\}");
break;
default:
var ch = c.c;
var code = (int)ch;
if(code < 128)
tempSB.Append(c.c);
else
tempSB.AppendFormat(@"{{\u{0}}}", code);
break;
}
}
Flush(sb, tempSB, currentStyleId);
//build color table
var list = new SortedList<int, Color>();
foreach (var pair in colorTable)
list.Add(pair.Value, pair.Key);
tempSB.Length = 0;
tempSB.AppendFormat(@"{{\colortbl;");
foreach (var pair in list)
tempSB.Append(GetColorAsString(pair.Value)+";");
tempSB.AppendLine("}");
//
if (UseOriginalFont)
{
sb.Insert(0, string.Format(@"{{\fonttbl{{\f0\fmodern {0};}}}}{{\fs{1} ",
tb.Font.Name, (int)(2 * tb.Font.SizeInPoints), tb.CharHeight));
sb.AppendLine(@"}");
}
sb.Insert(0, tempSB.ToString());
sb.Insert(0, @"{\rtf1\ud\deff0");
sb.AppendLine(@"}");
return sb.ToString();
}
示例2: GetHtml
public string GetHtml(Range r)
{
this.tb = r.tb;
Dictionary<StyleIndex, object> styles = new Dictionary<StyleIndex, object>();
StringBuilder sb = new StringBuilder();
StringBuilder tempSB = new StringBuilder();
StyleIndex currentStyleId = StyleIndex.None;
r.Normalize();
int currentLine = r.Start.iLine;
styles[currentStyleId] = null;
//
if (UseOriginalFont)
sb.AppendFormat("<font style=\"font-family: {0}, monospace; font-size: {1}pt; line-height: {2}px;\">",
r.tb.Font.Name, r.tb.Font.SizeInPoints, r.tb.CharHeight);
//
if (IncludeLineNumbers)
tempSB.AppendFormat("<span class=lineNumber>{0}</span> ", currentLine + 1);
//
bool hasNonSpace = false;
foreach (Place p in r)
{
Char c = r.tb[p.iLine][p.iChar];
if (c.style != currentStyleId)
{
Flush(sb, tempSB, currentStyleId);
currentStyleId = c.style;
styles[currentStyleId] = null;
}
if (p.iLine != currentLine)
{
for (int i = currentLine; i < p.iLine; i++)
{
tempSB.AppendLine(UseBr ? "<br>" : "");
if (IncludeLineNumbers)
tempSB.AppendFormat("<span class=lineNumber>{0}</span> ", i + 2);
}
currentLine = p.iLine;
hasNonSpace = false;
}
switch (c.c)
{
case ' ':
if ((hasNonSpace || !UseForwardNbsp) && !UseNbsp)
goto default;
tempSB.Append(" ");
break;
case '<':
tempSB.Append("<");
break;
case '>':
tempSB.Append(">");
break;
case '&':
tempSB.Append("&");
break;
default:
hasNonSpace = true;
tempSB.Append(c.c);
break;
}
}
Flush(sb, tempSB, currentStyleId);
if (UseOriginalFont)
sb.AppendLine("</font>");
//build styles
if (UseStyleTag)
{
tempSB.Length = 0;
tempSB.AppendLine("<style type=\"text/css\">");
foreach (var styleId in styles.Keys)
tempSB.AppendFormat(".fctb{0}{{ {1} }}\r\n", GetStyleName(styleId), GetCss(styleId));
tempSB.AppendLine("</style>");
sb.Insert(0, tempSB.ToString());
}
if (IncludeLineNumbers)
sb.Insert(0, LineNumbersCSS);
return sb.ToString();
}
示例3: ColorFromRange
Color ColorFromRange(Range range, double value)
{
//get our normalized lerp value
if(value == 0.0f)
return Color.AntiqueWhite;
return Color.Lerp(Color.Black, Color.White, (float)range.Normalize(value));
}