Updated TextPrinter.PerformLayout to use the new GdiPlus-based MeasureCharacterRanges function.
This commit is contained in:
parent
314bec1c66
commit
4b47612234
1 changed files with 34 additions and 37 deletions
|
@ -194,8 +194,8 @@ namespace OpenTK.Graphics
|
||||||
//ushort[] indices = new ushort[6 * text.Length];
|
//ushort[] indices = new ushort[6 * text.Length];
|
||||||
float x_pos = 0, y_pos = 0;
|
float x_pos = 0, y_pos = 0;
|
||||||
ushort i = 0, index_count = 0, vertex_count = 0, last_break_point = 0;
|
ushort i = 0, index_count = 0, vertex_count = 0, last_break_point = 0;
|
||||||
Box2 rect = new Box2();
|
RectangleF rect = new RectangleF();
|
||||||
float char_width, char_height, measured_width, measured_height;
|
float char_width, char_height;
|
||||||
int texture;
|
int texture;
|
||||||
|
|
||||||
font.LoadGlyphs(text);
|
font.LoadGlyphs(text);
|
||||||
|
@ -206,13 +206,20 @@ namespace OpenTK.Graphics
|
||||||
|
|
||||||
if (alignment == StringAlignment.Near && !rightToLeft || alignment == StringAlignment.Far && rightToLeft)
|
if (alignment == StringAlignment.Near && !rightToLeft || alignment == StringAlignment.Far && rightToLeft)
|
||||||
{
|
{
|
||||||
foreach (char c in text)
|
ICollection<RectangleF> ranges = new List<RectangleF>();
|
||||||
|
font.MeasureCharacterRanges(text, StringFormat.GenericTypographic, ref ranges);
|
||||||
|
|
||||||
|
int current = 0;
|
||||||
|
//foreach (char c in text)
|
||||||
|
foreach (RectangleF range in ranges)
|
||||||
{
|
{
|
||||||
|
char c = text[current++];
|
||||||
if (Char.IsSeparator(c))
|
if (Char.IsSeparator(c))
|
||||||
last_break_point = index_count;
|
last_break_point = index_count;
|
||||||
|
|
||||||
if (c != '\n' && c != '\r')
|
x_pos = range.X;
|
||||||
{
|
y_pos = range.Y;
|
||||||
|
|
||||||
font.GlyphData(c, out char_width, out char_height, out rect, out texture);
|
font.GlyphData(c, out char_width, out char_height, out rect, out texture);
|
||||||
|
|
||||||
vertices[vertex_count].X = x_pos; // Vertex
|
vertices[vertex_count].X = x_pos; // Vertex
|
||||||
|
@ -241,16 +248,6 @@ namespace OpenTK.Graphics
|
||||||
indices[index_count++] = (ushort)(vertex_count - 2);
|
indices[index_count++] = (ushort)(vertex_count - 2);
|
||||||
indices[index_count++] = (ushort)(vertex_count - 8);
|
indices[index_count++] = (ushort)(vertex_count - 8);
|
||||||
|
|
||||||
|
|
||||||
font.MeasureString(text.Substring(i, 1), out measured_width, out measured_height, false);
|
|
||||||
x_pos += measured_width;
|
|
||||||
}
|
|
||||||
else if (c == '\n')
|
|
||||||
{
|
|
||||||
//x_pos = layoutRect.Left;
|
|
||||||
x_pos = 0;
|
|
||||||
y_pos += font.Height;
|
|
||||||
}
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue