📜 ⬆️ ⬇️

How to change font name

Infrequently, but regularly people have a question - how to change the name of the font . Not a font file (there is no trick here), but the font itself. The name that will be displayed in the font dialog of word processors after installing this.

I ran into this problem as follows. It was required to convert a set of documents from CAD “Compass” to a PDF on a home computer. For this purpose there was KOMPAS-3D Viewer. And the plug came out with the fact that the author of the documents typed them in Arial Narrow font, which was absent on the computer; Instead, the caretaker substitutes the Arial font, which is why all the inscriptions in the document travel about anyhow.

Of course, we all know how to solve the problem with the missing font, and with the editor of the Compass. But I have a nasty habit of not violating copyrights unless absolutely necessary, so I began to look for a legitimate and relatively honest decision. The computer was a free font Liberation Sans Narrow (TrueType), which is very similar to Arial Narrow, and most importantly, has the same metrics. It was necessary only to convince the system (we are talking about Windows Vista) that the exact same font is called Arial Narrow, that's all.

First, we get the required fonts (LiberationSansNarrow.ttf, LiberationSansNarrow-Bold.ttf, LiberationSansNarrow-Italic.ttf, LiberationSansNarrow-BoldItalic.ttf) from C:\Windows\Fonts into an arbitrary folder. The named path actually contains a special file, not a folder, and something with its contents should be done only through Windows Explorer: copied the files with the mouse, trimmed it, and put it back with the mouse.
')
The easiest way to do something with a font is to download and install FontForge , a graphical font editor. If you are not too lazy to download the installer, then you can not read further - everything is elementary. But I decided that the distribution of the graphic product (weighs just over 16 MB) is hard for me to pump out - the Internet is not fast; and moved on to other options (not the fact that I acted wisely, well, yes, you can't throw a word out of a song).

The utility for working with fonts from the command line is TTX from the FontTools project. His .exe installer is found in the Internet archives, but I did not manage to launch the program obtained from it, so I downloaded the tar.gz archive from the official site (only 340 KB in weight). To build the utility from this archive, you will need:
  1. Python is a programming language. I had it configured as part of the Cygwin environment, in the console of which I did everything further, so I did not need to download it. Presumably, Cygwin for the assembly is not required, but in any case, convenient.
  2. Numerical Python library - no one knows why is required for assembly. The archive weighs about 4.3 MB. You may be able to install it without difficulty through the standard Cygwin installer.


So, the order of actions (for dummies, those familiar with the assembly of codes may not particularly read):
  1. Unpack the numpy-xxxzip archive into any folder and go there in the console using the cd "D:////numpy-xxx" (in the Cygwin shell, use / forward / slash instead of \ back \).
  2. Run the python setup.py install command. Then you will receive a compiler's abuse for half an hour, but the library will most likely be successfully installed as a result.
  3. Now unpack the fonttools- ... .tar.gz archive somewhere, and again go to the extracted folder and call python setup.py install . The installation will be completed pretty soon this time, and the ttx utility will be available from the command line.
  4. Go to the directory where we copied the files with fonts. Execute the command: ttx *.ttf , after which for each TrueType-font in the folder there will be a file with the .ttx extension. Source files can now be deleted (you copied them and did not move them?)
  5. TTX files are plain text files in XML format. Open them in any text editor and change everything you need; in my case, all I had to do was replace “LiberationSans” and “Liberation Sans” everywhere with Arial.
  6. ttx *.ttx utility again, in order to return the files to the compiled form: ttx *.ttx . There is a set of files similar to the original, but with a different internal name.
  7. Rename files in order to avoid conflicts (no matter what, if only you did not have such fonts). For this purpose, you can use the program Free Font Renamer , which renames all files in the folder to internal font names. I draw your attention that this program does not know how to change the contents of the files - it only reads the internal names of the fonts, and therefore is not really needed (I downloaded it before, because I expected more from it).

Everything, we received files which can be thrown a mouse in the pseudo- directory Fonts . With OpenType fonts, everything is done in a similar way, taking into account the replacement at the 4th step of .ttf with .otf.

PS I note that earlier I managed to rename OpenSymbol to StarSymbol, without using any heavy downloads. For this, the file was passed through a simple script containing a regular expression like s/O([\x00-\x1F]?)p([\x00-\x1F]?)e([\x00-\x1F]?)n/S$1t$2a$3r/g . However, I cannot guarantee that this trick always works, especially when the length of the names does not match.

Source: https://habr.com/ru/post/255187/


All Articles