winapi - DrawText draws Segoe UI font texts incorrectly -
winapi - DrawText draws Segoe UI font texts incorrectly -
i encountered 1 problem drawing texts using windows api drawtext phone call segoe ui font:
this image demonstrates problem: specified text shifted little bit right in specified rectangle lastly character clipped (the best illustration 0 digit).
our drawing routine works other fonts, , problem occurs segoe ui.
what , how solve it?
doing in vb6 ocx project on windows 8 pro 64-bit if matters.
the corresponding code source snippet following:
' draws or measure text (if dt_calcrect specified) ' using native winapi flags: public sub gpinternaldrawtext( _ byval lhdc long, _ byref stext string, _ byref tr rect, _ byval lflags long _ ) ' allows unicode rendering of text under nt/2000/xp if (g_bisnt) ' nt4 crashes ptr = 0 if strptr(stext) <> 0 drawtextw lhdc, strptr(stext), -1, tr, lflags end if else drawtexta lhdc, stext, -1, tr, lflags end if end sub ' draws string in specifed rectangle. ' should not called calculate text size ' (with dt_calcrect flag - utilize gpinternaldrawtext instead) public sub drawtext( _ byval lhdc long, _ byref stext string, _ byref rctext rect, _ byval lflags long, _ optional byval ealignh long = 0, _ optional byval ealignv long = 0 _ ) ' *** automatically turns processing prefixes off (if required) if (lflags , &h200000) = 0 lflags = lflags or dt_noprefix else lflags = lflags xor dt_prefixonly end if ' *** can modify rctext below, re-create dim rcdrawtext rect lset rcdrawtext = rctext ' *** getting total set of api flags our text select case ealignh ' in fact don't need dt_left=0: ' case igalignhleft ' lflags = lflags or dt_left case igalignhcenter lflags = lflags or dt_center case igalignhright lflags = lflags or dt_right end select if (lflags , dt_singleline) <> 0 select case ealignv ' in fact don't need dt_top=0: ' case igalignvtop ' lflags = lflags or dt_top case igalignvcenter lflags = lflags or dt_vcenter case igalignvbottom lflags = lflags or dt_bottom end select else if ealignv <> igalignvtop dim rccalcrect rect lset rccalcrect = rctext gpinternaldrawtext lhdc, stext, rccalcrect, lflags or dt_calcrect dim ltextheight long ltextheight = rccalcrect.bottom - rccalcrect.top select case ealignv case igalignvcenter ' simplified (rctext.top + rctext.bottom) / 2 - ltextheight / 2 ' should integer partition because of rounding erros in case of "/" rcdrawtext.top = (rcdrawtext.top + rcdrawtext.bottom - ltextheight) \ 2 case igalignvbottom rcdrawtext.top = rcdrawtext.bottom - ltextheight end select end if end if ' *** draw text const fixed_path_ellipsis_flags long = dt_singleline or dt_path_ellipsis if (lflags , fixed_path_ellipsis_flags) = fixed_path_ellipsis_flags drawtext_fixedpathellipsis lhdc, stext, rcdrawtext, lflags else gpinternaldrawtext lhdc, stext, rcdrawtext, lflags end if end sub
the font usercontrol dc set using code:
public function fonthandle(fnt ifont) long fonthandle = fnt.hfont end function private sub papplyfont() if (m_hfntdc <> 0) if (m_hdc <> 0) if (m_hfntolddc <> 0) selectobject m_hdc, m_hfntolddc end if end if end if m_hfntdc = fonthandle(usercontrol.font) if (m_hdc <> 0) m_hfntolddc = selectobject(m_hdc, m_hfntdc) end if end sub
, where
m_hdc = createcompatibledc(usercontrol.hdc)
the problem output quality using. using antialiased_quality
. segoe ui has been designed clear type. looks great clear type, terrible standard anti-aliasing. switch clear type (set lqquality
cleartype_quality
) , much improve results.
this image demonstrates rendering of 10pt segoe ui 2 quality options discussed above.
winapi vb6 ocx drawtext
Comments
Post a Comment