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
-
- Can't get richer than this
- Posts: 747
- Joined: Tue Mar 31, 2009 2:11 am
Stop wxRichTextCtrl Text Shifting
You do not have the required permissions to view the files attached to this post.
-
- Moderator
- Posts: 19164
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
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!
-
- Part Of The Furniture
- Posts: 7481
- Joined: Sat Apr 16, 2005 7:22 am
- Location: USA, Ukraine
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.
-
- Can't get richer than this
- Posts: 747
- Joined: Tue Mar 31, 2009 2:11 am
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?
}