本文整理汇总了C#中ILgWritingSystemFactory.GetStrFromWs方法的典型用法代码示例。如果您正苦于以下问题:C# ILgWritingSystemFactory.GetStrFromWs方法的具体用法?C# ILgWritingSystemFactory.GetStrFromWs怎么用?C# ILgWritingSystemFactory.GetStrFromWs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILgWritingSystemFactory
的用法示例。
在下文中一共展示了ILgWritingSystemFactory.GetStrFromWs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: WriteIntTextProp
/// <summary>
/// Write the integer text property as an XML attribute.
/// </summary>
/// <param name="writer"></param>
/// <param name="wsf"></param>
/// <param name="tpt"></param>
/// <param name="nVar"></param>
/// <param name="nVal"></param>
public void WriteIntTextProp(TextWriter writer, ILgWritingSystemFactory wsf,
int tpt, int nVar, int nVal)
{
Debug.Assert(writer != null);
Debug.Assert(wsf != null);
switch (tpt)
{
case (int)FwTextPropType.ktptBackColor:
writer.Write(" backcolor=\"{0}\"", ColorName(nVal));
break;
case (int)FwTextPropType.ktptBold:
writer.Write(" bold=\"{0}\"", ToggleValueName((byte)nVal));
break;
case (int)FwTextPropType.ktptWs:
if (nVal != 0)
{
string sWs = wsf.GetStrFromWs(nVal);
if (String.IsNullOrEmpty(sWs))
throw new Exception("Invalid writing system for <Run ws=\"...\">.");
writer.Write(" ws=\"{0}\"", XmlUtils.MakeSafeXmlAttribute(sWs));
}
break;
case (int)FwTextPropType.ktptBaseWs:
if (nVal != 0)
{
string sWs = wsf.GetStrFromWs(nVal);
if (String.IsNullOrEmpty(sWs))
throw new Exception("Invalid writing system for <Run wsBase=\"...\">.");
writer.Write(" wsBase=\"{0}\"", XmlUtils.MakeSafeXmlAttribute(sWs));
}
break;
case (int)FwTextPropType.ktptFontSize:
writer.Write(" fontsize=\"{0}\"", nVal);
if (nVar != (int)FwTextPropVar.ktpvDefault)
writer.Write(" fontsizeUnit=\"{0}\"", PropVarName(nVar));
break;
case (int)FwTextPropType.ktptForeColor:
writer.Write(" forecolor=\"{0}\"", ColorName(nVal));
break;
case (int)FwTextPropType.ktptItalic:
writer.Write(" italic=\"{0}\"", ToggleValueName((byte)nVal));
break;
case (int)FwTextPropType.ktptOffset:
writer.Write(" offset=\"{0}\"", nVal);
writer.Write(" offsetUnit=\"{0}\"", PropVarName(nVar));
break;
case (int)FwTextPropType.ktptSuperscript:
writer.Write(" superscript=\"{0}\"", SuperscriptValName((byte)nVal));
break;
case (int)FwTextPropType.ktptUnderColor:
writer.Write(" undercolor=\"{0}\"", ColorName(nVal));
break;
case (int)FwTextPropType.ktptUnderline:
writer.Write(" underline=\"{0}\"", UnderlineTypeName((byte)nVal));
break;
case (int)FwTextPropType.ktptSpellCheck:
writer.Write(" spellcheck=\"{0}\"", SpellingModeName((byte)nVal));
break;
// Paragraph level properties.
case (int)FwTextPropType.ktptAlign:
writer.Write(" align=\"{0}\"", AlignmentTypeName((byte)nVal));
break;
case (int)FwTextPropType.ktptFirstIndent:
writer.Write(" firstIndent=\"{0}\"", nVal);
break;
case (int)FwTextPropType.ktptLeadingIndent:
writer.Write(" leadingIndent=\"{0}\"", nVal);
break;
case (int)FwTextPropType.ktptTrailingIndent:
writer.Write(" trailingIndent=\"{0}\"", nVal);
break;
case (int)FwTextPropType.ktptSpaceBefore:
writer.Write(" spaceBefore=\"{0}\"", nVal);
break;
case (int)FwTextPropType.ktptSpaceAfter:
writer.Write(" spaceAfter=\"{0}\"", nVal);
break;
case (int)FwTextPropType.ktptTabDef:
writer.Write(" tabDef=\"{0}\"", nVal);
break;
case (int)FwTextPropType.ktptLineHeight:
writer.Write(" lineHeight=\"{0}\"", Math.Abs(nVal));
writer.Write(" lineHeightUnit=\"{0}\"", PropVarName(nVar));
Debug.Assert(nVal >= 0 || nVar == (int)FwTextPropVar.ktpvMilliPoint);
if (nVar == (int)FwTextPropVar.ktpvMilliPoint)
{
// negative means "exact" internally. See FWC-20.
writer.Write(" lineHeightType=\"{0}\"", nVal < 0 ? "exact" : "atLeast");
}
//.........这里部分代码省略.........
示例3: GetChrpForStyle
/// <summary>
/// Gets the character render properties for the given style name and writing system.
/// </summary>
/// <param name="styleName">The style name.</param>
/// <param name="styleSheet">The stylesheet.</param>
/// <param name="hvoWs">The HVO of the WS.</param>
/// <param name="writingSystemFactory">The writing system factory.</param>
/// <returns>The character render properties.</returns>
public static LgCharRenderProps GetChrpForStyle(string styleName, IVwStylesheet styleSheet,
int hvoWs, ILgWritingSystemFactory writingSystemFactory)
{
if (string.IsNullOrEmpty(writingSystemFactory.GetStrFromWs(hvoWs)))
{
try
{
throw new ArgumentException("This is a hard-to-reproduce scenario (TE-6891) where writing system (" + hvoWs + ") and factory are inconsistent. Call an expert (JohnT)");
}
catch (ArgumentException e)
{
Logger.WriteError(e);
Debug.Fail("This is a hard-to-reproduce scenario (TE-6891) where writing system and factory are inconsistent. Call an expert (JohnT) while you have this Assert active!");
hvoWs = writingSystemFactory.UserWs;
}
}
IVwPropertyStore vwps = VwPropertyStoreClass.Create();
vwps.Stylesheet = styleSheet;
vwps.WritingSystemFactory = writingSystemFactory;
ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();
ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName);
ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoWs);
ITsTextProps ttp = ttpBldr.GetTextProps();
LgCharRenderProps chrps = vwps.get_ChrpFor(ttp);
IWritingSystem ws = writingSystemFactory.get_EngineOrNull(hvoWs);
ws.InterpretChrp(ref chrps);
return chrps;
}
示例4: XmlTextRun
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="XmlTextRun"/> class, based on the given
/// run information
/// </summary>
/// <param name="wsDefault">The default writing system of the paragraph.</param>
/// <param name="lgwsf">The writing system factory.</param>
/// <param name="text">The text of the run.</param>
/// <param name="props">The properties of the run.</param>
/// ------------------------------------------------------------------------------------
public XmlTextRun(int wsDefault, ILgWritingSystemFactory lgwsf, string text,
ITsTextProps props)
{
int dummy;
int wsRun = props.GetIntPropValues((int)FwTextPropType.ktptWs, out dummy);
if (wsRun != wsDefault)
IcuLocale = lgwsf.GetStrFromWs(wsRun);
StyleName = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
m_text = text;
}
示例5: XmlScrAnnotationsList
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="XmlScrAnnotationsList"/> class based on
/// the given collection of Scripture notes.
/// </summary>
/// <param name="cache">The cache.</param>
/// ------------------------------------------------------------------------------------
public XmlScrAnnotationsList(FdoCache cache)
{
m_cache = cache;
m_lgwsf = m_cache.LanguageWritingSystemFactoryAccessor;
VernacularIcuLocale = m_lgwsf.GetStrFromWs(m_cache.DefaultVernWs);
DefaultIcuLocale = m_lgwsf.GetStrFromWs(m_cache.DefaultAnalWs);
DateTimeExported = DateTime.Now;
ProjectName = m_cache.LangProject.Name.GetAlternative(SpecialWritingSystemCodes.BestAnalysis);
WindowsIdentity whoami = WindowsIdentity.GetCurrent();
ExportedBy = whoami.Name.Normalize();
}
示例6: XmlNotePara
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="XmlNotePara"/> class based on the given
/// StTxtPara.
/// </summary>
/// <param name="stTxtPara">The FDO paragraph.</param>
/// <param name="wsDefault">The default (analysis) writing system.</param>
/// <param name="lgwsf">The writing system factory.</param>
/// ------------------------------------------------------------------------------------
public XmlNotePara(IStTxtPara stTxtPara, int wsDefault, ILgWritingSystemFactory lgwsf)
{
// REVIEW: Ask TomB about this. The only paragraph style allowed in
// TE for notes is "Remark" so is it necessary to write it to the XML?
// It causes a problem for the OXES validator.
//StyleName = stTxtPara.StyleName;
ITsString tssParaContents = stTxtPara.Contents.UnderlyingTsString;
if (tssParaContents.RunCount == 0)
return;
int dummy;
int wsFirstRun = tssParaContents.get_Properties(0).GetIntPropValues(
(int)FwTextPropType.ktptWs, out dummy);
//if (wsFirstRun != wsDefault)
IcuLocale = lgwsf.GetStrFromWs(wsFirstRun);
for (int iRun = 0; iRun < tssParaContents.RunCount; iRun++)
{
ITsTextProps props = tssParaContents.get_Properties(iRun);
string text = tssParaContents.get_RunText(iRun);
if (StringUtils.IsHyperlink(props))
Runs.Add(new XmlHyperlinkRun(wsFirstRun, lgwsf, text, props));
else
Runs.Add(new XmlTextRun(wsFirstRun, lgwsf, text, props));
}
}
示例7: InitializeCategory
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes categories in the hierarchy.
/// </summary>
/// <param name="categoryList">The list of categories for a Scripture note.</param>
/// <param name="lgwsf">The language writing system factory.</param>
/// <exception cref="ArgumentOutOfRangeException">thrown when the category list is empty.
/// </exception>
/// ------------------------------------------------------------------------------------
private void InitializeCategory(List<CategoryNode> categoryList, ILgWritingSystemFactory lgwsf)
{
XmlNoteCategory curCategory = this;
CategoryNode node = null;
for (int i = 0; i < categoryList.Count; i++)
{
node = categoryList[i];
curCategory.CategoryName = node.CategoryName;
curCategory.IcuLocale = lgwsf.GetStrFromWs(node.Ws);
if (categoryList.Count > i + 1)
{
curCategory.SubCategory = new XmlNoteCategory();
curCategory = curCategory.SubCategory;
}
else
{
curCategory.SubCategory = null;
}
}
}
示例8: Persist
public string Persist(ILgWritingSystemFactory wsf)
{
StringBuilder builder = new StringBuilder();
builder.Append(this.GetType().Name);
foreach (InterlinLineSpec spec in m_specs)
{
builder.Append(",");
builder.Append(spec.Flid);
builder.Append("%");
builder.Append(wsf.GetStrFromWs(spec.WritingSystem));
}
return builder.ToString();
}