private bool DoLayout(Text text, Polygon polygon, LayoutOptions options) { // Initialize internal variables _text = text; _polygon = polygon; _options = options; _bounds = _polygon.Bounds; _fits = false; // Build the h-lines according to the layout settings BuildLines(); // Find out the starting line and the total number // of lines needed to layout the text. _totalLines = 1; _startLine = FirstLine(_totalLines); if (GetHLines(_totalLines).Count == 0) return false; do { // Check if the text fits within the h-lines // in the range [_startLine, _startLine + _totalLines) int iword = 0; PointList hLine = null; for (int i = _startLine; i < _startLine + _totalLines; i++) { hLine = GetHLines(_totalLines)[i] as PointList; for (int j = 0; j < hLine.Count; j += 2) { PointF pt1 = hLine[j]; PointF pt2 = hLine[j + 1]; RectangleF rc = new RectangleF( pt1.X, pt1.Y, pt2.X - pt1.X, pt2.Y - pt1.Y); bool newLine = false; iword = FitTextInRect(iword, rc, ref newLine); if (newLine) break; if (iword >= _text.Words.Count) { _fits = true; return true; } } } // If the text does not fit, increase the total // number of lines and recalculate the starting // line depending on v-alignment. _totalLines++; if (_totalLines > GetHLines(_totalLines).Count) { _totalLines--; return false; } _startLine = FirstLine(_totalLines); ArrayList hLines = GetHLines(_totalLines); if (_startLine + _totalLines > hLines.Count) { ArrayList hLines2 = GetHLines(_totalLines + 1); if (_totalLines > hLines2.Count) { // The text would not fit in the // polygon, so use all of the available // space to layout as much text as possible _totalLines = Math.Max(hLines.Count, hLines2.Count); _startLine = 0; return false; } } } while ((_startLine = FirstLine(_totalLines)) != -1); return false; }
public bool LayoutInEllipse(Text text, RectangleF bounds, LayoutOptions options) { return DoLayout(text, new Polygon(bounds, 25), options); }
/// <summary> /// Layouts text inside polygonal area. /// </summary> public bool LayoutInPolygon(Text text, PointF[] polygon, LayoutOptions options) { if (polygon == null) return false; if (polygon.Length < 3) return false; if (text == null || text.RawText.Length == 0) return true; return DoLayout(text, new Polygon(new PointList(polygon)), options); }
public bool LayoutInRectangle(Text text, RectangleF rectangle, LayoutOptions options) { return DoLayout(text, new Polygon(rectangle), options); }