/// <summary> /// Finds a point inside the polygon. /// </summary> public PointF GetInternalPoint() { int cvi = FindConvexVertex(); int prev = cvi > 0 ? cvi - 1 : _points.Count - 1; int next = (cvi + 1) % _points.Count; PointF v = _points[cvi]; PointF a = _points[prev]; PointF b = _points[next]; PointList pl = new PointList(); pl.Add(a); pl.Add(v); pl.Add(b); Polygon avb = new Polygon(pl); float minDist = float.MaxValue; PointF intPt = v; for (int i = 0; i < _points.Count; ++i) { if (i == cvi) continue; if (i == prev) continue; if (i == next) continue; PointF q = _points[i]; if (avb.Contains(q)) { float dist = (float)Math.Sqrt((q.X-v.X)*(q.X-v.X) + (q.Y-v.Y)*(q.Y-v.Y)); if (dist < minDist) { minDist = dist; intPt = q; } } } if (intPt == v) return new PointF((a.X + b.X) / 2, (a.Y + b.Y) / 2); else return new PointF((v.X + intPt.X)/ 2, (v.Y + intPt.Y) / 2); }
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; }
internal override PointF getInitialPt() { PointF point = box.getCenter(); if (box.Style == BoxStyle.Shape && !box.containsPoint(point)) { PointList points = box.getPolygon(); if (points != null && points.Count > 2) { Polygon poly = new Polygon(points); return poly.GetInternalPoint(); } } return point; }