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


C# ITsString.Runs方法代码示例

本文整理汇总了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();
        }
开发者ID:ermshiperete,项目名称:LfMerge,代码行数:71,代码来源:ConvertFdoToMongoTsStrings.cs


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