如何加快MFC中旋转文本的输出速度

发布于 2024-08-18 03:44:11 字数 563 浏览 6 评论 0原文

我有一个显示带注释的地图的 MFC 应用程序,其中可能包含大量文本。虽然文本的大小和字体不会发生太大变化,但文本的旋转变化很大,以便与周围的线条对齐。这基本上意味着每次旋转发生变化时,我都必须在显示上下文中创建并选择一种新字体。像这样的东西;

if (TextRotationChanges)
{
    m_pFont = new CFont;
    m_lf.lfEscapement = NewRotation;
    m_pFont->CreateFontIndirect(&m_lf);
}
CFont *OldFont = m_pDC->SelectObject(m_pFont);
m_pDC->TextOut(x,y,text,strlen(text));
m_pDC->SelectObject(OldFont);

当处理大量文本时,这显然很慢。有没有什么方法可以在不使用不同的显示引擎(例如 D3D 或 OpenGL)的情况下加快速度?换句话说,我可以更改现有选定字体的文本旋转吗?

注意,我已经进行了其他明显的优化,例如在尝试绘制文本之前确保文本以可见大小显示在屏幕上。

I have a MFC application that displays annotated maps, which can include a large amount of text. While the size and font of the text does not tend to change much, the rotation of the text varies considerably, in order to be aligned with the surrounding line work. This basically means that I have to do create and select a new font into the display context each time the rotation changes. Something like;

if (TextRotationChanges)
{
    m_pFont = new CFont;
    m_lf.lfEscapement = NewRotation;
    m_pFont->CreateFontIndirect(&m_lf);
}
CFont *OldFont = m_pDC->SelectObject(m_pFont);
m_pDC->TextOut(x,y,text,strlen(text));
m_pDC->SelectObject(OldFont);

This is obviously slow when dealing with large amounts of text. Is there any way of speeding this up without going to a different display engine such as D3D or OpenGL? Put another way, can I change the text rotation in the existing selected font?

n.b. I'm already carrying out other obvious optimizations, like ensuring text is on screen at a visible size prior to attempting to draw it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尝蛊 2024-08-25 03:44:11

创建和销毁许多 GDI 对象可能会很慢。您可以做的是在程序启动时创建 360 种字体,以便您可以从查找表中以正确的旋转方式使用预制字体进行 SelectObject(),而不是按需创建它们。或者,您可以不使用 lfEscapement,而是使用 SetWorldTransform() 和适当的旋转矩阵来旋转文本(同样,您可以缓存旋转矩阵以提高速度)。您必须测试它是否真的会给您带来速度增益。

请参阅我的问题SetWorldTransform() 和字体旋转,了解我使用该方法遇到的问题,不过(还没有时间回去研究它)。

Creating and destroying many GDI object can be slow. What you can do is create 360 fonts at the startup of your program so that you can SelectObject() from a lookup table with pre-made fonts at the correct rotation, rather than creating them on-demand. Or you can rotate your text by not using lfEscapement but by using SetWorldTransform() with the appropriate rotation matrix (again, you could cache rotation matrices for speed). You'd have to test if it will actually give you a speed gain.

See my question here SetWorldTransform() and font rotation for an issue I had/have with that approach, though (haven't had time to go back and look into it).

请别遗忘我 2024-08-25 03:44:11

您确定问题出在字体而不是 TextOut 上吗?
如果您想避免闪烁,Oleg 使用后台缓冲区的想法还不错。

如果我要使用图形引擎,我会尝试 Cairo 因为它是专门为此类工作而设计的.
(它可以直接在win32 DC表面上渲染)

Are you sure that the problem is the font and not the TextOut?
Oleg's idea of using a back buffer isn't bad if you want to avoid flickering.

If I was going to use a graphic engine I'd try Cairo because it's designed specifically for that kind of jobs.
(it can render directly on win32 DC surfaces)

滥情哥ㄟ 2024-08-25 03:44:11

您应该首先将其绘制在不可见的DC上,然后复制到您的DC上。

You should first draw it on the invisible DC and than copy to your DC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文