开发者

.NET: drawing text hangs - FormattedText bug?

开发者 https://www.devze.com 2023-01-12 11:39 出处:网络
A customer has reported that our software hangs when he runs it on one of his computers. We narrowed down the problem to rendering text with FormattedText and put together a simple application for him

A customer has reported that our software hangs when he runs it on one of his computers. We narrowed down the problem to rendering text with FormattedText and put together a simple application for him 开发者_如何学运维to try, which just renders some text with different font parameters - this would hang too.

Here's the bit of code which does the actual text drawing:

Typeface typeface = new Typeface(m_Font, m_FontStyle, m_FontWeight, FontStretches.Normal);
FormattedText ftext = new FormattedText(m_Text, new CultureInfo("en-US"), FlowDirection.LeftToRight, typeface, m_FontSize, m_FontColor);

ftext.TextAlignment = CenterText ? TextAlignment.Center : TextAlignment.Left;

if (m_DrawOutline)
{
    Geometry geom = ftext.BuildGeometry(CenterText ? new Point(ftext.Width, 0) : new Point());
    dc.DrawGeometry(m_FontColor, DrawOutline ? new Pen(m_OutlineColor, m_OutlineWidth) : null, geom);
}
else
    dc.DrawText(ftext, CenterText ? new Point(ftext.Width, 0) : new Point());

The program simply stops responding whenever the ftext.BuildGeometry, dx.DrawText methods or the ftext.Width property is called, regardless of font and text parameters used. This only happens on one computer, which is a touchscreen laptop (not sure this is relevant) running Windows 7. We already tried reinstalling the .NET Framework but this didn't help.

Has anyone encountered a similar problem? Any ideas how to fix, work around or at least find out more about what the reason for this problem is?

Thanks.


Never personally encountered that problem and I use Windows 7 at home. However, if it is only on one machine, it is a safe bet that the problem is not software related. The first step I would try is to download the most recent video display drivers and installing them. If it is still giving you a problem, try booting into safe mode and see if it will run.


I've had this problem occur due to a corrupt presentation font cache.

Stop the font cache service, delete the file %systemdrive%\Documents and Settings\LocalService\Local Settings\Application Data\FontCache3.0.0.0.dat (xp) and restart.

Details at http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7cc032c1-5f4d-4518-adc6-f53afd051e6b

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号