/// <summary> /// Map LSCP to host CP, and return the last LSRun /// before the specified limit. /// </summary> internal LSRun CountText( int lscpLim, int cpFirst, out int count ) { LSRun lastRun = null; count = 0; int lsccp = lscpLim - _store.CpFirst; Debug.Assert(lsccp > 0, "Zero-length text line!"); foreach (Span span in _store.PlsrunVector) { if (lsccp <= 0) { break; } Plsrun plsrun = (Plsrun)span.element; // There should be no marker runs in _plsrunVector. Debug.Assert(!TextStore.IsMarker(plsrun)); // Is it a normal, non-static, LSRun? if (plsrun >= Plsrun.FormatAnchor) { // Get the run and remember the last run. lastRun = _store.GetRun(plsrun); // Accumulate the length. int cpRun = lastRun.Length; if (cpRun > 0) { if (lsccp < span.length && cpRun == span.length) { count += lsccp; break; } count += cpRun; } } lsccp -= span.length; } // make char count relative to cpFirst as the cpFirst of this metrics may not // be the same as the cpFirst of the store in optimal paragraph formatting. count = count - cpFirst + _store.CpFirst; return(lastRun); }