Increased line height for Consolas font in Eclipse

consolas, eclipse, fonts

Solution

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;
}

Problem

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: 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: - How can I change line height / line spacing in Eclipse? - https://stackoverflow.com/questions/15153938/improved-line-spacing-for-eclipse?lq=1 - 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.

Original source

Related problems