Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<getComponentCount(); i++) {
AbstractGutterComponent agc =
(AbstractGutterComponent)getComponent(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ protected void paintComponent(Graphics g) {
return;
}

// Top and bottom spacing around font if line height > 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
Expand All @@ -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;
Expand Down Expand Up @@ -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 <code>textArea</code>.
* 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 <code>textArea</code>.
*/
private void updateCellHeights() {
if (textArea!=null) {
Expand All @@ -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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading