Increased line height for Consolas font in Eclipse
Asked Answered
E

3

14

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.

Eraeradiate answered 3/12, 2013 at 7:13 Comment(1)
Check out: github.com/Salauyou/Consolas-High-LineSigfried
H
6

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;
}
Heimlich answered 19/12, 2013 at 16:46 Comment(1)
This works but there are two problems. First if you use line numbering then this is unaffected and so will not match your content. Second the display of text selection introduces gaps rather than a full fill with occasional paint artefact appearing in the gap (padding between line).Cartogram
F
0

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

Furuncle answered 11/12, 2013 at 6:44 Comment(0)
M
0

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

Muggy answered 12/9, 2017 at 8:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.