Skip to content

Commit c199843

Browse files
committed
WIP fix for #160 - Configurable Line Height. This currently makes the line height configurable when word wrap is NOT enabled. Line number list is also updated. Fold indicators do not currently work properly - they only update in the demo app because I've tied '8' and '9' keypresses to tweaking the line height for quick testing. I think what still needs to be done is: fold indicator immediate updating, fold indicator rendering of 'active' fold line, and *everything* when word wrap is enabled
1 parent cc84081 commit c199843

7 files changed

Lines changed: 50 additions & 25 deletions

File tree

RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextArea.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,18 @@ public boolean forceReparsing(Parser parser) {
10451045
}
10461046

10471047

1048+
/**
1049+
* Overridden to return account for all fonts being used
1050+
* when determining the line height.
1051+
*
1052+
* @return The line height.
1053+
*/
1054+
@Override
1055+
public int getActualLineHeight() {
1056+
return lineHeight;
1057+
}
1058+
1059+
10481060
/**
10491061
* Returns whether bracket matching should be animated.
10501062
*
@@ -1412,17 +1424,6 @@ public int getLastVisibleOffset() {
14121424
}
14131425

14141426

1415-
/**
1416-
* Returns the height to use for a line of text in this text area.
1417-
*
1418-
* @return The height of a line of text in this text area.
1419-
*/
1420-
@Override
1421-
public int getLineHeight() {
1422-
return lineHeight;
1423-
}
1424-
1425-
14261427
public LinkGenerator getLinkGenerator() {
14271428
return linkGenerator;
14281429
}

RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/SyntaxView.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,13 @@ public void paint(Graphics g, Shape a) {
736736
int heightAbove = clip.y - alloc.y;
737737
int linesAbove = Math.max(0, heightAbove / lineHeight);
738738

739+
// Top and bottom spacing around font if line height > font size
740+
int verticalSpacing = (lineHeight - host.getActualLineHeight()) / 2;
741+
739742
FoldManager fm = host.getFoldManager();
740743
linesAbove += fm.getHiddenLineCountAbove(linesAbove, true);
741744
Rectangle lineArea = lineToRect(a, linesAbove);
742-
int y = lineArea.y + ascent;
745+
int y = lineArea.y + verticalSpacing + ascent;
743746
int x = lineArea.x;
744747
Element map = getElement();
745748
int lineCount = map.getElementCount();
@@ -801,8 +804,8 @@ public void paint(Graphics g, Shape a) {
801804
Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
802805
if (c!=null) {
803806
g.setColor(c);
804-
g.drawLine(x,y+lineHeight-ascent-1,
805-
host.getWidth(),y+lineHeight-ascent-1);
807+
int lineY = y - verticalSpacing - ascent + lineHeight - 1;
808+
g.drawLine(x, lineY, host.getWidth(), lineY);
806809
}
807810

808811
// Skip to next line to paint, taking extra care for lines with

RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/FoldIndicator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ protected void paintComponent(Graphics g) {
502502
int topLine = (visibleRect.y-textAreaInsets.top)/cellHeight;
503503
int y = topLine*cellHeight +
504504
(cellHeight-collapsedFoldIcon.getIconHeight())/2;
505-
y += textAreaInsets.top;
505+
y += textAreaInsets.top - 1;
506506

507507
// Get the first and last lines to paint.
508508
FoldManager fm = rsta.getFoldManager();
@@ -538,7 +538,7 @@ protected void paintComponent(Graphics g) {
538538
if (paintingOutlineLine) {
539539
g.setColor(getForeground());
540540
int w2 = width / 2;
541-
g.drawLine(w2, y + cellHeight / 2, w2, y + cellHeight);
541+
g.drawLine(w2, y, w2, y + cellHeight / 2);
542542
}
543543
}
544544
if (mouseOverFoldIcon) {

RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/Gutter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,10 +1269,12 @@ public void propertyChange(PropertyChangeEvent e) {
12691269

12701270
String name = e.getPropertyName();
12711271

1272-
// If they change the text area's font, we need to update cell
1273-
// heights to match the font's height.
1272+
// If they change the text area's font, or any other property
1273+
// related to line height, we need to update cell heights to
1274+
// match the font's height.
12741275
if ("font".equals(name) ||
1275-
RSyntaxTextArea.SYNTAX_SCHEME_PROPERTY.equals(name)) {
1276+
RSyntaxTextArea.SYNTAX_SCHEME_PROPERTY.equals(name) ||
1277+
RTextArea.LINE_HEIGHT_MULTIPLIER_PROPERTY.equals(name)) {
12761278
for (int i=0; i<getComponentCount(); i++) {
12771279
AbstractGutterComponent agc =
12781280
(AbstractGutterComponent)getComponent(i);

RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/LineNumberList.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ protected void paintComponent(Graphics g) {
377377
return;
378378
}
379379

380+
// Top and bottom spacing around font if line height > font size
381+
int verticalSpacing = (cellHeight - textArea.getActualLineHeight()) / 2;
382+
380383
// Get where to start painting (top of the row), and where to paint
381384
// the line number (drawString expects y==baseline).
382385
// We need to be "scrolled up" just enough for the missing part of
@@ -388,7 +391,7 @@ protected void paintComponent(Graphics g) {
388391
}
389392
int topLine = (visibleRect.y-textAreaInsets.top)/cellHeight;
390393
int actualTopY = topLine*cellHeight + textAreaInsets.top;
391-
int y = actualTopY + ascent;
394+
int y = actualTopY + verticalSpacing + ascent;
392395

393396
// Get the actual first line to paint, taking into account folding.
394397
FoldManager fm = null;
@@ -726,9 +729,9 @@ public void setTextArea(RTextArea textArea) {
726729

727730

728731
/**
729-
* Changes the height of the cells in the JList so that they are as tall as
730-
* font. This function should be called whenever the user changes the Font
731-
* of <code>textArea</code>.
732+
* Changes the height of the cells in this component so that they are as
733+
* tall as the font. This function should be called whenever the user
734+
* changes the Font of <code>textArea</code>.
732735
*/
733736
private void updateCellHeights() {
734737
if (textArea!=null) {
@@ -744,8 +747,8 @@ private void updateCellHeights() {
744747

745748

746749
/**
747-
* Changes the width of the cells in the JList so you can see every digit
748-
* of each.
750+
* Changes the width of the cells in this component so you can see every
751+
* digit of each.
749752
*/
750753
void updateCellWidths() {
751754

RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/RTextAreaBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class RTextAreaBase extends JTextArea {
4848
public static final String CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY = "RTA.currentLineHighlightColor";
4949
public static final String CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY = "RTA.currentLineHighlightFade";
5050
public static final String HIGHLIGHT_CURRENT_LINE_PROPERTY = "RTA.currentLineHighlight";
51+
public static final String LINE_HEIGHT_MULTIPLIER_PROPERTY = "RTA.lineHeightMultiplier";
5152
public static final String ROUNDED_SELECTION_PROPERTY = "RTA.roundedSelection";
5253

5354
private boolean tabsEmulatedWithSpaces; // If true, tabs will be expanded to spaces.

RSyntaxTextAreaDemo/src/main/java/org/fife/ui/rsyntaxtextarea/demo/DemoRootPane.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ private RSyntaxTextArea createTextArea() {
263263

264264
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_E, ctrlShift), "copyAsStyledTextEclipse");
265265
am.put("copyAsStyledTextEclipse", createCopyAsStyledTextAction("eclipse"));
266+
267+
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_8, 0), "inc");
268+
am.put("inc", new AbstractAction() {
269+
@Override
270+
public void actionPerformed(ActionEvent e) {
271+
textArea.setLineHeightMultiplier(textArea.getLineHeightMultiplier() + 0.1f);
272+
}
273+
});
274+
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_9, 0), "dec");
275+
am.put("dec", new AbstractAction() {
276+
@Override
277+
public void actionPerformed(ActionEvent e) {
278+
textArea.setLineHeightMultiplier(textArea.getLineHeightMultiplier() - 0.1f);
279+
}
280+
});
266281
} catch (IOException ioe) {
267282
ioe.printStackTrace();
268283
}

0 commit comments

Comments
 (0)