Ejemplo n.º 1
0
        internal void RenderLines(DrawingContext dc)
        {
            for (int i = 0; i < _lineResults.Length; i++)
            {
                FixedLineResult lineResult = _lineResults[i];

                Pen  pen       = new Pen(Brushes.Red, 1);
                Rect layoutBox = lineResult.LayoutBox;
                dc.DrawRectangle(null, pen, layoutBox);

                CultureInfo   EnglishCulture = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;
                FixedPage     fp             = _fixedTextBuilder.FixedTextContainer.FixedDocument.GetFixedPage(PageIndex);
                FormattedText ft             = new FormattedText(i.ToString(),
                                                                 EnglishCulture,
                                                                 FlowDirection.LeftToRight,
                                                                 new Typeface("Arial"),
                                                                 10,
                                                                 Brushes.White,
                                                                 fp.GetDpi().PixelsPerDip);
                Point    labelLocation = new Point(layoutBox.Left - 25, (layoutBox.Bottom + layoutBox.Top) / 2 - 10);
                Geometry geom          = ft.BuildHighlightGeometry(labelLocation);
                Pen      backgroundPen = new Pen(Brushes.Black, 1);
                dc.DrawGeometry(Brushes.Black, backgroundPen, geom);
                dc.DrawText(ft, labelLocation);
            }
        }
Ejemplo n.º 2
0
        //
        /// <summary>
        /// If the point is in one of the lines, return that line.
        /// Otherwise, return the line with smallest (modified) manhattan distance.
        /// </summary>
        /// <param name="pt"></param>
        /// <returns></returns>
        internal FixedNode[] FindSnapToLine(Point pt)
        {
            Debug.Assert(_lineResults != null);
            FixedLineResult closestLine      = null;
            FixedLineResult closestManhattan = null;
            double          minVerDistance   = double.MaxValue;
            double          minHorDistance   = double.MaxValue;
            double          minManhattan     = double.MaxValue;

            foreach (FixedLineResult lineResult in _lineResults)
            {
                double absVerDistance = Math.Max(0, (pt.Y > lineResult.LayoutBox.Y) ? (pt.Y - lineResult.LayoutBox.Bottom) : (lineResult.LayoutBox.Y - pt.Y));
                double absHorDistance = Math.Max(0, (pt.X > lineResult.LayoutBox.X) ? (pt.X - lineResult.LayoutBox.Right) : (lineResult.LayoutBox.X - pt.X));
                if (absVerDistance == 0 && absHorDistance == 0)
                {
                    return(lineResult.Nodes);
                }

                //Update the closest line information. We need this if we can't find a close line below the point
                if (absVerDistance < minVerDistance || (absVerDistance == minVerDistance && absHorDistance < minHorDistance))
                {
                    minVerDistance = absVerDistance;
                    minHorDistance = absHorDistance;
                    closestLine    = lineResult;
                }
                //Update closest manhattan.  We decide which metric to choose later.
                double manhattan = 5 * absVerDistance + absHorDistance;
                //Consider removing second condition, or perhaps come up with an exponential weighting for vertical.
                if (manhattan < minManhattan && absVerDistance < lineResult.LayoutBox.Height)
                {
                    minManhattan     = manhattan;
                    closestManhattan = lineResult;
                }
            }
            //We couldn't find the next line below. Return the closest line in this case

            if (closestLine != null)
            {
                if (closestManhattan != null && (closestManhattan.LayoutBox.Left > closestLine.LayoutBox.Right || closestLine.LayoutBox.Left > closestManhattan.LayoutBox.Right))
                {
                    // they don't overlap, so go with closer one
                    return(closestManhattan.Nodes);
                }

                // no manhattan, or they overlap/are in same column

                return(closestLine.Nodes);
            }

            return(null);
        }
Ejemplo n.º 3
0
        //--------------------------------------------------------------------
        //
        // Public Methods
        //
        //---------------------------------------------------------------------

        // IComparable Override
        public int CompareTo(object o)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }

            if (o.GetType() != typeof(FixedLineResult))
            {
                throw new ArgumentException(SR.Get(SRID.UnexpectedParameterType, o.GetType(), typeof(FixedLineResult)), "o");
            }

            FixedLineResult lineResult = (FixedLineResult)o;

            return(this.BaseLine.CompareTo(lineResult.BaseLine));
        }
Ejemplo n.º 4
0
        // Token: 0x06002D96 RID: 11670 RVA: 0x000CD5D0 File Offset: 0x000CB7D0
        internal FixedNode[] FindSnapToLine(Point pt)
        {
            FixedLineResult fixedLineResult  = null;
            FixedLineResult fixedLineResult2 = null;
            double          num  = double.MaxValue;
            double          num2 = double.MaxValue;
            double          num3 = double.MaxValue;

            foreach (FixedLineResult fixedLineResult3 in this._lineResults)
            {
                double num4 = Math.Max(0.0, (pt.Y > fixedLineResult3.LayoutBox.Y) ? (pt.Y - fixedLineResult3.LayoutBox.Bottom) : (fixedLineResult3.LayoutBox.Y - pt.Y));
                double num5 = Math.Max(0.0, (pt.X > fixedLineResult3.LayoutBox.X) ? (pt.X - fixedLineResult3.LayoutBox.Right) : (fixedLineResult3.LayoutBox.X - pt.X));
                if (num4 == 0.0 && num5 == 0.0)
                {
                    return(fixedLineResult3.Nodes);
                }
                if (num4 < num || (num4 == num && num5 < num2))
                {
                    num             = num4;
                    num2            = num5;
                    fixedLineResult = fixedLineResult3;
                }
                double num6 = 5.0 * num4 + num5;
                if (num6 < num3 && num4 < fixedLineResult3.LayoutBox.Height)
                {
                    num3             = num6;
                    fixedLineResult2 = fixedLineResult3;
                }
            }
            if (fixedLineResult == null)
            {
                return(null);
            }
            if (fixedLineResult2 != null && (fixedLineResult2.LayoutBox.Left > fixedLineResult.LayoutBox.Right || fixedLineResult.LayoutBox.Left > fixedLineResult2.LayoutBox.Right))
            {
                return(fixedLineResult2.Nodes);
            }
            return(fixedLineResult.Nodes);
        }
Ejemplo n.º 5
0
        //--------------------------------------------------------------------
        // 
        // Public Properties 
        //
        //--------------------------------------------------------------------- 

        //--------------------------------------------------------------------
        //
        // Public Events 
        //
        //--------------------------------------------------------------------- 
 
        //-------------------------------------------------------------------
        // 
        // Internal Methods
        //
        //---------------------------------------------------------------------
 
        #region Internal Methods
 
        //------------------------------------- 
        // Line Detection
        //------------------------------------- 

        internal void SetupLineResults(FixedLineResult[] lineResults)
        {
            _lineResults = lineResults; 
#if DEBUG
            DocumentsTrace.FixedTextOM.Builder.Trace(string.Format("----LineResults Begin Dump-----\r\n")); 
            foreach(FixedLineResult lineResult in _lineResults) 
            {
                Debug.Assert(lineResult != null); 
                DocumentsTrace.FixedTextOM.Builder.Trace(string.Format("{0}\r\n", lineResult.ToString()));
            }
            DocumentsTrace.FixedTextOM.Builder.Trace(string.Format("----LineResults End Dump-----\r\n"));
#endif 
        }