本文介绍了如何获得GDI HFONT的线高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将SVG导出支持添加到使用MFC构建的旧应用程序中,并使用普通的旧GDI.由于SVG 1.1不支持文本换行,因此我不得不手动执行此操作.

I'm adding SVG export support to an old application built with MFC and using plain old GDI. As SVG 1.1 doesn't support text wrapping, I am forced to do this manually.

该应用程序为我提供了一个 CFont 实例(其中包含一个 HFONT ).我可以使用 CFont :: GetTextExtentPoint()计算一段文本的宽度,但是我还没有找到如何获取字体的行高.

The application provides me with a CFont instance (which contains an HFONT). I can calculate the width of a piece of text using CFont::GetTextExtentPoint(), but I haven't found out how to obtain the line height of a font yet.

如何获取字体的行高?还是 CFont :: GetTextExtentPoint()总是返回Y坐标中的行高(而不是文本紧密配合的边框的实际高度)?

How can I obtain the line height of my font?Or does CFont::GetTextExtentPoint() always return the line height in the Y coordinate (instead the actual height of the text's tight-fitting bounding box)?

推荐答案

我认为我有可能的答案:

I think I have a possible answer:

CDC desktopDC;
desktopDC.Attach(::GetDC(0));
desktopDC.SelecTObject(&font);

::TEXTMETRIC metrics;
desktopDC.GetTextMetrics(&metrics);

int lineHeight = metrics.tmHeight + metrics.tmExternalLeading;

这有点麻烦,因此,如果有一个更短,更明显的解决方案(或者如果有人可以确认 CFont :: GetTextExtentPoint()为我提供实际的行高),我会很高兴听到它;)

It's a bit cumbersome, so if there's a shorter, more obvious solution (or if anyone can confirm that CFont::GetTextExtentPoint() provides me with the actual line height), I'd be happy to hear it still ;)

这篇关于如何获得GDI HFONT的线高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:30
查看更多