Skip to content

Commit c088611

Browse files
akoch-yattafedejeanne
authored andcommitted
Add test for StyledText with fixed font metrics
This commit adds a test for StyledText with fixed font metrics that led to a regression with #1610
1 parent 534e994 commit c088611

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java

+20
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
import org.eclipse.swt.graphics.Color;
6464
import org.eclipse.swt.graphics.Font;
6565
import org.eclipse.swt.graphics.FontData;
66+
import org.eclipse.swt.graphics.FontMetrics;
67+
import org.eclipse.swt.graphics.GC;
6668
import org.eclipse.swt.graphics.GlyphMetrics;
6769
import org.eclipse.swt.graphics.Point;
6870
import org.eclipse.swt.graphics.RGB;
@@ -5934,4 +5936,22 @@ public void test_rangeSelectionKeepsCaret() {
59345936
assertEquals("Selection does not start from caret", initialOffset, text.getSelection().x);
59355937
assertNotEquals("Selection is not left-to-right", text.getSelection().x, text.getCaretOffset());
59365938
}
5939+
5940+
@Test
5941+
public void test_bug1610_fixedLineHeightWithChangingToSmallerFont_noException() {
5942+
shell.setVisible(true);
5943+
shell.setLayout(new GridLayout(1, false));
5944+
5945+
GC gc = new GC(shell.getDisplay());
5946+
FontMetrics metrics = gc.getFontMetrics();
5947+
text.setFixedLineMetrics(metrics);
5948+
5949+
FontData fontData = text.getFont().getFontData()[0];
5950+
text.setText("");
5951+
int smallFontHeight = metrics.getAscent() + metrics.getDescent() - 4;
5952+
Font font = new Font(text.getDisplay(), fontData.getName(), smallFontHeight, fontData.getStyle());
5953+
text.setFont(font);
5954+
font.dispose();
5955+
gc.dispose();
5956+
}
59375957
}

0 commit comments

Comments
 (0)