/// <summary> /// Constructs a <code>LineBreakMeasurer</code> for the specified text. /// </summary> /// <param name="text"> the text for which this <code>LineBreakMeasurer</code> /// produces <code>TextLayout</code> objects; the text must contain /// at least one character; if the text available through /// <code>iter</code> changes, further calls to this /// <code>LineBreakMeasurer</code> instance are undefined (except, /// in some cases, when <code>insertChar</code> or /// <code>deleteChar</code> are invoked afterward - see below) </param> /// <param name="breakIter"> the <seealso cref="BreakIterator"/> which defines line /// breaks </param> /// <param name="frc"> contains information about a graphics device which is /// needed to measure the text correctly; /// text measurements can vary slightly depending on the /// device resolution, and attributes such as antialiasing; this /// parameter does not specify a translation between the /// <code>LineBreakMeasurer</code> and user space </param> /// <exception cref="IllegalArgumentException"> if the text has less than one character </exception> /// <seealso cref= LineBreakMeasurer#insertChar </seealso> /// <seealso cref= LineBreakMeasurer#deleteChar </seealso> public LineBreakMeasurer(AttributedCharacterIterator text, BreakIterator breakIter, FontRenderContext frc) { if (text.EndIndex - text.BeginIndex < 1) { throw new IllegalArgumentException("Text must contain at least one character."); } this.BreakIter = breakIter; this.Measurer = new TextMeasurer(text, frc); this.Limit = text.EndIndex; this.Pos = this.Start = text.BeginIndex; CharIter = new CharArrayIterator(Measurer.Chars, this.Start); this.BreakIter.SetText(CharIter); }
private void MakeLayoutWindow(int localStart) { int compStart = localStart; int compLimit = FChars.Length; // If we've already gone past the layout window, format to end of paragraph if (LayoutCount > 0 && !HaveLayoutWindow) { float avgLineLength = System.Math.Max(LayoutCharCount / LayoutCount, 1); compLimit = System.Math.Min(localStart + (int)(avgLineLength * EST_LINES), FChars.Length); } if (localStart > 0 || compLimit < FChars.Length) { if (CharIter == null) { CharIter = new CharArrayIterator(FChars); } else { CharIter.Reset(FChars); } if (FLineBreak == null) { FLineBreak = BreakIterator.LineInstance; } FLineBreak.SetText(CharIter); if (localStart > 0) { if (!FLineBreak.IsBoundary(localStart)) { compStart = FLineBreak.Preceding(localStart); } } if (compLimit < FChars.Length) { if (!FLineBreak.IsBoundary(compLimit)) { compLimit = FLineBreak.Following(compLimit); } } } EnsureComponents(compStart, compLimit); HaveLayoutWindow = true; }