本文整理汇总了C#中ITsString.get_MinOfRun方法的典型用法代码示例。如果您正苦于以下问题:C# ITsString.get_MinOfRun方法的具体用法?C# ITsString.get_MinOfRun怎么用?C# ITsString.get_MinOfRun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITsString
的用法示例。
在下文中一共展示了ITsString.get_MinOfRun方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAdjustedTsString
/// -------------------------------------------------------------------------------------
/// <summary>
/// Make sure that all runs of the given ts string will fit within the given height.
/// </summary>
/// <param name="tss">(Potentially) unadjusted TsString -- may have some pre-existing
/// adjustments, but if it does, we (probably) ignore those and recheck every run</param>
/// <param name="dympMaxHeight">The maximum height (in millipoints) of the Ts String.</param>
/// <param name="styleSheet"></param>
/// <param name="writingSystemFactory"></param>
/// -------------------------------------------------------------------------------------
public static ITsString GetAdjustedTsString(ITsString tss, int dympMaxHeight,
IVwStylesheet styleSheet, ILgWritingSystemFactory writingSystemFactory)
{
if (dympMaxHeight == 0)
return tss;
ITsStrBldr bldr = null;
int runCount = tss.RunCount;
for (int irun = 0; irun < runCount; irun++)
{
ITsTextProps props = tss.get_Properties(irun);
int var;
int wsTmp = props.GetIntPropValues((int)FwTextPropType.ktptWs,
out var);
string styleName =
props.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle);
int height;
string name;
float sizeInPoints;
using (Font f = GetFontForStyle(styleName, styleSheet, wsTmp, writingSystemFactory))
{
height = GetFontHeight(f);
name = f.Name;
sizeInPoints = f.SizeInPoints;
}
int curHeight = height;
// incrementally reduce the size of the font until the text can fit
while (curHeight > dympMaxHeight)
{
using (var f = new Font(name, sizeInPoints - 0.25f))
{
curHeight = GetFontHeight(f);
name = f.Name;
sizeInPoints = f.SizeInPoints;
}
}
if (curHeight != height)
{
// apply formatting to the problem run
if (bldr == null)
bldr = tss.GetBldr();
int iStart = tss.get_MinOfRun(irun);
int iEnd = tss.get_LimOfRun(irun);
bldr.SetIntPropValues(iStart, iEnd,
(int)FwTextPropType.ktptFontSize,
(int)FwTextPropVar.ktpvMilliPoint, (int)(sizeInPoints * 1000.0f));
}
}
if (bldr != null)
return bldr.GetString();
else
return tss;
}
示例2: GetDiffsInTsStrings
/// <summary>
/// Get an indication of the range of characters that differ between two TsStrings.
/// Return null if they are equal
/// If they are not, ichMin indicates the first different character (or the length of the shorter string).
/// cvIns indicates how many characters must be inserted at ichMin, after deleting cvDel, to get tssNew.
/// Character properties as well as values are considered.
/// If it is ambiguous where the difference occurs, we first try to interpret the difference in a way
/// that equates to inserting or deleting a complete word, otherwise, prefer to find the longest common
/// string at the start.
/// </summary>
public static TsStringDiffInfo GetDiffsInTsStrings(ITsString tssOld, ITsString tssNew)
{
int ichMin = -1;
// no diff found
int cchOld = 0;
int crunOld = 0;
int crunNew = 0;
int cchNew = 0;
if (tssNew != null)
{
cchNew = tssNew.Length;
crunNew = tssNew.RunCount;
}
if (tssOld != null)
{
cchOld = tssOld.Length;
crunOld = tssOld.RunCount;
}
int crunBoth = Math.Min(crunOld, crunNew);
// Set ivMin to the index of the first character that is different or has different
// properties.
for (int irun = 0; irun < crunBoth; irun++)
{
if (tssOld.get_Properties(irun) != tssNew.get_Properties(irun))
{
ichMin = tssNew.get_MinOfRun(irun);
// previous runs are all OK.
break;
// difference at start of this run.
}
int ichMinRun = StringUtils.FirstDiff(tssOld.get_RunText(irun), tssNew.get_RunText(irun));
if (ichMinRun >= 0)
{
ichMin = tssNew.get_MinOfRun(irun) + ichMinRun;
break;
}
}
if (ichMin < 0)
{
// no difference found as far as crunBoth.
if (crunNew > crunBoth)
{
// All the additional length of tssNew is inserted.
return new TsStringDiffInfo(cchOld, cchNew - cchOld, 0);
}
if (crunOld > crunBoth)
{
// All the additional length of tssOld is deleted.
return new TsStringDiffInfo(cchNew, 0, cchOld - cchNew);
}
// same number of runs are identical; strings are equal
return null;
}
// There is a difference at ichMin.
// A default assumption is that the remainder of both strings differs.
//int cchEndBoth = Math.Min(cvIns, cvDel); // max characters that could be equal at end.
int irunOld = crunOld - 1;
int irunNew = crunNew - 1;
int cchSameEnd = 0;
for (; irunOld >= 0 && irunNew >= 0; irunOld--, irunNew--)
{
if (tssOld.get_Properties(irunOld) != tssNew.get_Properties(irunNew))
{
// difference at end of this run. All the text beyond this run (if any) must have matched.
break;
}
int cchSameRun = StringUtils.LastDiff(tssOld.get_RunText(irunOld), tssNew.get_RunText(irunNew));
if (cchSameRun >= 0)
{
// End of equal bit is cchSame from the ends of the two runs
cchSameEnd = cchOld - tssOld.get_LimOfRun(irunOld) + cchSameRun;
break;
}
// Same to start of this run.
cchSameEnd = cchOld - tssOld.get_MinOfRun(irunOld);
}
int cvIns = cchNew - ichMin - cchSameEnd;
int cvDel = cchOld - ichMin - cchSameEnd;
// It's possible, e.g., with "abc. def." and "abc. insert. def.", that the matching range we find
// starting from the end overlaps the matching range we find starting at the start (we find a match
// at the start up to the end of "abc. ", and from the end to the start of ". def").
// In such a case, it's ambiguous where the actual difference is (we might have inserted either
// "insert. " or ". insert"), but we definitely don't want to return any negative numbers,
// and we choose to make the longer match at the start.
// On the other hand, if the two strings are "xxxabc xxxdef" and "xxxdef", we could have deleted
// "xxxabc " or "abc xxx", and we'd prefer the first interpretation.
ITsString longerString = null;
// only used and valid if cvIns or cvDel < 0
int offsetIchMin = 0;
if (cvIns < 0)
//.........这里部分代码省略.........
示例3: MakeWssSuggestions
private ICollection<SpellCorrectMenuItem> MakeWssSuggestions(ITsString tssWord,
List<int> wss, IVwRootBox rootb, int hvoObj, int tag, int wsAlt,
int ichMin, int ichLim)
{
List<SpellCorrectMenuItem> result = new List<SpellCorrectMenuItem>(wss.Count + 1);
// Make an item with inserted spaces.
ITsStrBldr bldr = tssWord.GetBldr();
int wsFirst = TsStringUtils.GetWsOfRun(tssWord, 0);
int offset = 0;
for (int irun = 1; irun < tssWord.RunCount; irun++)
{
int wsNew = TsStringUtils.GetWsOfRun(tssWord, irun);
if (wsNew != wsFirst)
{
int ichInsert = tssWord.get_MinOfRun(irun) + offset;
bldr.Replace(ichInsert, ichInsert, " ", null);
wsFirst = wsNew;
offset++;
}
}
ITsString suggest = bldr.GetString();
string menuItemText = suggest.Text;
result.Add(new SpellCorrectMenuItem(rootb, hvoObj, tag, wsAlt, ichMin, ichLim, menuItemText, suggest));
// And items for each writing system.
foreach (int ws in wss)
{
bldr = tssWord.GetBldr();
bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, ws);
suggest = bldr.GetString();
ILgWritingSystemFactory wsf = rootb.DataAccess.WritingSystemFactory;
ILgWritingSystem engine = wsf.get_EngineOrNull(ws);
string wsName = engine.LanguageName;
string itemText = string.Format(RootSiteStrings.ksMlStringIsMono, tssWord.Text, wsName);
result.Add(new SpellCorrectMenuItem(rootb, hvoObj, tag, wsAlt, ichMin, ichLim, itemText, suggest));
}
return result;
}
示例4: FindRefRunMinLim
/// ------------------------------------------------------------------------------------
/// <summary>
/// Retrieve the extent of the current run if it is a chapter (optionally) or verse
/// number.
/// </summary>
/// <param name="tss">paragraph</param>
/// <param name="iRun">run index</param>
/// <param name="fCheckForChapter">true if we want to include searching for chapters
/// </param>
/// <param name="ichMin">output: index at beginning of run</param>
/// <param name="ichLim">output: index at limit of run</param>
/// <param name="fIsVerseNumber">output: <c>true</c> if this run is a verse number run
/// </param>
/// <returns><c>true</c> if this run is a verse number/bridge (or chapter, if checking
/// for that); <c>false</c> if not</returns>
/// ------------------------------------------------------------------------------------
private bool FindRefRunMinLim(ITsString tss, int iRun, bool fCheckForChapter,
out int ichMin, out int ichLim, out bool fIsVerseNumber)
{
ichMin = -1;
ichLim = -1;
// Check current run to see if it's a verse (or chapter) number.
ITsTextProps ttp = tss.get_Properties(iRun);
fIsVerseNumber = StStyle.IsStyle(ttp, ScrStyleNames.VerseNumber);
bool fIsChapterNumber = false;
if (!fIsVerseNumber && fCheckForChapter)
fIsChapterNumber = StStyle.IsStyle(ttp, ScrStyleNames.ChapterNumber);
if (fIsVerseNumber || fIsChapterNumber)
{
ichMin = tss.get_MinOfRun(iRun);
ichLim = tss.get_LimOfRun(iRun);
}
return (fIsVerseNumber || fIsChapterNumber);
}
示例5: RemoveOutOfRangeChapterRun
/// ------------------------------------------------------------------------------------
/// <summary>
/// Remove the current chapter run if it is not within the specified reference range.
/// </summary>
/// <param name="iRun">run index</param>
/// <param name="hvoObj">the id of the paragraph of translation being modified</param>
/// <param name="wsAlt">the writing system, if a back translation the multiString alt</param>
/// <param name="startRef">minimum reference allowed in tss</param>
/// <param name="endRef">maximum reference allowed in tss</param>
/// <param name="tss">ref: given structured string from which out of range chapters will
/// be removed</param>
/// <returns>true if chapter number run removed, otherwise false</returns>
/// <remarks>If the specified run is not a chapter run, it will not be removed.</remarks>
/// ------------------------------------------------------------------------------------
private bool RemoveOutOfRangeChapterRun(int iRun, int hvoObj, int wsAlt,
BCVRef startRef, BCVRef endRef, ref ITsString tss)
{
Debug.Assert(iRun >= 0 && iRun < tss.RunCount, "Out of range run index");
ITsTextProps ttp = tss.get_Properties(iRun);
// Is run is a chapter number?
if (ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle) ==
ScrStyleNames.ChapterNumber)
{
string runText = tss.get_RunText(iRun);
int chapterNum = ScrReference.ChapterToInt(runText);
if (chapterNum < startRef.Chapter || chapterNum > endRef.Chapter)
{
// chapter number is out of range. Remove!
int dummy;
int cchDel= runText.Length;
int ich = tss.get_MinOfRun(iRun);
ReplaceInParaOrBt(hvoObj, (int)CmTranslation.CmTranslationTags.kflidTranslation,
wsAlt, null, null, ich, ich + cchDel, ref tss, out dummy);
return true;
}
}
return false;
}
示例6: FindLastFootnoteInString
/// ------------------------------------------------------------------------------------
/// <summary>
/// Searches TsString backwards for last footnote reference.
/// </summary>
/// <param name="cache"></param>
/// <param name="tss"></param>
/// <param name="ich">Character index to start search, or -1 to start at the end of
/// the string.</param>
/// <param name="fSkipCurrentPosition">If <c>true</c> we search backwards starting with the
/// run before ich, otherwise we start with the run ich is in.</param>
/// <returns>Last footnote in string, or <c>null</c> if footnote can't be found.</returns>
/// ------------------------------------------------------------------------------------
public static ScrFootnote FindLastFootnoteInString(FdoCache cache, ITsString tss,
ref int ich, bool fSkipCurrentPosition)
{
if (ich == -1)
{
fSkipCurrentPosition = false;
ich = tss.Length;
}
ITsTextProps tprops = (fSkipCurrentPosition ? null : tss.get_PropertiesAt(ich));
int footnoteHvo = (fSkipCurrentPosition ? 0 : GetFootnoteFromProps(cache, tprops));
//TODO: TE-4199 if ich beyond the text, we must fix this so we do not skip the last run
int irun = tss.get_RunAt(ich);
while (footnoteHvo <= 0 && irun > 0)
{
irun--;
tprops = tss.get_Properties(irun);
footnoteHvo = GetFootnoteFromProps(cache, tprops);
}
ich = tss.get_MinOfRun(irun);
return footnoteHvo <= 0 ? null : new ScrFootnote(cache, footnoteHvo);
}
示例7: HasLabelText
/// <summary>
/// Test whether a run of text in a TsString contains 'label' text which should cause a segment break.
/// (Current definition is that there are characters in the range with the Scripture styles VerseNumber
/// or ChapterNumber, or the range being tested is a single character (possibly part of a longer run)
/// which is a hard line break.
/// </summary>
internal static bool HasLabelText(ITsString tss, int ichMin, int ichLim)
{
// True if the run at ichMin has one of the interesting styles or is an ORC.
int irun = tss.get_RunAt(ichMin);
if (IsLabelText(tss, irun, false))
return true;
// See if any later run in the character range has the required style or is an ORC.
int crun = tss.RunCount;
for (irun++; irun < crun && tss.get_MinOfRun(irun) < ichLim; irun++)
{
if (IsLabelText(tss, irun, false))
return true;
}
// All other ways it might be treated as a label have failed, so return false
// unless it is a one-character range containing a hard line break.
if (ichLim == ichMin + 1)
return tss.GetChars(ichMin, ichLim) == StringUtils.kChHardLB.ToString();
return false;
}
示例8: TsStringSegment
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="TsStringSegment"/> class for the
/// specified run of the specified TsString.
/// </summary>
/// <param name="tssBase">TsString from which this segment derives</param>
/// <param name="irun">The index of the run to represent.</param>
/// ------------------------------------------------------------------------------------
internal TsStringSegment(ITsString tssBase, int irun)
{
m_tssBase = tssBase;
IchMin = tssBase.get_MinOfRun(irun);
IchLim = tssBase.get_LimOfRun(irun);
}
示例9: CreatePuncFormsInSegmentForOrcs
/// ------------------------------------------------------------------------------------
/// <summary>
/// Creates punctuation form analyses for all of the ORCs in the specified baseLine string.
/// </summary>
/// <param name="segment">The segment to which we are going to add the analyses.</param>
/// <param name="baseLine">The base line of the original segment from which we are moving
/// the ORCs.</param>
/// <param name="para">The paragraph that owns the given segment.</param>
/// <param name="iInsertPos">Index (0-based) in the sequence of analyses where the ORC
/// punctuation form(s) should be inserted.</param>
/// ------------------------------------------------------------------------------------
private static void CreatePuncFormsInSegmentForOrcs(ISegment segment, ITsString baseLine,
IScrTxtPara para, int iInsertPos)
{
if (!para.SegmentsOS.Any(seg => seg.AnalysesRS.Count > 0))
return;
for (int i = 0; i < baseLine.RunCount; i++)
{
if (baseLine.get_IsRunOrc(i))
{
IPunctuationForm orcForm = para.Cache.ServiceLocator.GetInstance<IPunctuationFormFactory>().Create();
orcForm.Form = baseLine.GetSubstring(baseLine.get_MinOfRun(i), baseLine.get_LimOfRun(i));
segment.AnalysesRS.Insert(iInsertPos++, orcForm);
}
}
}
示例10: CorrectFootnotes
/// <summary>
/// Any ORCs in the given string with ktptObjData of type kodtOwnNameGuidHot (meaning a GUID that
/// 'owns' the footnote) should be changed to kodtNameGuidHot, since the BT does NOT own
/// the footnote.
/// </summary>
/// <param name="tssFt"></param>
/// <returns></returns>
private static ITsString CorrectFootnotes(ITsString tssFt)
{
ITsStrBldr bldr = null;
int crun = tssFt.RunCount;
for (int iRun = 0; iRun < crun; iRun++)
{
string sOrc = tssFt.get_RunText(iRun);
if (String.IsNullOrEmpty(sOrc))
continue;
if (StringUtils.kchObject != sOrc[0])
continue;
ITsTextProps orcPropsParaFootnote = tssFt.get_Properties(iRun);
string objData = orcPropsParaFootnote.GetStrPropValue((int) FwTextPropType.ktptObjData);
if (String.IsNullOrEmpty(objData))
continue;
if((char) (int) FwObjDataTypes.kodtOwnNameGuidHot != objData[0])
continue;
// OK, need to fix it.
if (bldr == null)
bldr = tssFt.GetBldr();
objData = ((char)(int)FwObjDataTypes.kodtNameGuidHot).ToString() + objData.Substring(1);
bldr.SetStrPropValue(tssFt.get_MinOfRun(iRun), tssFt.get_LimOfRun(iRun), (int)FwTextPropType.ktptObjData, objData);
}
if (bldr == null)
return tssFt; // no change
else
return bldr.GetString();
}
示例11: GetDiffsInTsStrings
/// <summary>
/// Get an indication of the range of characters that differ between two TsStrings.
/// Return true if they are equal, false if they are not.
/// If they are not, ichMin indicates the first different character (or the length of the shorter string).
/// cvIns indicates how many characters must be inserted at ichMin, after deleting cvDel, to get tssNew.
/// Character properties as well as values are considered.
/// </summary>
public static bool GetDiffsInTsStrings(ITsString tssOld, ITsString tssNew, out int ichMin, out int cvIns, out int cvDel)
{
ichMin = -1; // no diff found
cvIns = cvDel = 0; // defaults in case no diff found.
int cchOld = 0;
int crunOld = 0;
int crunNew = 0;
int cchNew = 0;
if (tssNew != null)
{
cchNew = tssNew.Length;
crunNew = tssNew.RunCount;
}
if (tssOld != null)
{
cchOld = tssOld.Length;
crunOld = tssOld.RunCount;
}
int crunBoth = Math.Min(crunOld, crunNew);
// Set ivMin to the index of the first character that is different or has different
// properties.
for (int irun = 0; irun < crunBoth; irun++)
{
if (tssOld.get_Properties(irun) != tssNew.get_Properties(irun))
{
ichMin = tssNew.get_MinOfRun(irun); // previous runs are all OK.
break; // difference at start of this run.
}
int ichMinRun = StringUtils.FirstDiff(tssOld.get_RunText(irun), tssNew.get_RunText(irun));
if (ichMinRun >= 0)
{
ichMin = tssNew.get_MinOfRun(irun) + ichMinRun;
break;
}
}
if (ichMin < 0)
{
// no difference found as far as crunBoth.
if (crunNew > crunBoth)
{
// All the additional length of tssNew is inserted.
ichMin = cchOld;
cvIns = cchNew - cchOld;
return false;
}
if (crunOld > crunBoth)
{
// All the additional length of tssOld is deleted.
ichMin = cchNew;
cvDel = cchOld - cchNew;
return false;
}
// same number of runs are identical; strings are equal
return true;
}
// There is a difference at ichMin.
// A default assumption is that the remainder of both strings differs.
//int cchEndBoth = Math.Min(cvIns, cvDel); // max characters that could be equal at end.
int irunOld = crunOld - 1;
int irunNew = crunNew - 1;
int cchSameEnd = 0;
for (; irunOld >= 0 && irunNew >= 0; irunOld--, irunNew--)
{
if (tssOld.get_Properties(irunOld) != tssNew.get_Properties(irunNew))
{
// difference at end of this run. All the text beyond this run (if any) must have matched.
break;
}
int cchSameRun = LastDiff(tssOld.get_RunText(irunOld), tssNew.get_RunText(irunNew));
if (cchSameRun >= 0)
{
// End of equal bit is cchSame from the ends of the two runs
cchSameEnd = cchOld - tssOld.get_LimOfRun(irunOld) + cchSameRun;
break;
}
// Same to start of this run.
cchSameEnd = cchOld - tssOld.get_MinOfRun(irunOld);
}
cvIns = cchNew - ichMin - cchSameEnd;
cvDel = cchOld - ichMin - cchSameEnd;
return false;
}
示例12: RunEqual
///----------------------------------------------------------------------------------
/// <summary>
/// Asserts that the run is equal to the expected TsString.
/// </summary>
///----------------------------------------------------------------------------------
public void RunEqual(string expectedText, ITsString tss, int iRun, int iMin)
{
var runText = tss.get_RunText(iRun);
Assert.AreEqual(expectedText, runText);
Assert.IsTrue(runText.IsNormalized(NormalizationForm.FormD));
Assert.AreEqual(iMin, tss.get_MinOfRun(iRun));
Assert.AreEqual(iMin + expectedText.Length, tss.get_LimOfRun(iRun));
}