Exemple #1
0
            public int CompareTo(object obj)
            {
                DirPt pt = (DirPt)obj;

                if (this < pt)
                {
                    return(-1);
                }
                else if (this > pt)
                {
                    return(1);
                }
                return(0);
            }
Exemple #2
0
        /// <summary>
        /// Creates single h-line at the specified vertical offset.
        /// </summary>
        private PointList BuildLine(float yOff)
        {
            PointF p11 = new PointF(_bounds.Left - 1, 0);
            PointF p12 = new PointF(_bounds.Right + 1, 0);
            PointF p21 = new PointF(_bounds.Left - 1, 0);
            PointF p22 = new PointF(_bounds.Right + 1, 0);

            p11.Y = p12.Y = yOff;
            yOff += _text.Height;
            if (yOff > _bounds.Bottom)
            {
                return(null);
            }
            p21.Y = p22.Y = yOff;

            ArrayList merge  = new ArrayList();
            PointList result = new PointList();
            PointList row1   = PolygonIntersect(p11, p12);
            PointList row2   = PolygonIntersect(p21, p22);

            int i;

            for (i = 0; i < row1.Count; i++)
            {
                merge.Add(new DirPt(row1[i], i % 2 == 1 ? 2 : 0));
            }
            for (i = 0; i < row2.Count; i++)
            {
                merge.Add(new DirPt(row2[i], i % 2 == 1 ? 3 : 1));
            }

            merge.Sort();

            PointF pt    = PointF.Empty;
            int    inter = -1;          // 0 - for first line, 2 for second line, 4 - for both

            for (i = 0; i < merge.Count; i++)
            {
                DirPt temp = merge[i] as DirPt;

                if (temp.Direction == 2 || temp.Direction == 3)                 // out
                {
                    if (inter != 4)
                    {
                        if (inter == 0 && temp.Direction == 2)
                        {
                            inter = -1;
                        }
                        else if (inter == 2 && temp.Direction == 3)
                        {
                            inter = -1;
                        }
                        continue;
                    }

                    pt.Y       = yOff - _text.Height;
                    temp.Point = new PointF(temp.Point.X, yOff);

                    // Make points relative to the upper-left point of the polygon
                    pt.X      -= _bounds.Left;
                    pt.Y      -= _bounds.Top;
                    temp.Point = new PointF(
                        temp.Point.X - _bounds.Left,
                        temp.Point.Y - _bounds.Top);

                    result.Add(pt);
                    result.Add(temp.Point);

                    if (temp.Direction == 2)
                    {
                        inter = 2;
                    }
                    else
                    {
                        inter = 0;
                    }
                }
                else
                {
                    pt = temp.Point;

                    if (temp.Direction == 0)
                    {
                        if (inter == -1)
                        {
                            inter = 0;
                        }
                        else if (inter == 2)
                        {
                            inter = 4;
                        }
                    }
                    else
                    {
                        if (inter == -1)
                        {
                            inter = 2;
                        }
                        else if (inter == 0)
                        {
                            inter = 4;
                        }
                    }
                }
            }

            // Check if the center point of each
            // rectangle lies within the polygon
            for (i = 0; i < result.Count;)
            {
                PointF pt1 = result[i];
                PointF pt2 = result[i + 1];
                PointF ptc = PointF.Empty;

                ptc.X = (pt1.X + pt2.X) / 2 + _bounds.Left;
                ptc.Y = (pt1.Y + pt2.Y) / 2 + _bounds.Top;

                if (!_polygon.Contains(ptc))
                {
                    result.RemoveAt(i);
                    result.RemoveAt(i);
                }
                else
                {
                    i += 2;
                }
            }

            return(result);
        }