Exemplo n.º 1
0
        public static MathListIndex IndexForPoint <TFont, TGlyph>(this TextLineDisplay <TFont, TGlyph> self, TypesettingContext <TFont, TGlyph> context, PointF point) where TFont : IFont <TGlyph>
        {
            // Convert the point to the reference of the CTLine
            var relativePoint   = new PointF(point.X - self.Position.X, point.Y - self.Position.Y);
            var runsAndIndicies =
                self.Runs
                .Select(run => ValueTuple.Create(run, run.Run.GlyphIndexForXOffset(context, relativePoint.Plus(run.Position).X)))
                .Where(x => x.Item2.HasValue)
                .ToArray();

            if (runsAndIndicies.Length == 0)
            {
                return(null);
            }
            var(r, nindex) = runsAndIndicies.Single();
            var index   = nindex.GetValueOrDefault();
            var diffLng = r.Run.Length != r.Range.Length;

            if (index < 0 || (!diffLng && index > self.Range.Length) || (diffLng && index > r.Run.Length))
            {
                throw new InvalidCodePathException($"Returned index out of range: {index}, range ({self.Range.Location}, {self.Range.Length})");
            }
            if (!diffLng)
            {
                return(MathListIndex.Level0Index(self.Range.Location + index));
            }
            if (index > r.Run.Length / 2)
            {
                return(MathListIndex.Level0Index(self.Range.End));
            }

            return(MathListIndex.Level0Index(self.Range.Location));
        }
        public static int MathListIndexToStringIndex <TFont, TGlyph>(this TextLineDisplay <TFont, TGlyph> self, int mlIndex) where TFont : IFont <TGlyph>
        {
            if (mlIndex >= self.Atoms.Length)
            {
                throw ArgOutOfRange($"The index is not in the range {self.Atoms.Length}", mlIndex, nameof(mlIndex));
            }
            int strIndex = 0;

            for (int i = 0; i < mlIndex; i++)
            {
                strIndex += self.Atoms[i].Nucleus.Length;
            }
            return(strIndex);
        }
        // Convert the index into the current string to an index into the mathlist. These may not be the same since a single
        // math atom may have multiple characters.
        public static int StringIndexToMathListIndex <TFont, TGlyph>(this TextLineDisplay <TFont, TGlyph> self, int strIndex) where TFont : IFont <TGlyph>
        {
            int strLenCovered = 0;

            for (int mlIndex = 0; mlIndex < self.Atoms.Length; mlIndex++)
            {
                if (strLenCovered >= strIndex)
                {
                    return(mlIndex);
                }
                strLenCovered += self.Atoms[mlIndex].Nucleus.Length;
            }
            if (strLenCovered < strIndex)
            {
                throw new InvalidCodePathException("StrIndex should not be more than the len covered");
            }
            return(self.Atoms.Length);
        }
        public static MathListIndex IndexForPoint <TFont, TGlyph>(this TextLineDisplay <TFont, TGlyph> self, TypesettingContext <TFont, TGlyph> context, PointF point) where TFont : IFont <TGlyph>
        {
            // Convert the point to the reference of the CTLine
            var relativePoint = new PointF(point.X - self.Position.X, point.Y - self.Position.Y);
            var indices       = self.Runs.Select(run => run.Run.GlyphIndexForXOffset(context, relativePoint.Plus(run.Position).X)).Where(x => x.HasValue);

            if (indices.IsEmpty())
            {
                return(null);
            }
            var index = indices.Single().GetValueOrDefault();
            // The index returned is in UTF-16, translate to codepoint index.
            // NSUInteger codePointIndex = stringIndexToCodePointIndex(self.attributedString.string, index);
            // Convert the code point index to an index into the mathlist
            var mlIndex = self.StringIndexToMathListIndex(index);

            // index will be between 0 and _range.length inclusive
            if (mlIndex < 0 || mlIndex > self.Range.Length)
            {
                throw new InvalidCodePathException($"Returned index out of range: {index}, range ({self.Range.Location}, {self.Range.Length})");
            }
            // translate to the current index
            return(MathListIndex.Level0Index(self.Range.Location + mlIndex));
        }
 public static (TextRunDisplay <TFont, TGlyph> run, int charIndex) GetRunAndCharIndexFromStringIndex <TFont, TGlyph>(this TextLineDisplay <TFont, TGlyph> self, int lineCharIndex) where TFont : IFont <TGlyph>
Exemplo n.º 6
0
 [System.Diagnostics.DebuggerStepThrough] // Debugger should stop at the line that uses this function
 void AssertText(string expected, TextLineDisplay <TFont, TGlyph> actual) =>
 Assert.Equal(expected, string.Concat(actual.Text));
Exemplo n.º 7
0
 public static string StringText(this TextLineDisplay <FrontEnd.TestMathFont, char> display)
 => new string(display.Text.ToArray());
 public static string StringText(this TextLineDisplay <MathFont <char>, char> display)
 => new string(display.Text.ToArray());
Exemplo n.º 9
0
this TextLineDisplay <TFont, TGlyph> self, int lineCharIndex) where TFont : IFont <TGlyph>