Skip to content

Commit b7fbbfe

Browse files
fix calculation of multiline heigth on windows with consolas size 9
1 parent 6957472 commit b7fbbfe

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,14 @@ public CodeMiningLineHeaderAnnotation(Position position, ISourceViewer viewer) {
7777

7878
@Override
7979
public int getHeight() {
80-
return hasAtLeastOneResolvedMiningNotEmpty() ? getMultilineHeight() : 0;
80+
return hasAtLeastOneResolvedMiningNotEmpty() ? getMultilineHeight(null) : 0;
8181
}
8282

83-
private int getMultilineHeight() {
83+
public int getHeight(GC gc) {
84+
return hasAtLeastOneResolvedMiningNotEmpty() ? getMultilineHeight(gc) : 0;
85+
}
86+
87+
private int getMultilineHeight(GC gc) {
8488
int numLinesOfAllMinings= 0;
8589
for (ICodeMining mining : fMinings) {
8690
String label= mining.getLabel();
@@ -94,7 +98,17 @@ private int getMultilineHeight() {
9498
}
9599
numLinesOfAllMinings++;
96100
StyledText styledText= super.getTextWidget();
97-
return numLinesOfAllMinings * (styledText.getLineHeight() + styledText.getLineSpacing());
101+
int lineHeight;
102+
if (gc != null) {
103+
// styledText.getLineHeight() returns 14 pixels for font "Consolas" size 9 on windows
104+
// gc.textExtent() for italic character "f" returns 15 pixels
105+
Point ext= gc.textExtent("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); //$NON-NLS-1$
106+
lineHeight= ext.y;
107+
} else {
108+
lineHeight= styledText.getLineHeight();
109+
}
110+
int result= numLinesOfAllMinings * (lineHeight + styledText.getLineSpacing());
111+
return result;
98112
}
99113

100114
/**

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.swt.graphics.Rectangle;
2626

2727
import org.eclipse.jface.internal.text.codemining.CodeMiningLineContentAnnotation;
28+
import org.eclipse.jface.internal.text.codemining.CodeMiningLineHeaderAnnotation;
2829

2930
import org.eclipse.jface.text.ITextViewer;
3031
import org.eclipse.jface.text.source.Annotation;
@@ -161,7 +162,12 @@ private static void draw(LineHeaderAnnotation annotation, GC gc, StyledText text
161162
}
162163
if (gc != null) {
163164
// Setting vertical indent first, before computing bounds
164-
int height= annotation.getHeight();
165+
int height;
166+
if (annotation instanceof CodeMiningLineHeaderAnnotation cmlha) {
167+
height= cmlha.getHeight(gc);
168+
} else {
169+
height= annotation.getHeight();
170+
}
165171
if (height != 0) {
166172
if (height != textWidget.getLineVerticalIndent(line)) {
167173
if (annotation.oldLine != -1 && annotation.oldLine < textWidget.getLineCount()) {

0 commit comments

Comments
 (0)