mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-24 15:46:57 +00:00
Added TextAlignment and TextDirection enums.
Implemented RightToLeft and Vertical TextDirections (Vertical is glitchy). Implemented Near, Far and Center TextAlignments. Improved support for word wrapping. Removed alpha blending from GL11TextOutputProvider.
This commit is contained in:
parent
44240ad598
commit
522d1d17dc
|
@ -20,11 +20,15 @@ namespace OpenTK.Graphics
|
|||
void Begin();
|
||||
void End();
|
||||
void Print(string text, Font font, Color color);
|
||||
void Print(string text, Font font, Color color, SizeF size);
|
||||
void Print(string text, Font font, Color color, SizeF size, TextPrinterOptions options);
|
||||
void Print(string text, Font font, Color color, RectangleF rect);
|
||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options);
|
||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment);
|
||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction);
|
||||
TextExtents Measure(string text, Font font);
|
||||
TextExtents Measure(string text, Font font, SizeF size);
|
||||
TextExtents Measure(string text, Font font, SizeF size, TextPrinterOptions options);
|
||||
TextExtents Measure(string text, Font font, RectangleF rect);
|
||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options);
|
||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment);
|
||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction);
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
void Draw(TextHandle handle);
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
protected override void SetColor(Color color)
|
||||
{
|
||||
GL.Color4(color);
|
||||
GL.Color3(color);
|
||||
}
|
||||
|
||||
protected override TextQuality TextQuality
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
protected override void SetBlendFunction()
|
||||
{
|
||||
GL.BlendFunc(BlendingFactorSrc.ConstantColorExt, BlendingFactorDest.OneMinusSrcColor); // For subpixel with color
|
||||
GL.BlendFunc(BlendingFactorSrc.ConstantColorExt, BlendingFactorDest.OneMinusSrcColor);
|
||||
}
|
||||
|
||||
protected override void SetColor(Color color)
|
||||
|
|
|
@ -53,8 +53,12 @@ namespace OpenTK.Graphics.Text
|
|||
readonly ObjectPool<PoolableTextExtents> text_extents_pool = new ObjectPool<PoolableTextExtents>();
|
||||
|
||||
// Check the constructor, too, for additional flags.
|
||||
static readonly StringFormat default_string_format = StringFormat.GenericTypographic;
|
||||
static readonly StringFormat load_glyph_string_format = StringFormat.GenericDefault;
|
||||
// Used for measuring text. Can set the leftToRight, rightToLeft, vertical and measure trailing spaces flags.
|
||||
readonly StringFormat measure_string_format = new StringFormat(StringFormat.GenericDefault);
|
||||
readonly StringFormat measure_string_format_tight = new StringFormat(StringFormat.GenericTypographic);
|
||||
// Used for loading glyphs. Only use leftToRight!
|
||||
readonly StringFormat load_glyph_string_format = new StringFormat(StringFormat.GenericDefault);
|
||||
readonly StringFormat load_glyph_string_format_tight = new StringFormat(StringFormat.GenericTypographic);
|
||||
|
||||
static readonly char[] newline_characters = new char[] { '\n', '\r' };
|
||||
|
||||
|
@ -66,8 +70,6 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
static GdiPlusGlyphRasterizer()
|
||||
{
|
||||
default_string_format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
|
||||
|
||||
using (Bitmap bmp = new Bitmap(1, 1))
|
||||
using (System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(bmp))
|
||||
{
|
||||
|
@ -75,7 +77,11 @@ namespace OpenTK.Graphics.Text
|
|||
}
|
||||
}
|
||||
|
||||
public GdiPlusGlyphRasterizer() { }
|
||||
public GdiPlusGlyphRasterizer()
|
||||
{
|
||||
measure_string_format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoClip;
|
||||
measure_string_format_tight.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -93,11 +99,29 @@ namespace OpenTK.Graphics.Text
|
|||
EnsureSurfaceSize(ref glyph_surface, ref glyph_renderer, glyph.Font);
|
||||
SetTextRenderingOptions(glyph_renderer, glyph.Font, quality);
|
||||
|
||||
glyph_renderer.Clear(Color.Transparent);
|
||||
glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, PointF.Empty,
|
||||
glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : default_string_format);
|
||||
RectangleF r2 = new RectangleF();
|
||||
|
||||
RectangleF r2 = FindEdges(glyph_surface);
|
||||
glyph_renderer.Clear(Color.Transparent);
|
||||
|
||||
glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty, //new Point(glyph_surface.Width, 0),
|
||||
glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : load_glyph_string_format_tight);
|
||||
|
||||
r2 = FindEdges(glyph_surface, true);
|
||||
|
||||
//if ((default_string_format.FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0)
|
||||
//{
|
||||
// glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty, //new Point(glyph_surface.Width, 0),
|
||||
// load_glyph_string_format);//glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : default_string_format);
|
||||
|
||||
// r2 = FindEdges(glyph_surface, true);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty,
|
||||
// load_glyph_string_format_tight); //glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : default_string_format);
|
||||
|
||||
// r2 = FindEdges(glyph_surface, false);
|
||||
//}
|
||||
|
||||
return glyph_surface.Clone(r2, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
}
|
||||
|
@ -129,6 +153,8 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
#endregion
|
||||
|
||||
#region Clear
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
block_cache.Clear();
|
||||
|
@ -136,6 +162,8 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
#region EnsureSurfaceSize
|
||||
|
@ -194,15 +222,32 @@ namespace OpenTK.Graphics.Text
|
|||
TextExtents MeasureTextExtents(TextBlock block, TextQuality quality)
|
||||
{
|
||||
// Todo: Parse layout options:
|
||||
//StringFormat format = default_string_format;
|
||||
StringFormat format = default_string_format;
|
||||
StringFormat format = block.Font.Italic ? measure_string_format : measure_string_format_tight;
|
||||
//StringFormat format = measure_string_format_tight;
|
||||
|
||||
if (block.Direction == TextDirection.Vertical)
|
||||
format.FormatFlags |= StringFormatFlags.DirectionVertical;
|
||||
else
|
||||
format.FormatFlags &= ~StringFormatFlags.DirectionVertical;
|
||||
|
||||
if (block.Direction == TextDirection.RightToLeft)
|
||||
format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
|
||||
else
|
||||
format.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft;
|
||||
|
||||
if (block.Alignment == TextAlignment.Near)
|
||||
format.Alignment = StringAlignment.Near;
|
||||
else if (block.Alignment == TextAlignment.Center)
|
||||
format.Alignment = StringAlignment.Center;
|
||||
else
|
||||
format.Alignment = StringAlignment.Far;
|
||||
|
||||
TextExtents extents = text_extents_pool.Acquire();
|
||||
|
||||
RectangleF rect = new RectangleF(PointF.Empty, block.Bounds);
|
||||
RectangleF rect = block.Bounds;
|
||||
// Work around Mono/GDI+ bug, which causes incorrect
|
||||
// text wraping when block.Bounds == SizeF.Empty.
|
||||
if (block.Bounds == SizeF.Empty)
|
||||
if (block.Bounds.Size == SizeF.Empty)
|
||||
rect.Size = MaximumGraphicsClipSize;
|
||||
|
||||
SetTextRenderingOptions(graphics, block.Font, quality);
|
||||
|
@ -211,7 +256,7 @@ namespace OpenTK.Graphics.Text
|
|||
IntPtr native_font = GdiPlus.GetNativeFont(block.Font);
|
||||
IntPtr native_string_format = GdiPlus.GetNativeStringFormat(format);
|
||||
|
||||
int height = 0;
|
||||
float max_width = 0, max_height = 0;
|
||||
|
||||
// It seems that the mere presence of \n and \r characters
|
||||
// is enough for Mono to botch the layout (even if these
|
||||
|
@ -224,14 +269,26 @@ namespace OpenTK.Graphics.Text
|
|||
string[] lines = block.Text.Replace("\r", String.Empty).Split('\n');
|
||||
foreach (string s in lines)
|
||||
{
|
||||
float width, height;
|
||||
|
||||
extents.AddRange(MeasureGlyphExtents(
|
||||
s, height, rect,
|
||||
native_graphics, native_font, native_string_format));
|
||||
height += block.Font.Height;
|
||||
ref block, s,
|
||||
native_graphics, native_font, native_string_format,
|
||||
ref rect, out width, out height));
|
||||
|
||||
if ((block.Direction & TextDirection.Vertical) == 0)
|
||||
rect.Y += block.Font.Height;
|
||||
else
|
||||
rect.X += block.Font.Height;
|
||||
|
||||
if (width > max_width)
|
||||
max_width = width;
|
||||
if (height > max_height)
|
||||
max_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
extents.BoundingBox = new RectangleF(extents[0].X, extents[0].Y, extents[extents.Count - 1].Right, extents[extents.Count - 1].Bottom);
|
||||
extents.BoundingBox = new RectangleF(extents[0].X, extents[0].Y, max_width, max_height);
|
||||
|
||||
return extents;
|
||||
}
|
||||
|
@ -241,56 +298,87 @@ namespace OpenTK.Graphics.Text
|
|||
#region MeasureGlyphExtents
|
||||
|
||||
// Gets the bounds of each character in a line of text.
|
||||
// The line is processed in blocks of 32 characters (GdiPlus.MaxMeasurableCharacterRanges).
|
||||
IEnumerable<RectangleF> MeasureGlyphExtents(string text, int height,
|
||||
RectangleF layoutRect, IntPtr native_graphics, IntPtr native_font, IntPtr native_string_format)
|
||||
// Each line is processed in blocks of 32 characters (GdiPlus.MaxMeasurableCharacterRanges).
|
||||
IEnumerable<RectangleF> MeasureGlyphExtents(
|
||||
ref TextBlock block, string text,
|
||||
IntPtr native_graphics, IntPtr native_font, IntPtr native_string_format,
|
||||
ref RectangleF layoutRect, out float max_width, out float max_height)
|
||||
{
|
||||
measured_glyphs.Clear();
|
||||
max_width = layoutRect.Left;
|
||||
max_height = layoutRect.Top;
|
||||
float last_line_width = 0, last_line_height = 0;
|
||||
|
||||
RectangleF rect = new RectangleF();
|
||||
int current = 0;
|
||||
while (current < text.Length)
|
||||
{
|
||||
int num_characters = (text.Length - current) > GdiPlus.MaxMeasurableCharacterRanges ?
|
||||
GdiPlus.MaxMeasurableCharacterRanges :
|
||||
text.Length - current;
|
||||
int status = 0;
|
||||
{
|
||||
int num_characters = (text.Length - current) > GdiPlus.MaxMeasurableCharacterRanges ?
|
||||
GdiPlus.MaxMeasurableCharacterRanges :
|
||||
text.Length - current;
|
||||
int status = 0;
|
||||
|
||||
for (int i = 0; i < num_characters; i++)
|
||||
{
|
||||
if (text[current + i] == '\n' || text[current + i] == '\r')
|
||||
throw new Exception();
|
||||
// Prepare the character ranges and region structs for the measurement.
|
||||
for (int i = 0; i < num_characters; i++)
|
||||
{
|
||||
if (text[current + i] == '\n' || text[current + i] == '\r')
|
||||
throw new NotSupportedException();
|
||||
|
||||
characterRanges[i] = new CharacterRange(current + i, 1);
|
||||
characterRanges[i] = new CharacterRange(current + i, 1);
|
||||
|
||||
IntPtr region;
|
||||
status = GdiPlus.CreateRegion(out region);
|
||||
regions[i] = region;
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
}
|
||||
IntPtr region;
|
||||
status = GdiPlus.CreateRegion(out region);
|
||||
regions[i] = region;
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
}
|
||||
|
||||
status = GdiPlus.SetStringFormatMeasurableCharacterRanges(native_string_format, num_characters, characterRanges);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
status = GdiPlus.SetStringFormatMeasurableCharacterRanges(native_string_format, num_characters, characterRanges);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
status = GdiPlus.MeasureCharacterRanges(native_graphics, text, text.Length,
|
||||
native_font, ref layoutRect, native_string_format, num_characters, regions);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
status = GdiPlus.MeasureCharacterRanges(native_graphics, text, text.Length,
|
||||
native_font, ref layoutRect, native_string_format, num_characters, regions);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
for (int i = 0; i < num_characters; i++)
|
||||
{
|
||||
GdiPlus.GetRegionBounds(regions[i], native_graphics, ref rect);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
GdiPlus.DeleteRegion(regions[i]);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
// Read back the results of the measurement.
|
||||
for (int i = 0; i < num_characters; i++)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
|
||||
rect.Y += height;
|
||||
|
||||
//yield return rect;
|
||||
measured_glyphs.Add(rect);
|
||||
}
|
||||
GdiPlus.GetRegionBounds(regions[i], native_graphics, ref rect);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
GdiPlus.DeleteRegion(regions[i]);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
current += num_characters;
|
||||
}
|
||||
if (rect.Bottom > max_height)
|
||||
max_height = rect.Bottom;
|
||||
if (rect.Right > max_width)
|
||||
max_width = rect.Right;
|
||||
|
||||
if (rect.X > last_line_width)
|
||||
last_line_width = rect.X;
|
||||
if (rect.Y > last_line_height)
|
||||
last_line_height = rect.Y;
|
||||
|
||||
measured_glyphs.Add(rect);
|
||||
}
|
||||
|
||||
current += num_characters;
|
||||
}
|
||||
|
||||
// Make sure the current height is updated, if the the current line has wrapped due to word-wraping.
|
||||
// Otherwise, the next line will overlap with the current one.
|
||||
if (measured_glyphs.Count > 1)
|
||||
{
|
||||
if ((block.Direction & TextDirection.Vertical) == 0)
|
||||
{
|
||||
if (layoutRect.Y < last_line_height)
|
||||
layoutRect.Y = last_line_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (layoutRect.X < last_line_width)
|
||||
layoutRect.X = last_line_width;
|
||||
}
|
||||
}
|
||||
|
||||
return measured_glyphs;
|
||||
}
|
||||
|
@ -305,18 +393,22 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
#pragma warning restore 0649
|
||||
|
||||
Rectangle FindEdges(Bitmap bmp)
|
||||
// Note: The bool parameter is not used at this point.
|
||||
// We might need it if we ever load true rightToLeft glyphs.
|
||||
Rectangle FindEdges(Bitmap bmp, bool rightToLeft)
|
||||
{
|
||||
BitmapData data = bmp.LockBits(
|
||||
new Rectangle(0, 0, bmp.Width, bmp.Height),
|
||||
ImageLockMode.ReadOnly,
|
||||
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
|
||||
Rectangle rect = Rectangle.FromLTRB(
|
||||
FindLeftEdge(bmp, data.Scan0),
|
||||
FindTopEdge(bmp, data.Scan0),
|
||||
FindRightEdge(bmp, data.Scan0),
|
||||
FindBottomEdge(bmp, data.Scan0));
|
||||
|
||||
//Rectangle rect = rightToLeft ?
|
||||
// Rectangle.FromLTRB(FindLeftEdge(bmp, data.Scan0), 0, bmp.Width - 1, FindBottomEdge(bmp, data.Scan0)) :
|
||||
// Rectangle.FromLTRB(0, 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
||||
|
||||
Rectangle rect =
|
||||
Rectangle.FromLTRB(0, 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
||||
//Rectangle.FromLTRB(FindLeftEdge(bmp, data.Scan0), 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
||||
|
||||
bmp.UnlockBits(data);
|
||||
|
||||
|
@ -331,8 +423,15 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
int FindLeftEdge(Bitmap bmp, IntPtr ptr)
|
||||
{
|
||||
// Don't trim the left edge, because the layout engine expects it to be 0.
|
||||
return 0;
|
||||
for (int x = 0; x < bmp.Width; x++)
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
unsafe
|
||||
{
|
||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
||||
return x;
|
||||
}
|
||||
|
||||
return bmp.Width - 1;
|
||||
}
|
||||
|
||||
int FindRightEdge(Bitmap bmp, IntPtr ptr)
|
||||
|
@ -350,8 +449,15 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
int FindTopEdge(Bitmap bmp, IntPtr ptr)
|
||||
{
|
||||
// Don't trim the top edge, because the layout engine expects it to be 0.
|
||||
return 0;
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
for (int x = 0; x < bmp.Width; x++)
|
||||
unsafe
|
||||
{
|
||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
||||
return y;
|
||||
}
|
||||
|
||||
return bmp.Height - 1;
|
||||
}
|
||||
|
||||
int FindBottomEdge(Bitmap bmp, IntPtr ptr)
|
||||
|
|
|
@ -41,22 +41,28 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
public readonly Font Font;
|
||||
|
||||
public readonly SizeF Bounds;
|
||||
public readonly RectangleF Bounds;
|
||||
|
||||
public readonly TextPrinterOptions Options;
|
||||
|
||||
public int UsageCount; // Used to identify old and unused blocks of text.
|
||||
public readonly TextAlignment Alignment;
|
||||
|
||||
public readonly TextDirection Direction;
|
||||
|
||||
public readonly int UsageCount;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public TextBlock(string text, Font font, TextPrinterOptions options, SizeF bounds)
|
||||
public TextBlock(string text, Font font, RectangleF bounds, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
||||
{
|
||||
Text = text;
|
||||
Font = font;
|
||||
Bounds = bounds;
|
||||
Options = options;
|
||||
Alignment = alignment;
|
||||
Direction = direction;
|
||||
UsageCount = 0;
|
||||
}
|
||||
|
||||
|
|
19
Source/Utilities/Graphics/TextAlignment.cs
Normal file
19
Source/Utilities/Graphics/TextAlignment.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines available alignments for text.
|
||||
/// </summary>
|
||||
public enum TextAlignment
|
||||
{
|
||||
/// <summary>The text is aligned to the near side (left for left-to-right text and right for right-to-left text).</summary>
|
||||
Near = 0,
|
||||
/// <summary>The text is aligned to the center.</summary>
|
||||
Center,
|
||||
/// <summary>The text is aligned to the far side (right for left-to-right text and left for right-to-left text).</summary>
|
||||
Far
|
||||
}
|
||||
}
|
19
Source/Utilities/Graphics/TextDirection.cs
Normal file
19
Source/Utilities/Graphics/TextDirection.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines available directions for text layout.
|
||||
/// </summary>
|
||||
public enum TextDirection
|
||||
{
|
||||
/// <summary>The text is layed out from left to right.</summary>
|
||||
LeftToRight,
|
||||
/// <summary>The text is layed out from right to left.</summary>
|
||||
RightToLeft,
|
||||
/// <summary>The text is layed out vertically.</summary>
|
||||
Vertical
|
||||
}
|
||||
}
|
|
@ -64,23 +64,33 @@ namespace OpenTK.Graphics
|
|||
|
||||
public void Print(string text, Font font, Color color)
|
||||
{
|
||||
Print(text, font, color, SizeF.Empty, TextPrinterOptions.Default);
|
||||
Print(text, font, color, RectangleF.Empty, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
public void Print(string text, Font font, Color color, SizeF size)
|
||||
public void Print(string text, Font font, Color color, RectangleF rect)
|
||||
{
|
||||
Print(text, font, color, size, TextPrinterOptions.Default);
|
||||
Print(text, font, color, rect, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
public void Print(string text, Font font, Color color, SizeF size, TextPrinterOptions options)
|
||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options)
|
||||
{
|
||||
Print(text, font, color, rect, options, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment)
|
||||
{
|
||||
Print(text, font, color, rect, options, alignment, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException(this.GetType().ToString());
|
||||
|
||||
if (!ValidateParameters(text, font, size))
|
||||
if (!ValidateParameters(text, font, rect))
|
||||
return;
|
||||
|
||||
TextOutput.Print(new TextBlock(text, font, options, size), color, Rasterizer);
|
||||
TextOutput.Print(new TextBlock(text, font, rect, options, alignment, direction), color, Rasterizer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -89,23 +99,34 @@ namespace OpenTK.Graphics
|
|||
|
||||
public TextExtents Measure(string text, Font font)
|
||||
{
|
||||
return Measure(text, font, SizeF.Empty, TextPrinterOptions.Default);
|
||||
return Measure(text, font, RectangleF.Empty, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
public TextExtents Measure(string text, Font font, SizeF size)
|
||||
public TextExtents Measure(string text, Font font, RectangleF rect)
|
||||
{
|
||||
return Measure(text, font, size, TextPrinterOptions.Default);
|
||||
return Measure(text, font, rect, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
public TextExtents Measure(string text, Font font, SizeF size, TextPrinterOptions options)
|
||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options)
|
||||
{
|
||||
return Measure(text, font, rect, options, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
|
||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment)
|
||||
{
|
||||
return Measure(text, font, rect, options, alignment, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException(this.GetType().ToString());
|
||||
|
||||
if (!ValidateParameters(text, font, size))
|
||||
if (!ValidateParameters(text, font, rect))
|
||||
return TextExtents.Empty;
|
||||
|
||||
return Rasterizer.MeasureText(new TextBlock(text, font, options, size));
|
||||
return Rasterizer.MeasureText(new TextBlock(text, font, rect, options, alignment, direction));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -223,13 +244,13 @@ namespace OpenTK.Graphics
|
|||
|
||||
#region Static Members
|
||||
|
||||
static bool ValidateParameters(string text, Font font, SizeF size)
|
||||
static bool ValidateParameters(string text, Font font, RectangleF rect)
|
||||
{
|
||||
if (String.IsNullOrEmpty(text))
|
||||
return false;
|
||||
if (font == null)
|
||||
throw new ArgumentNullException("font");
|
||||
if (size.Width < 0 || size.Height < 0)
|
||||
if (rect.Width < 0 || rect.Height < 0)
|
||||
throw new ArgumentOutOfRangeException("size");
|
||||
|
||||
return true;
|
||||
|
|
|
@ -4,12 +4,15 @@ using System.Text;
|
|||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines available options for the TextPrinter.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum TextPrinterOptions
|
||||
{
|
||||
Default = 0,
|
||||
NoCache = 1,
|
||||
RightToLeft = 2,
|
||||
Vertical = 4,
|
||||
/// <summary>The TextPrinter will use default printing options.</summary>
|
||||
Default = 0x0000,
|
||||
/// <summary>The TextPrinter will not cache text blocks as they are measured or printed.</summary>
|
||||
NoCache = 0x0001,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
public enum TextQuality
|
||||
{
|
Loading…
Reference in a new issue