Combining Accents not Displayed Nicely with DrawString -
11-18-2009
, 04:18 AM
Hi,
I'd like to draw strings using System.Drawing.Graphics.DrawString. I have
found that combining accents sometimes do not display well, though. I have
prepared a small example project:
using System;
using System.Windows.Forms;
using System.Drawing;
namespace Test
{
public class DrawStringTest
{
public static void Main(string[] args)
{
Form frm = new Form();
TextBox tb = new TextBox();
tb.Font = new Font("Arial Unicode MS", 10);
tb.TextChanged += delegate(object sender, EventArgs e) {
frm.Refresh();
};
tb.Parent = frm;
tb.Left = 10;
tb.Top = 10;
tb.Text = "aa\x0301AA\x0301";
frm.Paint += delegate(object sender, PaintEventArgs e) {
Graphics g = e.Graphics;
g.DrawString(tb.Text, tb.Font, SystemBrushes.WindowText, new
PointF(10, 40));
};
frm.Width = 400;
frm.Height = 300;
frm.ShowDialog();
}
}
}
The text box contains two small 'a's and two capital 'a's, the 2nd of each
has a combining acute accent. While the text box displays both accents fine,
DrawString only draws the small 'á' prettily, whereas the accent on the
capital 'Á' is misplaced.
Now, I could normalize my string before passing it to DrawString, but I fear
losing correspondance to the character widths obtained via
System.Drawing.Graphics.MeasureCharacterRanges which I have to call using the
original (not normalized) string.
Is there any way to draw these strings correctly?
Thanks in advance |