c++ - GetCharWidth32 and Point Size issue -


currently have following function attempt character widths specific characters in string. returns same values font regardless of point size. know in logical units. multiplier need take account out of logical units , pixels?

thanks!

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; } 

new code mark using measure string.

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; } 

you're trying select gdi+ font gdi dc. i'm pretty sure that's not going work. need gdi handle font.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -