How does the font tell the OS that "I AM THE MONASSIFIED / FIXED FONT"?

at the very beginning, I just want to know why in the PYCHARM IDE on Windows 10, when only "monospaced fonts" are checked, many fonts will not be displayed in the editor's font selection dialog [settings / editor / colors and fonts / font], also in mintty.

I don't know how pycharm works, but mintty uses the win32 API "LOGFONT".

how does Windows OS know if a font is monospaced (fixed-width)?

ie: "pro source" is specified, "pro source black / extralight / light ... is not;

"fira code" is specified, but fira code light / medium / retina is not;

and some other monospaced fonts are not listed there if "show monospace only".

It seems that pycharm only recognizes the font surname when "show only monospaced fonts" is checked

on OSX (Mavericks) it's a bit tricky: if "only show monospaced fonts" was checked, pycharm could still get the last name, but it couldn't know what default font size was used if the coarse weighted version was installed.


then I tried to change some fonts and by the way looking at the original "file-info" font in the font forge, but I don't know which part really affects WINDOWS or PYCHARM (IDEA / INTELIJ / is actually JDK?) to find out which font is monospaced.

in the "OS / 2" section, all the options mentioned as fixed-width / monospace / monospaced are checked but don't help, and in windows pycharm still can't detect them.

so finally i really wonder what setting do ttf files or any other font file types do to tell windows / osx / mac os / linux that "i am monospaced"?

+3


source to share


2 answers


A TrueType font can contain a table post

. The table post

contains a 32-bit field named isFixedPitch

. If it contains 0

, it indicates a proportional font. A monospaced font should have this set in 1

(but it is generally recommended that the font engine accept any non-zero value denoting a monospaced font, as this is what was required by earlier versions of the TT specification).

Monospaced font should also have numberOfHMetrics

tables hhea

and hmtx

installed on 3

.

There is also data in the corkscrew font mapping data (in the OS / 2 table) to indicate whether the font is monospaced or not.

If I had to guess, I would say that Apple is more likely to use a table post

, while Microsoft is more likely to use Panose data (but I might be wrong about one or the other).




Literature:

+1


source


PyCharm, in which case all JetBrains IDEA packages do not use font flags to identify monospaced fonts. Instead, they determine if a font is monospaced using the following algorithm:

  • The characters 'l'

    , 'W'

    and ' '

    are the same width in size 12?
  • Are the 'l'

    , 'W'

    and ' '

    bold characters the same width at size 12?
  • Are characters 'l'

    , 'W'

    and ' '

    italicized the same width at size 12?
  • Are the characters 'l'

    , 'W'

    and ' '

    bold italic same width at a rate of 12?

The font will be listed as non-monospaced if any of the width calculations above return an inconsistent answer.

To fix this problem, you must install the bold version of the font you are trying to use. If a bold version of a font is not available, the IntelliJ font renderer will automatically generate one that affects the character widths and therefore causes the monospace check to fail.




Source : Source Code of the IntelliJ Community Version (Excerpts abbreviated for brevity and licensed under Apache 2.0, not StackOverflow CC-BY-SA licenses.)

private static int getFontWidth(Font font, int mask) {
    int width = getCharWidth(font, ' ');
    return width == getCharWidth(font, 'l')
        && width == getCharWidth(font, 'W') ? width : 0;
}

      

In the constructor FontInfo

.

int width = getFontWidth(font, Font.PLAIN);
if (!plainOnly) {
    if (width != 0 && width != getFontWidth(font, Font.BOLD)) width = 0;
    if (width != 0 && width != getFontWidth(font, Font.ITALIC)) width = 0;
    if (width != 0 && width != getFontWidth(font, Font.BOLD | Font.ITALIC)) width = 0;
}
boolean isMonospaced = width > 0;

      

0


source







All Articles