Bug 26258 - TextBox can have garbled text and/or misplaced cursor
Summary: TextBox can have garbled text and/or misplaced cursor
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms ()
Version: 3.4.0
Hardware: PC Linux
: --- normal
Target Milestone: Community
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-21 18:19 UTC by Stephen McConnel
Modified: 2017-12-06 08:01 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
I'm attaching a screenshot showing the bug in action. (60.50 KB, image/png)
2015-01-22 16:37 UTC, Stephen McConnel
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 26258 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Stephen McConnel 2015-01-21 18:19:51 UTC
For certain fonts at certain point sizes, text that is being typed can be misdisplayed, with the cursor offset from where it should be showing.  This may require that a text box have preloaded text to manifest itself.  We've seen this problem off and on for a long time, but had never been able to pinpoint what was going on.

The code for TextBoxTextRenderer.MeasureText() (in System.Windows.Forms/TextBoxTextRenderer.cs) caches measurements for single characters.  This works well 99.99% of the time, but occasionally records a value that differs from what is dynamically determined later on as part of a long string.  After tracing things for a couple of days, I've finally determined that the mismeasurements occur when the Graphics object has a VisibleClipRectangle with Height=1 and Width=1.  If the caching is avoided under those circumstances, then everything seems to work okay.

I'll submit a pull request with my suggested fix tomorrow after testing it further.  I could also submit screen shots or a test program if desired.  :-)
Comment 1 Stephen McConnel 2015-01-22 14:00:10 UTC
I've submitted pull request https://github.com/mono/mono/pull/1522.

Note that further testing showed that the differing values occur only when
the Graphics object VisibleClipRectangle is {X=0,Y=0,Width=1,Height=1}.  The
fix submitted caches those values as well by modifying the key to allow two values for the same font and character.
Comment 2 Stephen McConnel 2015-01-22 16:37:06 UTC
Created attachment 9452 [details]
I'm attaching a screenshot showing the bug in action.