本文整理汇总了C#中ITsString.Runs方法的典型用法代码示例。如果您正苦于以下问题:C# ITsString.Runs方法的具体用法?C# ITsString.Runs怎么用?C# ITsString.Runs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITsString
的用法示例。
在下文中一共展示了ITsString.Runs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextFromTsString
public static string TextFromTsString(ITsString tss, ILgWritingSystemFactory wsf)
{
// This will replace SafeTsStringText, and will actually deal with <span> elements
// Spec: the TsString properties ktptWs (an int property) and ktptNamedStyle (a string property)
// will be replaced with lang="(wsStr)" and class="styleName_PropValue". Other properties, that
// LF doesn't process, will be preserved in the class attribute as well, as follows:
//
// 1) Determine whether the property is an int property or a string property.
// 2) Call either IntPropertyName() or StringPropertyName() to get its name.
// 3) Create a class string in format "propC_N_NAME_VALUE" where:
// - C is "i" for int props or "s" for string props
// - N is the property number
// - NAME is, of course, the property name
// - VALUE is the property's value, with two special cases:
// * in string properties, spaces are first replaced by "_SPACE_"
// * in int properties, there's a value and a "variation", and VALUE is both of them separated by _
//
// Result: class="propi_1_ktptWs_1_0 props_1_ktptFontFamily_Times_SPACE_New_SPACE_Roman"
if (tss == null)
return null;
int[] intPropsToSkip = new int[] { (int)FwTextPropType.ktptWs };
int[] strPropsToSkip = new int[] { (int)FwTextPropType.ktptNamedStyle };
int mainWs = tss.get_WritingSystem(0);
var resultBuilder = new StringBuilder();
foreach (TsRunPart run in tss.Runs())
{
string runText = run.Text;
ITsTextProps props = run.Props;
int ws = props.GetWs();
string namedStyle = props.Style();
List<string> classes = ClassesFromTsTextProps(props, intPropsToSkip, strPropsToSkip);
bool needSpan = false;
string langAttr = null;
string classAttr = null;
if (ws != mainWs)
{
needSpan = true;
langAttr = String.Format(" lang=\"{0}\"", wsf.GetStrFromWs(ws));
}
if (namedStyle != null)
{
needSpan = true;
classes.Insert(0, String.Format("styleName_{0}", namedStyle.Replace(" ", "_SPACE_")));
}
if (classes.Count > 0)
{
needSpan = true;
classAttr = String.Format(" class=\"{0}\"", String.Join(" ", classes));
}
if (needSpan)
{
var spanBuilder = new StringBuilder();
spanBuilder.Append("<span");
if (langAttr != null)
spanBuilder.Append(langAttr);
if (classAttr != null)
spanBuilder.Append(classAttr);
spanBuilder.Append(">");
spanBuilder.Append(runText);
spanBuilder.Append("</span>");
resultBuilder.Append(spanBuilder.ToString());
}
else
resultBuilder.Append(runText);
}
return resultBuilder.ToString();
}