diff --git a/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextArea.java b/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextArea.java index 6c45a3c3..8166a4e4 100755 --- a/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextArea.java +++ b/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextArea.java @@ -1045,6 +1045,18 @@ public boolean forceReparsing(Parser parser) { } + /** + * Overridden to return account for all fonts being used + * when determining the line height. + * + * @return The line height. + */ + @Override + public int getActualLineHeight() { + return lineHeight; + } + + /** * Returns whether bracket matching should be animated. * @@ -1412,17 +1424,6 @@ public int getLastVisibleOffset() { } - /** - * Returns the height to use for a line of text in this text area. - * - * @return The height of a line of text in this text area. - */ - @Override - public int getLineHeight() { - return lineHeight; - } - - public LinkGenerator getLinkGenerator() { return linkGenerator; } diff --git a/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/SyntaxView.java b/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/SyntaxView.java index 68a9635d..783cecba 100755 --- a/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/SyntaxView.java +++ b/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/SyntaxView.java @@ -736,10 +736,13 @@ public void paint(Graphics g, Shape a) { int heightAbove = clip.y - alloc.y; int linesAbove = Math.max(0, heightAbove / lineHeight); + // Top and bottom spacing around font if line height > font size + int verticalSpacing = (lineHeight - host.getActualLineHeight()) / 2; + FoldManager fm = host.getFoldManager(); linesAbove += fm.getHiddenLineCountAbove(linesAbove, true); Rectangle lineArea = lineToRect(a, linesAbove); - int y = lineArea.y + ascent; + int y = lineArea.y + verticalSpacing + ascent; int x = lineArea.x; Element map = getElement(); int lineCount = map.getElementCount(); @@ -801,8 +804,8 @@ public void paint(Graphics g, Shape a) { Color c = RSyntaxUtilities.getFoldedLineBottomColor(host); if (c!=null) { g.setColor(c); - g.drawLine(x,y+lineHeight-ascent-1, - host.getWidth(),y+lineHeight-ascent-1); + int lineY = y - verticalSpacing - ascent + lineHeight - 1; + g.drawLine(x, lineY, host.getWidth(), lineY); } // Skip to next line to paint, taking extra care for lines with diff --git a/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/FoldIndicator.java b/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/FoldIndicator.java index c27335d8..5920d20f 100755 --- a/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/FoldIndicator.java +++ b/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/FoldIndicator.java @@ -502,7 +502,7 @@ protected void paintComponent(Graphics g) { int topLine = (visibleRect.y-textAreaInsets.top)/cellHeight; int y = topLine*cellHeight + (cellHeight-collapsedFoldIcon.getIconHeight())/2; - y += textAreaInsets.top; + y += textAreaInsets.top - 1; // Get the first and last lines to paint. FoldManager fm = rsta.getFoldManager(); @@ -538,7 +538,7 @@ protected void paintComponent(Graphics g) { if (paintingOutlineLine) { g.setColor(getForeground()); int w2 = width / 2; - g.drawLine(w2, y + cellHeight / 2, w2, y + cellHeight); + g.drawLine(w2, y, w2, y + cellHeight / 2); } } if (mouseOverFoldIcon) { diff --git a/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/Gutter.java b/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/Gutter.java index d6445506..0cd9453a 100755 --- a/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/Gutter.java +++ b/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/Gutter.java @@ -1269,10 +1269,12 @@ public void propertyChange(PropertyChangeEvent e) { String name = e.getPropertyName(); - // If they change the text area's font, we need to update cell - // heights to match the font's height. + // If they change the text area's font, or any other property + // related to line height, we need to update cell heights to + // match the font's height. if ("font".equals(name) || - RSyntaxTextArea.SYNTAX_SCHEME_PROPERTY.equals(name)) { + RSyntaxTextArea.SYNTAX_SCHEME_PROPERTY.equals(name) || + RTextArea.LINE_HEIGHT_MULTIPLIER_PROPERTY.equals(name)) { for (int i=0; i font size + int verticalSpacing = (cellHeight - textArea.getActualLineHeight()) / 2; + // Get where to start painting (top of the row), and where to paint // the line number (drawString expects y==baseline). // We need to be "scrolled up" just enough for the missing part of @@ -388,7 +391,7 @@ protected void paintComponent(Graphics g) { } int topLine = (visibleRect.y-textAreaInsets.top)/cellHeight; int actualTopY = topLine*cellHeight + textAreaInsets.top; - int y = actualTopY + ascent; + int y = actualTopY + verticalSpacing + ascent; // Get the actual first line to paint, taking into account folding. FoldManager fm = null; @@ -726,9 +729,9 @@ public void setTextArea(RTextArea textArea) { /** - * Changes the height of the cells in the JList so that they are as tall as - * font. This function should be called whenever the user changes the Font - * of textArea. + * Changes the height of the cells in this component so that they are as + * tall as the font. This function should be called whenever the user + * changes the Font of textArea. */ private void updateCellHeights() { if (textArea!=null) { @@ -744,8 +747,8 @@ private void updateCellHeights() { /** - * Changes the width of the cells in the JList so you can see every digit - * of each. + * Changes the width of the cells in this component so you can see every + * digit of each. */ void updateCellWidths() { diff --git a/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/RTextAreaBase.java b/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/RTextAreaBase.java index 98135d69..ec35bbef 100755 --- a/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/RTextAreaBase.java +++ b/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/RTextAreaBase.java @@ -48,6 +48,7 @@ public abstract class RTextAreaBase extends JTextArea { public static final String CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY = "RTA.currentLineHighlightColor"; public static final String CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY = "RTA.currentLineHighlightFade"; public static final String HIGHLIGHT_CURRENT_LINE_PROPERTY = "RTA.currentLineHighlight"; + public static final String LINE_HEIGHT_MULTIPLIER_PROPERTY = "RTA.lineHeightMultiplier"; public static final String ROUNDED_SELECTION_PROPERTY = "RTA.roundedSelection"; private boolean tabsEmulatedWithSpaces; // If true, tabs will be expanded to spaces. diff --git a/RSyntaxTextAreaDemo/src/main/java/org/fife/ui/rsyntaxtextarea/demo/DemoRootPane.java b/RSyntaxTextAreaDemo/src/main/java/org/fife/ui/rsyntaxtextarea/demo/DemoRootPane.java index cf2a45bf..777383d6 100755 --- a/RSyntaxTextAreaDemo/src/main/java/org/fife/ui/rsyntaxtextarea/demo/DemoRootPane.java +++ b/RSyntaxTextAreaDemo/src/main/java/org/fife/ui/rsyntaxtextarea/demo/DemoRootPane.java @@ -263,6 +263,21 @@ private RSyntaxTextArea createTextArea() { im.put(KeyStroke.getKeyStroke(KeyEvent.VK_E, ctrlShift), "copyAsStyledTextEclipse"); am.put("copyAsStyledTextEclipse", createCopyAsStyledTextAction("eclipse")); + + im.put(KeyStroke.getKeyStroke(KeyEvent.VK_8, 0), "inc"); + am.put("inc", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + textArea.setLineHeightMultiplier(textArea.getLineHeightMultiplier() + 0.1f); + } + }); + im.put(KeyStroke.getKeyStroke(KeyEvent.VK_9, 0), "dec"); + am.put("dec", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + textArea.setLineHeightMultiplier(textArea.getLineHeightMultiplier() - 0.1f); + } + }); } catch (IOException ioe) { ioe.printStackTrace(); }