Increased line height for Consolas font in Eclipse

5.9k views Asked by At

Many people are using Consolas for their primary programming font but unfortunately there is no way to change line height in Eclipse so it looks kinda ugly as it is shown below:

enter image description here

I was wondering if there is anyone who solved this by adding some extra space between lines or simply changing the font itself which has longer height now.

It would be nice to share it with us here on Stackoverflow.

There are some topics I've found while searching for this but none of them were what I am looking for:

  1. How can I change line height / line spacing in Eclipse?
  2. https://stackoverflow.com/questions/15153938/improved-line-spacing-for-eclipse?lq=1
  3. and so on...

Some of them designed their own fonts (such as Meslo Font) by modifying the existing ones so it would be nice if you could share your modified Consolas font.

3

There are 3 answers

1
greg-449 On BEST ANSWER

As mentioned in one of the answers you reference the underlying StyledText control does have a setLineSpacing method, but the existing editors do not use it.

The CSS styling code in Eclipse 4.3 does provide a way to access this but it requires writing a plugin to extend the CSS in order to do so.

The plugin.xml for the plugin would look like this:

<plugin>
   <extension
         point="org.eclipse.e4.ui.css.core.elementProvider">
      <provider
            class="linespacing.LineSpacingElementProvider">
         <widget
               class="org.eclipse.swt.custom.StyledText"></widget>
      </provider>
   </extension>
   <extension
         point="org.eclipse.e4.ui.css.core.propertyHandler">
      <handler
            adapter="linespacing.StyledTextElement"
            composite="false"
            handler="linespacing.LineSpacingPropertyHandler">
         <property-name
               name="line-spacing">
         </property-name>
      </handler>
   </extension>
</plugin>

which declares a CSS element provider LineSpacingElementProvider which would be:

public class LineSpacingElementProvider implements IElementProvider
{
  @Override
  public Element getElement(final Object element, final CSSEngine engine)
  {
    if (element instanceof StyledText)
      return new StyledTextElement((StyledText)element, engine);

    return null;
  }
}

The StyledTextElement this provides is just:

public class StyledTextElement extends ControlElement
{
  public StyledTextElement(StyledText control, CSSEngine theEngine)
  {
    super(control, theEngine);
  }
}

The second declaration in the plugin.xml is a CSS property handler for a property called line-spacing

public class LineSpacingPropertyHandler extends AbstractCSSPropertySWTHandler implements ICSSPropertyHandler
{
  @Override
  protected void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception
  {
    if (!(control instanceof StyledText))
      return;

    StyledText text = (StyledText)control;

    if ("line-spacing".equals(property))
     {
       int pixelValue = (int)((CSSPrimitiveValue)value).getFloatValue(CSSPrimitiveValue.CSS_PX);

       text.setLineSpacing(pixelValue);
     }
  }

  @Override
  protected String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine) throws Exception
  {
     return null;
  }
}

With a plugin containing this installed you can then modify one of the existing CSS style sheets to contain:

StyledText {
    line-spacing: 2px;
}
0
Foolish On

You better choose different fonts. Don't just stick to things. Try new things and accept them. :D I was also using Consolas. But now I am using Courier New and they are pretty fine. If you have 21" or larger display you can use Courier New at 12 or 14 size. Once you use this you will get used to it as you are with Consolas now :P

0
aliopi On

You could try Fira Mono. See some screenshots here. Small sizes look good too.