Working With Linux Fonts (Microsoft Core Fonts, etc)

Jarret B

Well-Known Member
Staff member
Joined
May 22, 2017
Messages
344
Reaction score
377
Credits
11,920
Linux comes with quite a few pre-installed fonts, especially if your distro comes with a word processor. Most word processors come with their own fonts.

Adding fonts is an easy task, just download your font, right-click on it, and select Install. On some systems, you may need to open the font file in the program 'Fonts' and then click on 'Install'.

Microsoft Fonts

If you have used Windows quite often, you may notice that the fonts you are used to are not present on some distros, like Ubuntu.

The fonts installed with the package are:

Andale_Mono.ttf
andalemo.ttf
arialbd.ttf
arialbi.ttf
Arial_Black.ttf
Arial_Bold_Italic.ttf
Arial_Bold.ttf
Arial_Italic.ttf
ariali.ttf
arial.ttf
Arial.ttf
ariblk.ttf
comicbd.ttf
Comic_Sans_MS_Bold.ttf
Comic_Sans_MS.ttf
comic.ttf
courbd.ttf
courbi.ttf
Courier_New_Bold_Italic.ttf
Courier_New_Bold.ttf
Courier_New_Italic.ttf
Courier_New.ttf
couri.ttf
cour.ttf
Georgia_Bold_Italic.ttf
Georgia_Bold.ttf
georgiab.ttf
Georgia_Italic.ttf
georgiai.ttf
georgia.ttf
Georgia.ttf
georgiaz.ttf
impact.ttf
Impact.ttf
timesbd.ttf
timesbi.ttf
timesi.ttf
Times_New_Roman_Bold_Italic.ttf
Times_New_Roman_Bold.ttf
Times_New_Roman_Italic.ttf
Times_New_Roman.ttf
times.ttf
trebucbd.ttf
trebucbi.ttf
Trebuchet_MS_Bold_Italic.ttf
Trebuchet_MS_Bold.ttf
Trebuchet_MS_Italic.ttf
Trebuchet_MS.ttf
trebucit.ttf
trebuc.ttf
Verdana_Bold_Italic.ttf
Verdana_Bold.ttf
verdanab.ttf
Verdana_Italic.ttf
verdanai.ttf
verdana.ttf
Verdana.ttf
verdanaz.ttf
webdings.ttf
Webdings.ttf


For Ubuntu and like distros, use the command:

sudo apt install ttf-mscorefonts-installer

The files are stored in the folder '/usr/share/fonts/truetype/msttcorefonts' and have a 'ttf' extension since they are Truetype fonts.

For Red Hat distros, like CentOS, use the commands:

sudo yum install curl cabextract xorg-x11-font-utils fontconfig
rpm -i https://downloads.sourceforge.net/p...pms/msttcore-fonts-installer-2.6-1.noarch.rpm


The font files are placed into the directory '/usr/share/fonts/msttcore'.

NOTE: Notice that the file structure varies slightly, this will be important later for the script that is set as an attachment.

Within your word processor, you should notice that more fonts are available. The new fonts include the Microsoft fonts that you may be more familiar with using before Linux.

Printing a Font List

Now that you have installed the Microsoft fonts or other fonts you downloaded, you may want a nice listing of font samples.

I've attached a script called 'fonts.txt'. You can leave the extension or change it to 'sh'. All you need to do is make it 'executable' and a few changes. You can use the command 'sudo chmod +x fonts.sh'.

I noted earlier that the file structure is different. So, let's see what needs changing.

Line 1 needs to be changed as needed. Depending on the distro, you need to change the location of the fonts.

Line 2 sets the extension of the fonts. If you want a listing of the Truetype fonts, then use 'ttf' and for Opentype fonts, use 'otf'.

Line 14 is the last one you need to change. The line is 'sorted=(printf "%s\n" "${array[@]}" | sort -ft/ -k7)'. This sorts the list of fonts based on the file name. The sort is not case-sensitive, the '-f' parameter is. The sections are terminated with the '-t' parameter using the forward slash '/' character. The '-k' parameter specifies the field to sort by. The fields are based on the terminating value of '/'. For CentOS, a value of '6' is needed and Ubuntu needs '7'. Just count how many fields exist to get to the file name.

The output is to a file named 'Fonts.html' which is created in the current folder. Open 'Fonts.html' with a web browser and you should see all your fonts in alphabetical order in the left column. The left column uses the default font. If I were to use the font itself, you wouldn't be able to read the non-alphabetic characters, like webdings.

The font sample is the alphabet in the right column. You can see an example in Figure 1.

Figure 1.JPG

FIGURE 1

The script could be changed to allow a parameter to be passed to the script to name the HTML file, but this works for now.

The Script

Let's look over the script a bit to see how it works.

The first loop, after setting your default folder and extension, gets the files from the folders named with specific extensions. The list includes the full path. The results are placed into an array named 'array'.

After the array is created, we sort the array with the line 'sorted=(printf "%s\n" "${array[@]}" | sort -ft/ -k6)'. The sorted array is placed into 'sorted'. It takes all of the values in 'array' and runs them through the 'sort' command. The sorted field is field 6, in this case.

The next line simply sets up the variable 'count' with the number of elements in the array, or the number of fonts.

The remaining lines are set up and create a file named 'Fonts.html'. The basics needed for a general HTML file are echoed in the file. The first loop creates a CSS section to allow for the use of different fonts. The script could include font sizes, colors, etc, but we want to keep it simple.

Next, a Table is created which will have two fields in the HTML file.

The last loop takes the font name in the array, the full path with extension, and removes the path and the extension. The file name is then stored in the variable 't1'. The variable 'j' is used as a counter to number the fonts.

The line 'echo "<tr><td>${j}. ${t1} </td> <td class="A${i}">ABCDEFGHIJKLMNOPQRSTUVWXYZ</td></tr>" >> Fonts.html' echoes out the table entries of the font number and the font file name. The second table entry, on the right, lists the upper-cased alphabet using the specified font created in the CSS section.

The HTML sections are closed and the file is completed. It is ready to be opened by a browser. Opening the file may take a few seconds for the font files to be loaded. The more font files that are installed, the longer it can take.

Conclusion

You should be able to add the Microsoft fonts to your Operating System. Keep in mind that websites exist that allow you to download numerous fonts.

After you have fonts on your system, you can create an HTML file to show what the fonts each look like as a sample. Simply open the created HTML in a browser and print the sample fonts.
 

Attachments

  • fonts.txt
    1.4 KB · Views: 187

Members online


Latest posts

Top