本文整理汇总了C#中ITsString.get_LimOfRun方法的典型用法代码示例。如果您正苦于以下问题:C# ITsString.get_LimOfRun方法的具体用法?C# ITsString.get_LimOfRun怎么用?C# ITsString.get_LimOfRun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITsString
的用法示例。
在下文中一共展示了ITsString.get_LimOfRun方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
Font f = GetFontForStyle(styleName, styleSheet, wsTmp, writingSystemFactory);
int height = GetFontHeight(f);
int curHeight = height;
// incrementally reduce the size of the font until the text can fit
while (curHeight > dympMaxHeight)
{
f = new Font(f.Name, f.SizeInPoints - 0.25f);
curHeight = GetFontHeight(f);
}
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)(f.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: 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);
}
示例4: RemoveDuplicateVerseNumbersInPara
//.........这里部分代码省略.........
--iRun;
}
//If we found a chapter beyond our target chapter, we are done.
else if (chapterNum > removeChapter)
return true;
}
else if (ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle) ==
ScrStyleNames.VerseNumber)
{
// Process this verse number run
string verseNumberText = tss.get_RunText(iRun);
string bridgeJoiner = m_scr.BridgeForWs(wsAlt);
// get binary values of this verse number run
int startNumber, endNumber; //numbers in this verse number run
ScrReference.VerseToInt(verseNumberText, out startNumber, out endNumber);
// and the bridge-joiner index, if any
int bridgeJoinerIndex = verseNumberText.IndexOf(bridgeJoiner, StringComparison.Ordinal);
if (startNumber <= removeUpToVerse)
{
// Target verse(s) found. Remove!
int cchDel;
int dummy;
if (endNumber <= removeUpToVerse)
{
//remove all of verseNumberText
cchDel = verseNumberText.Length;
ReplaceInParaOrBt(hvoObj, propTag, wsAlt, null, null,
ich, ich + cchDel,
ref tss, out dummy);
// since we removed an entire run, we must adjust our current iRun
if (iRun > 0)
--iRun;
if (endNumber == removeUpToVerse)
fAllDone = true;
}
else if (endNumber == removeUpToVerse + 1)
{
// reduce to a single verse (ending verse)
Debug.Assert(bridgeJoinerIndex > -1);
cchDel = bridgeJoinerIndex + bridgeJoiner.Length;
ReplaceInParaOrBt(hvoObj, propTag, wsAlt, null, null,
ich, ich + cchDel,
ref tss, out dummy);
fAllDone = true;
}
else // endNumber > removeUpToVerse + 1
{
// set beginning of bridge to max+1
Debug.Assert(bridgeJoinerIndex > -1);
cchDel = bridgeJoinerIndex;
string maxPlusOne = m_scr.ConvertToString(removeUpToVerse + 1);
ReplaceInParaOrBt(hvoObj, propTag, wsAlt, maxPlusOne, ttp,
ich, ich + cchDel,
ref tss, out dummy);
fAllDone = true;
}
}
else // startNumber > removeUpToVerse
{
fAllDone = true; //we are done looking.
// we assume verse numbers are in order
}
if (fAllDone)
return true;
}
// we are not looking to remove a chapter, and the current run is not a verse
else if (ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle) ==
ScrStyleNames.ChapterNumber)
{
string runText = tss.get_RunText(iRun);
if (ScrReference.ChapterToInt(runText) != 1)
{
// quit when a chapter number is found that is not one.
return true;
}
else
{
// chapter 1 found after inserted verse number. Remove!
int cchDel = runText.Length;
int dummy;
ReplaceInParaOrBt(hvoObj, propTag, wsAlt, null, null,
ich, ich + cchDel, ref tss, out dummy);
// since we removed an entire run, we must adjust our current iRun
if (iRun > 0)
--iRun;
}
}
ich = tss.get_LimOfRun(iRun);
}
return false;
}
示例5: GetLimOfReference
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets the ending character index of reference run--or runs if a chapter and verse
/// number are adjacent.
/// </summary>
/// <param name="tss">The ITsString.</param>
/// <param name="iRun">The index of the run.</param>
/// <param name="ttp">The text properties of the run.</param>
/// <returns>character index at the end of the reference runs(s)</returns>
/// ------------------------------------------------------------------------------------
private static int GetLimOfReference(ITsString tss, int iRun, ref ITsTextProps ttp)
{
// The first run is either a verse or chapter number run.
if (tss.RunCount > iRun + 1)
{
// There are more runs so determine if the next run is a verse number.
ttp = tss.get_Properties(iRun + 1);
// If so, get the lim of this next run.
if (StStyle.IsStyle(ttp, ScrStyleNames.VerseNumber))
return tss.get_LimOfRun(iRun + 1);
}
return tss.get_LimOfRun(iRun);
}
示例6: GetIchLimRef_IfIchInRefAtParaStart
/// ------------------------------------------------------------------------------------
/// <summary>
/// Determine if the paragraph starts with chapter/verse run and the ich is within one
/// of these runs.
/// </summary>
/// <param name="tss">paragraph string</param>
/// <param name="ich">character offset</param>
/// <returns>ich after the reference or -1 if the paragraph does not begin with a
/// chapter/verse run</returns>
/// ------------------------------------------------------------------------------------
private static int GetIchLimRef_IfIchInRefAtParaStart(ITsString tss, int ich)
{
int iRun = tss.get_RunAt(ich);
ITsTextProps firstTtp = tss.get_Properties(0);
ITsTextProps ttp = tss.get_PropertiesAt(ich);
if ((StStyle.IsStyle(ttp, ScrStyleNames.VerseNumber) ||
StStyle.IsStyle(ttp, ScrStyleNames.ChapterNumber)) && iRun == 0)
{
return GetLimOfReference(tss, iRun, ref ttp);
}
else if (StStyle.IsStyle(firstTtp, ScrStyleNames.ChapterNumber) &&
StStyle.IsStyle(ttp, ScrStyleNames.VerseNumber) && iRun == 1)
{
// The first run is a chapter and the next is a verse number run.
// Return the lim of the verse number (current) run.
return tss.get_LimOfRun(iRun);
}
else if (iRun == 0 && IsBlank(tss, iRun))
{
// The first run contains only white space.
// Ignore this run and check the following runs.
if (tss.RunCount > 1)
{
ttp = tss.get_Properties(iRun + 1);
if (StStyle.IsStyle(ttp, ScrStyleNames.VerseNumber) ||
StStyle.IsStyle(ttp, ScrStyleNames.ChapterNumber))
{
return GetLimOfReference(tss, iRun + 1, ref ttp);
}
}
}
// Paragraph doesn't begin with a chapter/verse number run (or the ich
// wasn't in it).
return -1;
}
示例7: FindBtFootnoteIndex
/// ------------------------------------------------------------------------------------
/// <summary>
/// Determine the zero-based index within a paragraph of a footnote to be inserted in
/// the back translation.</summary>
/// <param name="ichBtSel">the character offset in the back translation paragraph</param>
/// <param name="btTss">back translation ITsString</param>
/// <returns>zero-based index of a footnote to be inserted</returns>
/// ------------------------------------------------------------------------------------
private int FindBtFootnoteIndex(int ichBtSel, ITsString btTss)
{
// Scan through the back translation paragraph to find the index of the footnote
// to insert
int iRun = 0;
int iBtFootnote = 0;
int runLim = btTss.get_RunAt(ichBtSel);
TsRunInfo tri;
ITsTextProps ttp;
FwObjDataTypes odt;
Set<FwObjDataTypes> desiredOrcTypes = new Set<FwObjDataTypes>(2);
desiredOrcTypes.Add(FwObjDataTypes.kodtNameGuidHot);
desiredOrcTypes.Add(FwObjDataTypes.kodtOwnNameGuidHot); // We have to look for this kind of ORC too because of a past bug that caused BT footnotes to get imported with the wrong type of ORC
while (iRun < btTss.RunCount && btTss.get_LimOfRun(iRun) <= ichBtSel)
{
if (StringUtils.GetGuidFromRun(btTss, iRun, out odt, out tri, out ttp, desiredOrcTypes)
!= Guid.Empty)
{
// Found footnote ORC in back translation
iBtFootnote++;
}
iRun++;
}
return iBtFootnote;
}
示例8: FindFirstFootnoteInString
/// ------------------------------------------------------------------------------------
/// <summary>
/// Searches TsString forwards for first footnote reference.
/// </summary>
/// <param name="cache"></param>
/// <param name="tss"></param>
/// <param name="ich">Character index to start search.</param>
/// <param name="fSkipCurrentPosition">If <c>true</c> we search forward starting with the
/// run after ich, otherwise we start with the current run.</param>
/// <returns>First footnote in string after ich, or <c>null</c> if footnote can't be found.</returns>
/// ------------------------------------------------------------------------------------
public static ScrFootnote FindFirstFootnoteInString(FdoCache cache, ITsString tss,
ref int ich, bool fSkipCurrentPosition)
{
int irun = tss.get_RunAt(ich);
int runCount = tss.RunCount;
ITsTextProps tprops;
int footnoteHvo;
if (fSkipCurrentPosition)
irun++;
while (irun < runCount)
{
tprops = tss.get_Properties(irun);
footnoteHvo = GetFootnoteFromProps(cache, tprops);
if (footnoteHvo > 0)
{
ich = tss.get_LimOfRun(irun);
return new ScrFootnote(cache, footnoteHvo);
}
irun++;
}
return null;
}
示例9: 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);
}
示例10: 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);
}
}
}
示例11: 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();
}
示例12: 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;
}
示例13: 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));
}