Skip to content

Commit

Permalink
Add test for StyledText with fixed font metrics
Browse files Browse the repository at this point in the history
This commit adds a test for StyledText with fixed font metrics that led to a regression with #1610
  • Loading branch information
akoch-yatta authored and fedejeanne committed Dec 20, 2024
1 parent 534e994 commit c088611
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.GlyphMetrics;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
Expand Down Expand Up @@ -5934,4 +5936,22 @@ public void test_rangeSelectionKeepsCaret() {
assertEquals("Selection does not start from caret", initialOffset, text.getSelection().x);
assertNotEquals("Selection is not left-to-right", text.getSelection().x, text.getCaretOffset());
}

@Test
public void test_bug1610_fixedLineHeightWithChangingToSmallerFont_noException() {
shell.setVisible(true);
shell.setLayout(new GridLayout(1, false));

GC gc = new GC(shell.getDisplay());
FontMetrics metrics = gc.getFontMetrics();
text.setFixedLineMetrics(metrics);

FontData fontData = text.getFont().getFontData()[0];
text.setText("");
int smallFontHeight = metrics.getAscent() + metrics.getDescent() - 4;
Font font = new Font(text.getDisplay(), fontData.getName(), smallFontHeight, fontData.getStyle());
text.setFont(font);
font.dispose();
gc.dispose();
}
}

0 comments on commit c088611

Please sign in to comment.