Hi. I've noticed a weird issue that doesn't happen on all fonts. But, if you highlight text (select the text) in a wxRichTextCtrl, the text will shift depending where you are highlighting. For instance, in the sample, if I try to select the line that begins with "Naturally" as seen in the picture, starting with the N, when I get to the t, the text shifts a little. I'm using Windows 7 64.
Stop wxRichTextCtrl Text Shifting
Re: Stop wxRichTextCtrl Text Shifting
The chance that any bug/quirk in wxRTC ever gets fixed is practically zero. The code base is hard to dig through and the original author doesn't support it any more.
Use the source, Luke!
Re: Stop wxRichTextCtrl Text Shifting
Hi,
It is possible that its the font that is wide and it needs shifting to accomodate it.
.
Try a different font.
Thank you.
It is possible that its the font that is wide and it needs shifting to accomodate it.
.
Try a different font.
Thank you.
Re: Stop wxRichTextCtrl Text Shifting
Another followup on this. I identified the code that was causing it. It appears it was patched in version 3.1.4 in textmeasure.cpp in the function DoGetTextExtent() with this code:
So, in previous versions, they only tested for len > 0, but this new code only runs for italic text. Incidentally, the shifting problem will still occur when this code runs with italic text. Personally, I edited it to never even do that code segment, even for italic text, because it isn't clear to me what exactly that code is needed for.
Code: Select all
// the result computed by GetTextExtentPoint32() may be too small as it
// accounts for under/overhang of the first/last character while we want
// just the bounding rect for this string so adjust the width as needed
// when using italic fonts as the difference is really noticeable for them
// (it may still exist, but seems to be at most 1px for the other fonts,
// and calling GetCharABCWidths() is pretty slow and much slower than
// calling GetTextExtentPoint32() itself, so avoid its overhead unless it's
// really, really necessary).
const wxFont font = GetFont();
if ( font.IsOk() && font.GetStyle() != wxFONTSTYLE_NORMAL && len > 0 )
{
ABC widthABC;
const wxChar chFirst = *string.begin();
if ( ::GetCharABCWidths(m_hdc, chFirst, chFirst, &widthABC) )
{
if ( widthABC.abcA < 0 )
sizeRect.cx -= widthABC.abcA;
if ( len > 1 )
{
const wxChar chLast = *string.rbegin();
::GetCharABCWidths(m_hdc, chLast, chLast, &widthABC);
}
//else: we already have the width of the last character
if ( widthABC.abcC < 0 )
sizeRect.cx -= widthABC.abcC;
}
//else: GetCharABCWidths() failed, not a TrueType font?
}