How do I get GNU Unifont or Free Mono working on gvim windows?
Asked Answered
B

4

8

I am trying to get support for runic characters in gvim on Windows 7. I have the fonts Free Mono and GNU Unifont (which both support this range) installed in my Fonts directory, but they do not appear in the font menu, and gvim gives me an invalid font message for the following lines:

set guifont=unifont:h12:cANSI
set guifont=GNU_Unifont:h12:cANSI
set guifont=Free_Mono:h12:cANSI
set guifont=Free_Monospaced:h12:cANSI
set guifont=FreeMono:h12:cANSI

etc...

How do I get this to work? I noticed the fonts both are part of font family, "Medium", while Ubuntu Mono, which works, is tagged as "Regular". Does this make any difference? I have not had much luck in general with changing fonts on gvim, even monospace fonts.

Bombproof answered 24/4, 2012 at 2:13 Comment(0)
B
5

You made me curious about why this wasn't working, so I installed fontforge to snoop around inside the font. It turns out you were right about the font itself having the issue: The PANOSE proportion code is "Even Width" (4), not "Monospaced" (9). Since vim filters out non-monospaced fonts, this explains why they don't show up in the dialog.

In case you're interested, I got Windows fontforge via a standalone cygwin/X build prepared by this Japanese fellow, via this page with a discussion in English. Once you have it installed, open the font and look in Element->Font Info->OS/2->Panose.

I tried changing the setting and saving the file, but 1) the saved font file was 10 times larger than the original and it took a couple minutes to save the file, so something probably went wrong, and then 2) Windows refused to load it, complaining it isn't a valid font file. I've reached the end of my curiosity, but maybe you can make it work.

Bergamot answered 25/4, 2012 at 1:41 Comment(4)
Awesome! Thanks. I will definitely try it.Bombproof
Soooo, after 3 years, I finally went back and tried this. I had to use "Generate Font" instead of "Save Font" in font forge. Also, I had to turn off error validation. But after saving as a .ttf, the unifont one worked! Thanks! Free Mono still not working, but whatever. I can now type in the Hobbit's dwarf runes in gvim...:SBombproof
Also, for anyone else fiddling with this, I got fontforge from PortableApps.comBombproof
I was also able to fix Free Mono from the instructions here and by checking the BB -> Check Advance: 600 option in validation.Bombproof
T
4

For Win32, GTK, Motif, Mac OS and Photon:

:set guifont=* 

will bring up a font requester, where you can pick the font you want.

Type :set guifont? to get the setting, and put it into your .vimrc. When you put it into the .vimrc file, you will have to escape spaces if there are spaces. For example, if ':set guifont?' outputs 'Gnu Unifont 10', it needs to set in .vimrc as:

set guifont=Gnu\ Unifont\ 10
Tetramethyldiarsine answered 24/4, 2012 at 3:16 Comment(3)
Yes, I tried that, but these fonts are not appearing in the font window. I believe based on #8359266 that it may have something to do with GNU Unifont and Free Mono possibly not being 100% accurate on their fixed-width-ness? This is just a guess. Or maybe the tags don't match up with what gvim expects? Or maybe it requires postscript fonts? Just stabbing in the dark here.Bombproof
Any system-installed fixed-width font should work. Where did you get the fonts from? Are they the TrueType variants?Bergamot
Yes, they are both TrueType fonts. They are both installed in C:\Windows\Fonts and work fin in MS Word. GNU Unifont is from unifoundry.com/unifont.html and Free Mono is from savannah.gnu.org/projects/freefont. In both cases, I am using the ttf versions.Bombproof
S
4

I recently had the same problem and fixed it with fontforge. Here is the workflow to generate a working unifontmono.ttf font:

  • start fontforge and open the unifont.ttf font. On Debian this is installed at

/usr/share/fonts/truetype/unifont/unifont.ttf

  • go to Element -> Font Info...
    • under PS Names change Fontname, Family Name and Name for Humans, for example into UnifontMono.
    • under OS/2 -> Panose change Proportion to Monospaced.
  • click Save. In the popup select Change.
  • File -> Generate Fonts.... Select TrueType in the left requester, select No Bitmap Fonts, disable Validate Before Saving.
  • Save

This should save a TTF file that you can install under Windows.

To use the font with gvim on Windows:

  1. install the font by double-clicking it and choose Install.
  2. start gvim as Administrator:

    • goto Edit -> Startup Settings.
    • add the following line:

set guifont=UnifontMono:h12:cANSI

  1. restart gvim, it should now use the converted font.
Shrink answered 1/9, 2016 at 11:40 Comment(1)
If you want to use this font for Windows cmd.exe you'll have to pull the regedit trick and you'll have to open the Options menu before generating the font and check the "Windows-compatible 'kern'" box. Wouldn't show up properly for me until I didAlvertaalves
J
2

The problem is that Unifont claims to be fixed-width, but contains double-width characters (e.g. the combined double tilde, U+0360). Depending on what toolkit Gvim was built with, TTF fonts may not be accepted, only bitmaps. Hence this answer.

Solution for the bitmap (PCF) font

Grab a copy of the font to a directory where you have permissions and open it in Fontforge.

Select all elements with Ctrl+A (they will be highlighted). Go to

  • Toolbar > Metrics > Set Width
  • Set width to: 8 {Half the number initially set}
  • Click OK and wait, it will take some minutes

After the operation is complete,

  • Toolbar > Element > Other Info > BDF info
  • In the FONT field, change "Unifont" to "Unifix" (or other name you like)
  • Scroll down and click New > FONT ASCENT (a number is auto-set, leave it alone)
  • Scroll down and click New > FONT DESCENT (a number is auto-set, leave it alone)
  • Click OK

Now save the BDF font in the File > Generate Fonts menu (Ctrl+Shift+G). Choose the name you like, but otherwise use the default settings.

Setting up the font for X11 in Linux

I will assume you named the font unifix.bdf in the previous step. Exit Fontforge, get back to the terminal and issue

bdftopcf unifix.bdf > unifix.pcf
gzip unifix.pcf

At this point the two PCF and BDF files that were left behind can be deleted. Now choose one route.

  • With root permissions,

    mv unifix.pcf.gz /usr/share/fonts/X11/misc
    mkfontdir /usr/share/fonts/X11/misc
    xset fp rehash
    
  • If you don't have root permissions or prefer not to fuss with system-wide directories, in the home directory,

    mkdir .fonts
    mv unifix.pcf.gz .fonts
    mkfontdir .fonts
    xset +fp $HOME/.fonts/
    xset fp rehash
    

    The two Xset commands will need to be repeated after each reboot.

Now the font should be listed is xfontsel and xlsfonts and you can finally use it in Gvim with :set gfn=-*-unifix-*.

Jamal answered 11/2, 2021 at 17:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.