Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRenderEngine::GdiplusDrawText错误 #179

Open
rosejober opened this issue May 14, 2024 · 0 comments
Open

CRenderEngine::GdiplusDrawText错误 #179

rosejober opened this issue May 14, 2024 · 0 comments

Comments

@rosejober
Copy link

GdiplusDrawText函数中用Gdiplus::Font font(hDC, pManager->GetFont(iFont));创建字体,它创建出来的字体GetUnit拿到的值是UnitWorld,我们实际绘制的时候都是用UnitPixel,这样会照成部分电脑上绘制的文本异常。需要改造成:

// 获取HFONT的LOGFONT
LOGFONT logFont;
GetObject(pManager->GetFont(iFont), sizeof(LOGFONT), &logFont);
// 创建一个FontFamily对象
Gdiplus::FontFamily fontFamily(logFont.lfFaceName);
// 获取字体大小,注意这是以设备无关的逻辑单位,一般为像素
Gdiplus::REAL fontSize = static_castGdiplus::REAL(abs(logFont.lfHeight));
// 用将LOGFONT的样式转换成Gdiplus的样式
INT fontStyle = Gdiplus::FontStyleRegular;
if (logFont.lfWeight > FW_NORMAL) fontStyle |= Gdiplus::FontStyleBold;
if (logFont.lfItalic) fontStyle |= Gdiplus::FontStyleItalic;
if (logFont.lfUnderline) fontStyle |= Gdiplus::FontStyleUnderline;
if (logFont.lfStrikeOut) fontStyle |= Gdiplus::FontStyleStrikeout;
// 创建新的Gdiplus::Font对象
Gdiplus::Font font(&fontFamily, fontSize, fontStyle, Gdiplus::UnitPixel);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant