monospaced fonts not quite monospaced

  • hujhax

    hujhax - 2009-01-14

    I'm not 100% sure this is a bug, but it sure seems like it....

    1.  Go to Settings->Styler Configurator.
    2.  Set Global Styles->Default Style->Font Name to "Courier".
    3.  Open a "Normal Text" file.

    At this point, you should get text like this:
    The spaces are as wide as characters, as they should be.  Now...

    4.  Go to Settings->Styler Configurator.
    5.  Set Global Styles->Default Style->Font Name to "Times New Roman".
    6.  Set C++->DEFAULT->Font Name  to "Courier"
    7.  Open a C++ file.

    At this point, you get default text like this:

    The spaces are *not* the same width as the characters, which isn't how a monospace font is supposed to work.

    Is this intended behavior?  (I'm using ANSI 5.1.4 on WinXP SP3, FWIW.)

    • Jason

      Jason - 2009-02-04

      All fonts used have to be the same for monospace to truly be monospace -- all styles in Global Styles and C++ styles.  (Once you set Global Styles / Default Style, you can set the rest to have a blank font name and size.)  I also remember having a few Bold styles screwing  up the spacing, but it seems to work now for Lucida Console and Courier.

    • Sune Marcher

      Sune Marcher - 2009-01-14

      Hm, for some reason this combination probably ends up using both Courier and Times New Roman fonts - which both are monospace, but have different sizes? Sounds weird that this happens, but at least it could explain what's happening.

      • Bob Uncle

        Bob Uncle - 2009-01-19

        Times New Roman is not a monospaced font. If it is using both Courier for the text and Times for the spaces, that would explain the different size of spaces than expected.

        I cannot see the links you provided so I cannot reply to that specifically.

    • hujhax

      hujhax - 2009-01-25

      Additional note:  it looks like line spacing is also a problem.

      You can set the default font size to whatever you want for C++ -- it'll still use the line spacing from the *global* font size, if one is set.

  • Aru

    Aru - 2013-04-21

    Over four years later, and this is still a problem, and still the number one reason I don't want to use notepad++ as a code and text editor. Monospaced whitespace is kind of important for coding. And by kind of I mean extremely. For all of it's language and theme options, I have yet to find a way to have it actually change fonts with file extension.

    Looks like it's either code or plain text, never both.

    edit: Thought I'd add, comments are monospaced, but code isn't. I kind of know why, but from what browsing of the styles xml file I've done there doesn't seem to be any way to fix this. It's hard coded into the language a little deeper than the style sheets. (Though it probably should be available via the style sheet.) It works properly for some languages (Python) but not others (C++).

    Whitespace that isn't part of an explicit style (comments and preprocessor) passes through to the 'Default Style' of the 'Global Styles' language. Most obvious fix would be to make 'DEFAULT' include whitespace and everything else that isn't included by the other styles (instead of just identifiers), which is probably what it was supposed to do in the first place.

    Also, for certain themes and languages, the DEFAULT style shows the 'Default keywords' and 'User-defined keywords' input boxes, which it's not supposed to. They don't do anything but mirror the default keywords of the next style down.

    Last edit: Aru 2013-04-27
    • Aru

      Aru - 2013-04-27

      Bump I guess..

  • François-R Boyer

    I verified and this is caused by an error in the stylers.xml file given with Notepad++. Most probably, Scintilla lexers were updated and stylers.xml was not modified to follow. For example, for C++, "DEFAULT" is styleID 11 in stylers.xml while SCE_C_DEFAULT is 0 in SciLexer.h. So DEFAULT should be styleID 0, styleID 11 should be IDENTIFIER, and there are missing UUID (8), STRING EOL (12), GLOBAL CLASS (19), STRING RAW (20), and TRIPLE VERBATIM (21). You can do these modifications to your stylers.xml and it will work.

  • Loreia2

    Loreia2 - 2013-08-12

    Ok, I just played around with this thing and this is what it comes down to.

    1. DEFAULT style covers visible characters and it is set through styles.xml file (for each language individually)
    2. IDENTIFIER style covers white space

    For some reason IDENTIFIER is not defined in styles.xml file for C++. Therefore you can't set it in Styles configurator, and therefore it gets value from global default.

    Solution for C++ language:
    1. Open styles.xml in external editor (not N++).
    2. For C++ language copy line where DEFAULT style is defined (to have two identical lines)
    3. Define DEFAULT to have styleID="0" (fix styleID)
    4. Define IDENTIFIER to have styleID="11" (fix name)
    5. Save

    Open N++, it will have one more entry for C++ language (IDENTIFIER).
    When you set value for DEFAULT style, you will have to set the same style for IDENTIFIER too.

    And that's it.
    To paraphrase the title, everything is monospaced again :-)

    Anyway, it looks like there are quite some problems with styles.xml file. A lot of styleID's have to be updated to follow macros from SciLexer.cpp file.
    I'll try to do it in next couple of days, and then send the new version to Don. Until then fix your own styles.xml file manually.


    Last edit: Loreia2 2013-08-12
  • hujhax

    hujhax - 2014-03-29

    Yay! happy to see that there's a solution for C++.

    I tried making this same change (copy the DEFAULT line, set the new line to IDENTIFIER) for a user-defined language in which the font is monospaced, and it seemed to have no effect.

    Any idea how I'd sort out the spaces in a user-defined language?