本文介绍了获取字距调整信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何获取GDI的字距调整信息,然后在 GetKerningPairs ? 文档说明How can I obtain kerning information for GDI to then use in GetKerningPairs? The documentation states that但是,我不知道编辑#2这里是我的填充应用程序,我也试过,这是总是产生0的任何字体的数量对。 GetLastError总是返回0。Here is my fill application that I have also tried, this is always producing 0 for any font for the number of pairs. GetLastError will always return 0 also.#include <windows.h>#include <Gdiplus.h>#include <iostream>using namespace std;using namespace Gdiplus;int main(void){ GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Font* myFont = new Font(L"Times New Roman", 12); Bitmap* bitmap = new Bitmap(256, 256, PixelFormat32bppARGB); Graphics* g = new Graphics(bitmap); //HDC hdc = g->GetHDC(); HDC hdc = GetDC(NULL); SelectObject(hdc, myFont->Clone()); DWORD numberOfKerningPairs = GetKerningPairs(hdc, INT_MAX, NULL ); cout << GetLastError() << endl; cout << numberOfKerningPairs << endl; GdiplusShutdown(gdiplusToken); return 0;} EDIT 但是,它仍然给了我0。EDITI tried to do the following, however, it still gave me 0.Font* myFont = new Font(L"Times New Roman", 10);Bitmap* bitmap = new Bitmap(256, 256, PixelFormat32bppARGB);Graphics* g = new Graphics(bitmap);SelectObject(g->GetHDC(), myFont);//DWORD numberOfKerningPairs = GetKerningPairs( g->GetHDC(), -1, NULL );DWORD numberOfKerningPairs = GetKerningPairs( g->GetHDC(), INT_MAX, NULL );推荐答案问题在于你传递a Gdiplus :: Font ,而不是 SelectObject 的HFONT。您需要将 Font * myFont 转换为 HFONT ,然后传递 HFONT into SelectObject。The problem lies in the fact that you are passing in a Gdiplus::Font and not a HFONT for SelectObject. You need to convert Font* myFont into a HFONT, then pass that HFONT into SelectObject.首先,将 Gdiplus :: Font 转换为 HFONT ,您需要获取 LOGFONT 从 Gdiplus :: Font 。一旦你这样做,其余的很简单。获得数字字距对的工作解决方案是First, to convert a Gdiplus::Font into a HFONT, you need to get the LOGFONT from the Gdiplus::Font. Once you do this, the rest is simple. The working solution to get number of kerning pairs isFont* gdiFont = new Font(L"Times New Roman", 12);Bitmap* bitmap = new Bitmap(256, 256, PixelFormat32bppARGB);Graphics* g = new Graphics(bitmap);LOGFONT logFont;gdiFont->GetLogFontA(g, &logFont);HFONT hfont = CreateFontIndirect(&logFont);HDC hdc = GetDC(NULL);SelectObject(hdc, hfont);DWORD numberOfKerningPairs = GetKerningPairs(hdc, INT_MAX, NULL );正如你所知,我所提供的唯一功能变化是创建一个 FONT 。As you can tell, the only functional change I gave was to creating a FONT. 这篇关于获取字距调整信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 08:32