Moved TextExtents to OpenTK.Graphics.

Added documentation to all public classes and interfaces.
This commit is contained in:
the_fiddler 2009-02-12 23:10:09 +00:00
parent c18b522763
commit 538198776b
4 changed files with 235 additions and 18 deletions

View file

@ -17,19 +17,125 @@ namespace OpenTK.Graphics
/// </summary>
public interface ITextPrinter : IDisposable
{
void Begin();
void End();
#region Print
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
void Print(string text, Font font, Color color);
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
void Print(string text, Font font, Color color, RectangleF rect);
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options);
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment);
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to print text.</param>
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction);
#endregion
#region Measure
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
TextExtents Measure(string text, Font font);
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
TextExtents Measure(string text, Font font, RectangleF rect);
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options);
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment);
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to measure text.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction);
#endregion
#region Obsolete
[Obsolete]
void Begin();
[Obsolete]
void End();
[Obsolete("Use TextPrinter.Print instead")]
void Draw(TextHandle handle);
@ -38,5 +144,7 @@ namespace OpenTK.Graphics
[Obsolete("Use TextPrinter.Print instead")]
void Prepare(string text, TextureFont font, out TextHandle handle);
#endregion
}
}

View file

@ -30,9 +30,11 @@ using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace OpenTK.Graphics.Text
namespace OpenTK.Graphics
{
// Holds layout information about a TextBlock.
/// <summary>
/// Holds the results of a text measurement.
/// </summary>
public class TextExtents : IDisposable
{
#region Fields
@ -54,39 +56,42 @@ namespace OpenTK.Graphics.Text
#region Public Members
/// <summary>
/// Gets the bounding box of the measured text.
/// </summary>
public RectangleF BoundingBox
{
get { return text_extents; }
internal set { text_extents = value; }
}
/// <summary>
/// Gets the extents of each glyph in the measured text.
/// </summary>
/// <param name="i">The index of the glyph.</param>
/// <returns>The extents of the specified glyph.</returns>
public RectangleF this[int i]
{
get { return glyph_extents[i]; }
internal set { glyph_extents[i] = value; }
}
/// <summary>
/// Gets the extents of each glyph in the measured text.
/// </summary>
public IEnumerable<RectangleF> GlyphExtents
{
get
{
return (IEnumerable<RectangleF>)glyph_extents;
}
get { return (IEnumerable<RectangleF>)glyph_extents; }
}
/// <summary>
/// Gets the number of the measured glyphs.
/// </summary>
public int Count
{
get { return glyph_extents.Count; }
}
public TextExtents Clone()
{
TextExtents extents = new TextExtents();
extents.glyph_extents.AddRange(GlyphExtents);
extents.BoundingBox = BoundingBox;
return extents;
}
#endregion
#region Internal Members
@ -107,10 +112,21 @@ namespace OpenTK.Graphics.Text
glyph_extents.Clear();
}
internal TextExtents Clone()
{
TextExtents extents = new TextExtents();
extents.glyph_extents.AddRange(GlyphExtents);
extents.BoundingBox = BoundingBox;
return extents;
}
#endregion
#region IDisposable Members
/// <summary>
/// Frees the resources consumed by this TextExtents instance.
/// </summary>
public virtual void Dispose()
{
}

View file

@ -41,11 +41,15 @@ namespace OpenTK.Graphics
#region Constructors
/// <summary>
/// Constructs a new TextPrinter object.
/// Constructs a new TextPrinter instance.
/// </summary>
public TextPrinter()
: this(null, null, TextQuality.Default) { }
/// <summary>
/// Constructs a new TextPrinter instance with the specified TextQuality level.
/// </summary>
/// <param name="quality">The desired TextQuality of this TextPrinter.</param>
public TextPrinter(TextQuality quality)
: this(null, null, quality) { }
@ -62,26 +66,66 @@ namespace OpenTK.Graphics
#region Print
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
public void Print(string text, Font font, Color color)
{
Print(text, font, color, RectangleF.Empty, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
}
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
public void Print(string text, Font font, Color color, RectangleF rect)
{
Print(text, font, color, rect, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
}
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options)
{
Print(text, font, color, rect, options, TextAlignment.Near, TextDirection.LeftToRight);
}
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment)
{
Print(text, font, color, rect, options, alignment, TextDirection.LeftToRight);
}
/// <summary>
/// Prints text using the specified color and layout options.
/// </summary>
/// <param name="text">The System.String to print.</param>
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to print text.</param>
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
{
if (disposed)
@ -97,27 +141,66 @@ namespace OpenTK.Graphics
#region Measure
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
public TextExtents Measure(string text, Font font)
{
return Measure(text, font, RectangleF.Empty, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
}
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
public TextExtents Measure(string text, Font font, RectangleF rect)
{
return Measure(text, font, rect, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
}
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options)
{
return Measure(text, font, rect, options, TextAlignment.Near, TextDirection.LeftToRight);
}
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment)
{
return Measure(text, font, rect, options, alignment, TextDirection.LeftToRight);
}
/// <summary>
/// Measures text using the specified layout options.
/// </summary>
/// <param name="text">The System.String to measure.</param>
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to measure text.</param>
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
{
if (disposed)
@ -260,6 +343,9 @@ namespace OpenTK.Graphics
#region IDisposable Members
/// <summary>
/// Frees the resources consumed by this TextPrinter object.
/// </summary>
public void Dispose()
{
if (!disposed)

View file

@ -4,11 +4,18 @@ using System.Text;
namespace OpenTK.Graphics
{
/// <summary>
/// Defines available quality levels for text printing.
/// </summary>
public enum TextQuality
{
/// <summary>Use the default quality, as specified by the operating system.</summary>
Default = 0,
/// <summary>Use fast, low quality text (typically non-antialiased) .</summary>
Low,
/// <summary>Use medium quality text (typically grayscale antialiased).</summary>
Medium,
/// <summary>Use slow, high quality text (typically subpixel antialiased).</summary>
High
}
}