0
현재 문자열의 특정 문자에 대한 문자 너비를 가져 오려고 시도하는 다음 함수가 있습니다. 점 크기에 관계없이 글꼴에 대해 동일한 값을 반환합니다. 나는 이것이 논리적 단위라는 것을 안다. 논리적 단위와 픽셀을 얻기 위해 승수를 고려해야합니까?GetCharWidth32 및 포인트 크기 문제
감사합니다.
double Utils::GetFormattedCharWidth(char theChar, Gdiplus::Font* pFont, RectF& rectArc, Graphics& graphics)
{
double textWidth = 0;
HDC hdc = NULL;
DWORD outLine = 0; //= GetLastError();
hdc = graphics.GetHDC();
outLine = GetLastError();
LPINT lpBuffer = new int;
/*ABC *abc = new ABC[256];
for(int iCon = 0; iCon < 256; iCon++)
{
(&abc[iCon])->abcA = 0;
(&abc[iCon])->abcB = 0;
(&abc[iCon])->abcC = 0;
}*/
DWORD dSize = 0;
SetMapMode(hdc,MM_TEXT);
HGDIOBJ hOldFont = SelectObject(hdc, pFont);
outLine = GetLastError();
//outLine = GetLastError();
//DWORD d = GetGlyphOutline(hdc, theChar, GGO_METRICS, lpg, dSize, lpvBuffer, LPM);
DWORD d = GetCharWidth32(hdc, theChar, theChar, lpBuffer);
//lpABC = (LPABC)GlobalAllocPtr(GHND, 256*sizeof(ABC));
//d = GetCharABCWidthsA(hdc, 0, 255, abc);
outLine = GetLastError();
//DWORD d = GetCharABCWidthsA(hdc, theChar, theChar, abc);
int iExtraSpacing = GetTextCharacterExtra(hdc);
outLine = GetLastError();
graphics.ReleaseHDC(hdc);
textWidth = (double)(*lpBuffer) ;
//delete abc;
delete lpBuffer;
graphics.ReleaseHDC(hdc);
return textWidth + iExtraSpacing;
}
측정 문자열을 사용하는 표시의 새 코드입니다.
double Utils::GetFormattedCharWidth(char theChar, Gdiplus::Font* pFont, RectF& rectArc, Graphics& graphics)
{
double textWidth = 0;
char charBuff[4];
memset(&charBuff, 0, 4);
charBuff[0] = theChar;
RectF rectTemp;
WCHAR* pChar = (WCHAR*)charBuff;
graphics.MeasureString(pChar, 1, pFont, rectArc, &rectTemp);
textWidth = rectTemp.Width;
return textWidth;
}
흥미 롭습니다. 어떤 유형의 손잡이가 필요한가요? GDI에서 어디서 얻을 수 있습니까? – Alikar
GDI +에 어떤 기능을 사용하고 싶습니까? – Alikar
@Alikar, Graphics :: MeasureString 또는 Graphics :: MeasureDriverString을 시도하십시오. –