Bug 531768 - [StyledText] Draw content which takes place with GlyphMetrics#insert
Summary: [StyledText] Draw content which takes place with GlyphMetrics#insert
Status: CLOSED DUPLICATE of bug 531769
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-27 19:10 EST by Angelo ZERR CLA
Modified: 2018-02-28 03:32 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Angelo ZERR CLA 2018-02-27 19:10:14 EST
The inlined annotation support draw line content annotations by using GlyphMetrics#width which are set with StyledText#setStyleRange for a given offset when annotation is drawn (see InlinedAnnotationDrawingStrategy). The offset used contains a character (character after the GlyphMetrics) which is replaced by GlyphMetrics, in other words the character disapear. To fix this problem the draw of inlined annotation:

 * draw the content of the inlined annotation
 * redraw the character which is replaced by GlyphMetrics

This redraw is not perfect because it doesn't take care of some background color like selection, line cusrsor, etc

You can see the trouble with a simple snippet:

 * the StyledText contains "abc"
 * the insert of GlyphMetrics after the character "a" (offset of "b" character replace "b" and "b" is not visible.

Here the snippet:

-----------------------------------------------------------------
StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
text.setText("abc");

// insert a blank space after "a" by replacing "b" character
GlyphMetrics metrics = new GlyphMetrics(0, 0, 100);

StyleRange style = new StyleRange();
style.start = 1;
style.length = 1;
style.metrics = metrics;
text.setStyleRange(style);
-----------------------------------------------------------------

The StyledText will contain ("b" is hidden by GlyphMetrics):
-----------------------------------------------------------------
a          c
-----------------------------------------------------------------

My idea to fix this problem (and manage line content annotation with clean mean without redrawing the character "b") is that GlyphMetrics should provide a new field "insert"

-----------------------------------------------------------------
/**
 * true if metrics should be inserted in the given offset and false othewise.
 */
public boolean insert;
-----------------------------------------------------------------

Here  the same snippet with "metrics.insert = true;"

-----------------------------------------------------------------
StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
text.setText("abc");

// insert a blank space after "a" and before "b" ("b" is visible)
GlyphMetrics metrics = new GlyphMetrics(0, 0, 100);
metrics.insert = true;

StyleRange style = new StyleRange();
style.start = 1;
style.length = 1;
style.metrics = metrics;
text.setStyleRange(style);
-----------------------------------------------------------------

To provide this feature, the TextLayout of each OS must be changed. As I have only Windows OS, I have supported that for windows. 

I will create a gerrit patch with this snippet and support of GlyphMetrics#insert only for windows.

If you like this idea, I hope that they will have people which will update too TextLayout for other OS.

@Mickael, do you like this idea? If yes, do you think there is any chance that  we will find people who will implement GlyphMetrics#insert for other OS?

IMHO I think we should have this feature to provide a better draw of inlined line content annotation (without redrawing the character will support selection, line cursor, etc)
Comment 1 Niraj Modi CLA 2018-02-28 03:17:06 EST
Bug title/content similar to bug 531769(which additionally as a gerrit.)

*** This bug has been marked as a duplicate of bug 531769 ***
Comment 2 Angelo ZERR CLA 2018-02-28 03:32:25 EST
Oooops sorry @Niraj with my mistake.