예제 #1
0
        /// <summary>
        ///   Get the index of the character at position pos
        /// </summary>
        /// <param name="pos">the position of the character within the text draw area</param>
        /// <param name="text"></param>
        /// <param name="lines"></param>
        /// <param name="horzFormat"></param>
        /// <param name="vertFormat"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="leftToRight"></param>
        /// <returns></returns>
        public int GetTextIndexFromPosition(PointF pos, string text,
                                            List <TextRange> lines,
                                            HorizontalTextFormat horzFormat,
                                            VerticalTextFormat vertFormat,
                                            float width, float height,
                                            bool leftToRight)
        {
            float y      = GetTextStartOffset(lines.Count, 0, vertFormat, height);
            float deltaY = pos.Y - y;

            if (deltaY < 0)
            {
                return(0);
            }
            int lineIndex = (int)(deltaY / this.LineSpacing);

            if (lineIndex >= lines.Count)
            {
                return(text.Length);
            }
            float x      = GetTextStartOffset(text, lines[lineIndex], horzFormat, width, leftToRight);
            float deltaX = pos.X - x;

            if (!leftToRight)
            {
                throw new NotImplementedException("rightToLeft layout not fully supported");
            }
            if (deltaX < 0)
            {
                return(lines[lineIndex].start);
            }
            return(GetCharAtPixel(text, lines[lineIndex].start, lines[lineIndex].end - lines[lineIndex].start, deltaX));
        }
예제 #2
0
        /// <summary>
        ///  Gets the offset into the rectangle of the top left (or top right
        ///  if right to left) for the character at textIndex.
        /// </summary>
        /// <param name="textIndex"></param>
        /// <returns></returns>
        public PointF GetOffset(string text, List <TextRange> lines,
                                int textIndex,
                                HorizontalTextFormat horzFormat,
                                VerticalTextFormat vertFormat,
                                float width, float height, bool leftToRight)
        {
            int lineIndex = GetLineIndex(lines, textIndex);

            if (lineIndex == -1)
            {
                throw new Exception("Invalid text index");
            }
            TextRange line = lines[lineIndex];
            PointF    rv   = new PointF();

            // Get the top left of the text area
            rv.X = GetTextStartOffset(text, line, horzFormat, width, leftToRight);
            rv.Y = GetTextStartOffset(lines.Count, lineIndex, vertFormat, height);
            // Move to the left past some characters
            if (textIndex > line.end)
            {
                textIndex = line.end;
            }
            rv.X += GetTextExtent(text, line.start, textIndex - line.start);
            return(rv);
        }
예제 #3
0
        /// <summary>
        ///		Draw text into a specified area of the display.
        /// </summary>
        /// <param name="text">The text to be drawn.</param>
        /// <param name="area">
        ///		Rect object describing the area of the display where the text is to be rendered.  The text is not clipped to this Rect, but is formatted
        ///		using this Rect depending upon the option specified in <paramref name="format"/>.
        /// </param>
        /// <param name="z">float value specifying the z co-ordinate for the drawn text.</param>
        /// <param name="clip">Rect object describing the clipping area for the drawing.  No drawing will occur outside this Rect.</param>
        /// <param name="format">The text formatting required.</param>
        /// <param name="colors">
        ///		ColorRect object describing the colors to be applied when drawing the text.
        ///		The colors specified in here are applied to each glyph, rather than the text as a whole.
        /// </param>
        /// <returns>The number of lines output.  This does not consider clipping, so if all text was clipped, this would still return >=1.</returns>
        public int DrawText(string text, Rect area, float z, Rect clip,
                            HorizontalTextFormat horzFormat,
                            VerticalTextFormat vertFormat,
                            ColorRect colors)
        {
            List <TextRange> lines = GetLines(text, area.Width, horzFormat, false);

            return(DrawText(text, lines, area, z, clip, horzFormat, vertFormat, colors));
        }
예제 #4
0
        public List <TextRange> GetLines(string text, float wrapWidth, HorizontalTextFormat format, bool nonSpaceWrap)
        {
            switch (format)
            {
            case HorizontalTextFormat.Left:
            case HorizontalTextFormat.Right:
            case HorizontalTextFormat.Centered:
                return(TextWrapHelper.GetLines(text));

            case HorizontalTextFormat.WordWrapLeft:
            case HorizontalTextFormat.WordWrapRight:
            case HorizontalTextFormat.WordWrapCentered:
                return(TextWrapHelper.GetWrappedLines(this, text, wrapWidth, nonSpaceWrap));

            default:
                throw new NotImplementedException(string.Format("Unknown text format option '{0}'", format));
            }
        }
예제 #5
0
        /// <summary>
        ///   Return the horizontal pixel extent given text would be formatted to.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="formatArea"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public float GetFormattedTextExtent(string text, Rect area, HorizontalTextFormat format)
        {
            float  lineWidth;
            float  widest = 0;
            int    lineStart = 0, lineEnd = 0;
            string currLine;

            Rect tmpDrawArea = area;

            while (lineEnd < text.Length)
            {
                if ((lineEnd = text.IndexOf('\n', lineStart)) == -1)
                {
                    lineEnd = text.Length;
                }
                currLine  = text.Substring(lineStart, lineEnd - lineStart);
                lineStart = lineEnd + 1;                // +1 to skip \n char

                switch (format)
                {
                case HorizontalTextFormat.Centered:
                case HorizontalTextFormat.Right:
                case HorizontalTextFormat.Left:
                    lineWidth = GetTextExtent(currLine);
                    break;

                case HorizontalTextFormat.WordWrapLeft:
                case HorizontalTextFormat.WordWrapRight:
                case HorizontalTextFormat.WordWrapCentered:
                    lineWidth = GetWrappedTextExtent(currLine, area.Width, false);
                    break;

                default:
                    throw new NotImplementedException("Font.GetFormattedTextExtent - Unknown or unsupported TextFormatting value specified.");
                }

                if (lineWidth > widest)
                {
                    widest = lineWidth;
                }
            }

            return(widest);
        }
예제 #6
0
        protected float GetTextStartOffset(string text, TextRange line,
                                           HorizontalTextFormat format,
                                           float width, bool leftToRight)
        {
            float baseX = 0;

            switch (format)
            {
            case HorizontalTextFormat.Left:
            case HorizontalTextFormat.WordWrapLeft:
                if (!leftToRight)
                {
                    baseX += GetTextExtent(text, line.start, line.Length);
                }
                break;

            case HorizontalTextFormat.Right:
            case HorizontalTextFormat.WordWrapRight:
                baseX = width;
                if (leftToRight)
                {
                    baseX -= GetTextExtent(text, line.start, line.Length);
                }
                break;

            case HorizontalTextFormat.Centered:
            case HorizontalTextFormat.WordWrapCentered:
                if (leftToRight)
                {
                    baseX = (float)Math.Floor((width - GetTextExtent(text, line.start, line.Length)) * 0.5f);
                }
                else
                {
                    baseX = width - (float)Math.Floor((width - GetTextExtent(text, line.start, line.Length)) * 0.5f);
                }
                break;

            default:
                throw new NotImplementedException(string.Format("Unknown text format option '{0}'", format));
            }
            return(baseX);
        }
예제 #7
0
 /// <summary>
 ///		Draw text into a specified area of the display.
 /// </summary>
 /// <param name="text">The text to be drawn.</param>
 /// <param name="area">
 ///		Rect object describing the area of the display where the text is to be rendered.  The text is not clipped to this Rect, but is formatted
 ///		using this Rect depending upon the option specified in <paramref name="format"/>.
 /// </param>
 /// <param name="z">float value specifying the z co-ordinate for the drawn text.</param>
 /// <param name="clip">Rect object describing the clipping area for the drawing.  No drawing will occur outside this Rect.</param>
 /// <param name="format">The text formatting required.</param>
 /// <param name="colors">
 ///		ColorRect object describing the colors to be applied when drawing the text.
 ///		The colors specified in here are applied to each glyph, rather than the text as a whole.
 /// </param>
 /// <returns>The number of lines output.  This does not consider clipping, so if all text was clipped, this would still return >=1.</returns>
 public int DrawText(string text, List <TextRange> lines, Rect area, float z, Rect clip, HorizontalTextFormat horzFormat, VerticalTextFormat vertFormat, ColorRect colors)
 {
     foreach (TextRange line in lines)
     {
         PointF offset = GetOffset(text, lines, line.start, horzFormat, vertFormat, area.Width, area.Height, leftToRight);
         DrawTextLine(text, line.start, line.Length,
                      new Vector3(area.Left + offset.X, area.Top + offset.Y, z),
                      clip, colors);
     }
     return(lines.Count);
 }
예제 #8
0
        public float GetFormattedLineCount(string text, Rect area, HorizontalTextFormat format)
        {
            List <TextRange> lines = GetLines(text, area.Width, format, false);

            return(lines.Count);
        }
 /// <summary>
 ///		Draw text into a specified area of the display.
 /// </summary>
 /// <param name="text">The text to be drawn.</param>
 /// <param name="area">
 ///		Rect object describing the area of the display where the text is to be rendered.  The text is not clipped to this Rect, but is formatted
 ///		using this Rect depending upon the option specified in <paramref name="format"/>.
 /// </param>
 /// <param name="z">float value specifying the z co-ordinate for the drawn text.</param>
 /// <param name="clip">Rect object describing the clipping area for the drawing.  No drawing will occur outside this Rect.</param>
 /// <param name="format">The text formatting required.</param>
 /// <param name="colors">
 ///		ColorRect object describing the colors to be applied when drawing the text.
 ///		The colors specified in here are applied to each glyph, rather than the text as a whole.
 /// </param>
 /// <returns>The number of lines output.  This does not consider clipping, so if all text was clipped, this would still return >=1.</returns>
 public int DrawText(string text, List<TextRange> lines, Rect area, float z, Rect clip, HorizontalTextFormat horzFormat, VerticalTextFormat vertFormat, ColorRect colors)
 {
     foreach (TextRange line in lines) {
         PointF offset = GetOffset(text, lines, line.start, horzFormat, vertFormat, area.Width, area.Height, leftToRight);
         DrawTextLine(text, line.start, line.Length,
                      new Vector3(area.Left + offset.X, area.Top + offset.Y, z),
                      clip, colors);
     }
     return lines.Count;
 }
예제 #10
0
 protected float GetTextStartOffset(string text, TextRange line, 
                                    HorizontalTextFormat format, 
                                    float width, bool leftToRight)
 {
     float baseX = 0;
     switch (format) {
         case HorizontalTextFormat.Left:
         case HorizontalTextFormat.WordWrapLeft:
             if (!leftToRight)
                 baseX += GetTextExtent(text, line.start, line.Length);
             break;
         case HorizontalTextFormat.Right:
         case HorizontalTextFormat.WordWrapRight:
             baseX = width;
             if (leftToRight)
                 baseX -= GetTextExtent(text, line.start, line.Length);
             break;
         case HorizontalTextFormat.Centered:
         case HorizontalTextFormat.WordWrapCentered:
             if (leftToRight)
                 baseX = (float)Math.Floor((width - GetTextExtent(text, line.start, line.Length)) * 0.5f);
             else
                 baseX = width - (float)Math.Floor((width - GetTextExtent(text, line.start, line.Length)) * 0.5f);
             break;
         default:
             throw new NotImplementedException(string.Format("Unknown text format option '{0}'", format));
     }
     return baseX;
 }
예제 #11
0
 public List<TextRange> GetLines(string text, float wrapWidth, HorizontalTextFormat format, bool nonSpaceWrap)
 {
 }
예제 #12
0
 public float GetFormattedLineCount(string text, Rect area, HorizontalTextFormat format)
 {
 }
예제 #13
0
 /// <summary>
 ///   Get the index of the character at position pos
 /// </summary>
 /// <param name="pos">the position of the character within the text draw area</param>
 /// <param name="text"></param>
 /// <param name="lines"></param>
 /// <param name="horzFormat"></param>
 /// <param name="vertFormat"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="leftToRight"></param>
 /// <returns></returns>
 public int GetTextIndexFromPosition(PointF pos, string text, 
                                     List<TextRange> lines,
                                     HorizontalTextFormat horzFormat,
                                     VerticalTextFormat vertFormat,
                                     float width, float height, 
                                     bool leftToRight)
 {
     float y = GetTextStartOffset(lines.Count, 0, vertFormat, height);
     float deltaY = pos.Y - y;
     if (deltaY < 0)
         return 0;
     int lineIndex = (int)(deltaY / this.LineSpacing);
     if (lineIndex >= lines.Count)
         return text.Length;
     float x = GetTextStartOffset(text, lines[lineIndex], horzFormat, width, leftToRight);
     float deltaX = pos.X - x;
     if (!leftToRight)
         throw new NotImplementedException("rightToLeft layout not fully supported");
     if (deltaX < 0)
         return lines[lineIndex].start;
     return GetCharAtPixel(text, lines[lineIndex].start, lines[lineIndex].end - lines[lineIndex].start, deltaX);
 }
예제 #14
0
 /// <summary>
 ///  Gets the offset into the rectangle of the top left (or top right 
 ///  if right to left) for the character at textIndex.
 /// </summary>
 /// <param name="textIndex"></param>
 /// <returns></returns>
 public PointF GetOffset(string text, List<TextRange> lines, 
                        int textIndex,
                        HorizontalTextFormat horzFormat, 
                        VerticalTextFormat vertFormat, 
                        float width, float height, bool leftToRight)
 {
     int lineIndex = GetLineIndex(lines, textIndex);
     if (lineIndex == -1)
         throw new Exception("Invalid text index");
     TextRange line = lines[lineIndex];
     PointF rv = new PointF();
     // Get the top left of the text area
     rv.X = GetTextStartOffset(text, line, horzFormat, width, leftToRight);
     rv.Y = GetTextStartOffset(lines.Count, lineIndex, vertFormat, height);
     // Move to the left past some characters
     if (textIndex > line.end)
         textIndex = line.end;
     rv.X += GetTextExtent(text, line.start, textIndex - line.start);
     return rv;
 }
예제 #15
0
 public List<TextRange> GetLines(string text, float wrapWidth, HorizontalTextFormat format, bool nonSpaceWrap)
 {
     switch (format) {
         case HorizontalTextFormat.Left:
         case HorizontalTextFormat.Right:
         case HorizontalTextFormat.Centered:
             return TextWrapHelper.GetLines(text);
         case HorizontalTextFormat.WordWrapLeft:
         case HorizontalTextFormat.WordWrapRight:
         case HorizontalTextFormat.WordWrapCentered:
             return TextWrapHelper.GetWrappedLines(this, text, wrapWidth, nonSpaceWrap);
         default:
             throw new NotImplementedException(string.Format("Unknown text format option '{0}'", format));
     }
 }
예제 #16
0
 public float GetFormattedLineCount(string text, Rect area, HorizontalTextFormat format)
 {
     List<TextRange> lines = GetLines(text, area.Width, format, false);
     return lines.Count;
 }
예제 #17
0
 public List <TextRange> GetLines(string text, float wrapWidth, HorizontalTextFormat format, bool nonSpaceWrap)
 {
 }
예제 #18
0
        /// <summary>
        ///   Return the horizontal pixel extent given text would be formatted to.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="formatArea"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public float GetFormattedTextExtent(string text, Rect area, HorizontalTextFormat format)
        {
            float lineWidth;
            float widest = 0;
            int lineStart = 0, lineEnd = 0;
            string currLine;

            Rect tmpDrawArea = area;

            while (lineEnd < text.Length) {
                if ((lineEnd = text.IndexOf('\n', lineStart)) == -1)
                    lineEnd = text.Length;
                currLine = text.Substring(lineStart, lineEnd - lineStart);
                lineStart = lineEnd + 1;		// +1 to skip \n char

                switch (format) {
                    case HorizontalTextFormat.Centered:
                    case HorizontalTextFormat.Right:
                    case HorizontalTextFormat.Left:
                        lineWidth = GetTextExtent(currLine);
                        break;

                    case HorizontalTextFormat.WordWrapLeft:
                    case HorizontalTextFormat.WordWrapRight:
                    case HorizontalTextFormat.WordWrapCentered:
                        lineWidth = GetWrappedTextExtent(currLine, area.Width, false);
                        break;

                    default:
                        throw new NotImplementedException("Font.GetFormattedTextExtent - Unknown or unsupported TextFormatting value specified.");
                }

                if (lineWidth > widest)
                    widest = lineWidth;
            }

            return widest;
        }
예제 #19
0
 public float GetFormattedLineCount(string text, Rect area, HorizontalTextFormat format)
 {
 }
예제 #20
0
 /// <summary>
 ///		Draw text into a specified area of the display.
 /// </summary>
 /// <param name="text">The text to be drawn.</param>
 /// <param name="area">
 ///		Rect object describing the area of the display where the text is to be rendered.  The text is not clipped to this Rect, but is formatted
 ///		using this Rect depending upon the option specified in <paramref name="format"/>.
 /// </param>
 /// <param name="z">float value specifying the z co-ordinate for the drawn text.</param>
 /// <param name="clip">Rect object describing the clipping area for the drawing.  No drawing will occur outside this Rect.</param>
 /// <param name="format">The text formatting required.</param>
 /// <param name="colors">
 ///		ColorRect object describing the colors to be applied when drawing the text.
 ///		The colors specified in here are applied to each glyph, rather than the text as a whole.
 /// </param>
 /// <returns>The number of lines output.  This does not consider clipping, so if all text was clipped, this would still return >=1.</returns>
 public int DrawText(string text, Rect area, float z, Rect clip, 
                     HorizontalTextFormat horzFormat, 
                     VerticalTextFormat vertFormat, 
                     ColorRect colors)
 {
     List<TextRange> lines = GetLines(text, area.Width, horzFormat, false);
     return DrawText(text, lines, area, z, clip, horzFormat, vertFormat, colors);
 }