예제 #1
0
		// Token: 0x06002D3B RID: 11579 RVA: 0x000CC368 File Offset: 0x000CA568
		internal Rect ComputeDesignRect()
		{
			Glyphs glyphs = this._element as Glyphs;
			if (glyphs == null)
			{
				Image image = this._element as Image;
				if (image != null && image.Source != null)
				{
					return new Rect(0.0, 0.0, image.Width, image.Height);
				}
				Path path = this._element as Path;
				if (path != null)
				{
					return path.Data.Bounds;
				}
				return Rect.Empty;
			}
			else
			{
				GlyphRun measurementGlyphRun = glyphs.MeasurementGlyphRun;
				if (measurementGlyphRun == null || this._gBeginOffset >= this._gEndOffset)
				{
					return Rect.Empty;
				}
				Rect result = measurementGlyphRun.ComputeAlignmentBox();
				result.Offset(glyphs.OriginX, glyphs.OriginY);
				int num = (measurementGlyphRun.Characters == null) ? 0 : measurementGlyphRun.Characters.Count;
				double num2 = measurementGlyphRun.GetDistanceFromCaretCharacterHit(new CharacterHit(this._gBeginOffset, 0));
				double num3;
				if (this._gEndOffset == num)
				{
					num3 = measurementGlyphRun.GetDistanceFromCaretCharacterHit(new CharacterHit(num - 1, 1));
				}
				else
				{
					num3 = measurementGlyphRun.GetDistanceFromCaretCharacterHit(new CharacterHit(this._gEndOffset, 0));
				}
				if (num3 < num2)
				{
					double num4 = num2;
					num2 = num3;
					num3 = num4;
				}
				double width = num3 - num2;
				if ((measurementGlyphRun.BidiLevel & 1) != 0)
				{
					result.X = glyphs.OriginX - num3;
				}
				else
				{
					result.X = glyphs.OriginX + num2;
				}
				result.Width = width;
				return result;
			}
		}
        // Token: 0x06002EF3 RID: 12019 RVA: 0x000D43E0 File Offset: 0x000D25E0
        private static double _GetDistanceToCharacter(GlyphRun run, int charOffset)
        {
            int num            = charOffset;
            int trailingLength = 0;
            int num2           = (run.Characters == null) ? 0 : run.Characters.Count;

            if (num == num2)
            {
                num--;
                trailingLength = 1;
            }
            return(run.GetDistanceFromCaretCharacterHit(new CharacterHit(num, trailingLength)));
        }
예제 #3
0
        private static double _GetDistanceToCharacter(GlyphRun run, int charOffset)
        {
            int firstChar = charOffset, trailingLength = 0;

            int characterCount = (run.Characters == null) ? 0 : run.Characters.Count;

            if (firstChar == characterCount)
            {
                // place carat at end of previous character to make sure it works at end of line
                firstChar--;
                trailingLength = 1;
            }

            return(run.GetDistanceFromCaretCharacterHit(new CharacterHit(firstChar, trailingLength)));
        }
        //--------------------------------------------------------------------
        //
        // Public Properties
        //
        //---------------------------------------------------------------------


        //--------------------------------------------------------------------
        //
        // Public Events
        //
        //---------------------------------------------------------------------


        //--------------------------------------------------------------------
        //
        // Internal Methods
        //
        //---------------------------------------------------------------------

        #region Internal Methods

        // Compute the rectangle that covers this highlight
        internal Rect ComputeDesignRect()
        {
            Glyphs g = _element as Glyphs;

            if (g == null)
            {
                Image im = _element as Image;
                if (im != null && im.Source != null)
                {
                    return(new Rect(0, 0, im.Width, im.Height));
                }
                else
                {
                    Path p = _element as Path;
                    if (p != null)
                    {
                        return(p.Data.Bounds);
                    }
                }

                return(Rect.Empty);
            }

            GlyphRun run = g.MeasurementGlyphRun; // g.ToGlyphRun();

            if (run == null || _gBeginOffset >= _gEndOffset)
            {
                return(Rect.Empty);
            }

            Rect designRect = run.ComputeAlignmentBox();

            designRect.Offset(g.OriginX, g.OriginY);

            int chrct = (run.Characters == null ? 0 : run.Characters.Count);

            Debug.Assert(_gBeginOffset >= 0);
            Debug.Assert(_gEndOffset <= chrct);

            double x1, x2, width;

            x1 = run.GetDistanceFromCaretCharacterHit(new CharacterHit(_gBeginOffset, 0));

            if (_gEndOffset == chrct)
            {
                x2 = run.GetDistanceFromCaretCharacterHit(new CharacterHit(chrct - 1, 1));
            }
            else
            {
                x2 = run.GetDistanceFromCaretCharacterHit(new CharacterHit(_gEndOffset, 0));
            }

            if (x2 < x1)
            {
                double temp = x1;
                x1 = x2;
                x2 = temp;
            }
            width = x2 - x1;

            if ((run.BidiLevel & 1) != 0)
            {
                // right to left
                designRect.X = g.OriginX - x2;
            }
            else
            {
                designRect.X = g.OriginX + x1;
            }

            designRect.Width = width;

#if DEBUG
            DocumentsTrace.FixedTextOM.Highlight.Trace(string.Format("DesignBound {0}", designRect));
#endif
            return(designRect);
        }