Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 63154 - JavaEditor draws squiggle underline over the string
Summary: JavaEditor draws squiggle underline over the string
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: 3.0 M9   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-19 19:07 EDT by Felipe Heidrich CLA
Modified: 2004-05-22 05:31 EDT (History)
2 users (show)

See Also:


Attachments
Picture (14.34 KB, image/jpeg)
2004-05-21 09:35 EDT, Felipe Heidrich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Felipe Heidrich CLA 2004-05-19 19:07:18 EDT
build I20040519

JavaEditor draws squiggle underline over the string (a.k.a red see).
This problem is been caused by SWT. It was introduced when we added italic 
font support.

Here is the situation:
The application set a font in the StyledText. Internally StyledText will 
create 3 more fonts: boldFont, italicFont, boldItalicFont.
In order to line up normal, bold, italic, and boldItalic segments of text in 
the same line StyledText need to compute the max baseline amongs all those 
fonts. Usually these font have same (or very similar) metrics, but sometimes 
they are not (example: default font in Solaris).

I believe the code that draws the squiggle is getting the normal font from the 
StyledText, getting its metrics, compute the baseline (ascent+descent), and 
draws the squiggle at y + baseline. Since this baseline can be less than the 
maxBaseline it possible that the siggle will be drawn over the text instead of 
the real baseline where the strings where drawn.

Right now we have two solutions:
1) The app code will need to create all the fonts and do the same styledtext 
is doing.

2) We add getBaseline() to StyledText and app code start to using it instead 
of getting the line metrics.
Comment 1 Felipe Heidrich CLA 2004-05-20 17:20:32 EDT
StyledText#getBaseline() API added.
Comment 2 Jim des Rivieres CLA 2004-05-20 17:27:34 EDT
The SWT StyledText API change has PMC approval for inclusion in 3.0 M9.
Comment 3 Dani Megert CLA 2004-05-20 17:33:02 EDT
which build will contain this?
Comment 4 Jim des Rivieres CLA 2004-05-20 17:43:05 EDT
Carolyn says it will appear in the 20:00 EDT build.
Comment 5 Dani Megert CLA 2004-05-21 04:57:53 EDT
We adopted the new API for I200405210800.

Just one remark: we used gc.getFont().getFontMetric().getHeight() - 1 to draw
the squiggly line i.e. always at the bottom. Would using
StyledText.getLineHeight() instead also have fixed the problem?
Comment 6 Felipe Heidrich CLA 2004-05-21 09:27:02 EDT
"gc.getFont().getFontMetric().getHeight() - 1" it means you don't draw at the 
baseline. Height is the ascent+descent+leading. You draw at the bottom of the 
string. The baseline is ascent+leading.

I set the font of the JavaEditor to Tahoma 36 and it seems that the bottom of 
the squiggle is at lineY + lineHeight. IMO, the top of the squiggle should be 
at lineY + baseline.
Comment 7 Dani Megert CLA 2004-05-21 09:33:40 EDT
Up to now we actually drew it at the bottom using the code I described. The
questions are:
- why did this cause the squiggly lines to appear in the text on Solaris
- is StyledText.getLineHeight() better than
gc.getFont().getFontMetric().getHeight() which we used i.e. if we would have
simply replaced this with StyledText.getLineHeight() would this have fixed the
problem (still at the bottom though)?

We now draw it at the baseline. I simply want to understand why it drew the into
the string using gc.getFont().getFontMetric().getHeight() -1 and whether it
would have worked using StyledText.getLineHeight(). We use getHeight at several
other places and those might be affected then as well.


Comment 8 Felipe Heidrich CLA 2004-05-21 09:35:28 EDT
Created attachment 10942 [details]
Picture

Top image: the bottom of the squiggle drawn at y + lineHeight
Bottom image: the top of the squiggle drawn at y + baseline
Comment 9 Felipe Heidrich CLA 2004-05-21 10:32:07 EDT
- gc.getFont().getFontMetric().getHeight()  returns the height of the normal 
font only.
- styledText.getLineHeight() returns the max height of all the fonts used by 
the styledtext. 
Yes, you could fix this by using styledText.getLineHeight().

It failed because some OS don't have a lot of fonts so when styledtext create 
a bold or italic version of the normal font it's possible that these fonts 
won't have the same height (example: the system don't have a courier-bold-10 
so it returns a courier-bold-12) this would cause styledtext to draw its 
strings a few pixels down so it can line up bold/italic/normal text at the 
same baseline. Since the squiggle don't know that the text was moved down a 
few pixels it ends up drawing on the wrong place, potencially over the text.
Comment 10 Dani Megert CLA 2004-05-21 10:36:33 EDT
I guess we should then revisit our code and replace
gc.getFont().getFontMetric().getHeight() with StyledText.getLineHeight() where
possible, right?
Comment 11 Felipe Heidrich CLA 2004-05-21 10:54:38 EDT
Yes, that would be good.
Comment 12 Dani Megert CLA 2004-05-21 11:00:20 EDT
created bug 63423 for this
Comment 13 Steve Northover CLA 2004-05-21 17:48:40 EDT
Seems to me we could have called getLineHeight() to draw the squiggles in the 
same place as we used to.  Strictly speaking, getBaseline() returns the 
correct place for them but getLineHeight() would implement approximately the 
3.0 behavior.

Depending on what Felipe and SSQ think, we could *consider* removing the API.
Comment 14 Dani Megert CLA 2004-05-22 05:31:09 EDT
I don't think so. Sometimes we need to know the line height in order to e.g.
draw an icon in the middle of the line or draw the line number ruler.