The PMW-Music Fonts: history and maintenance notes
==================================================

Files in this directory:

PMW-Music-T3   the original PostScript Type 3 font
PMW-Music.otf  the OpenType font
PMW-Music.pfa  the PostScript Type 1 font
PMW-Music.raw  the input to t1asm to make the .pfa font
PMW-Music.ttx  the ttx file made from the OTF font

PMW-Alpha3     the PMW-Alpha Type 3 font, renamed as PMW-Alpha3
PMW-Alpha.otf  OpenType version of PMW-Alpha
PMW-Alpha.pfa  Type 1 version of PMW-Alpha
PMW-Alpha.raw  input to t1asm to make the .pfa font

README         this file
Run            a short script for running the Show... tests with the .pfa font
ShowMusic      a PostScript program to demonstrate the font
ShowOne        a PostScript program for looking at individual characters

Some of the strings in ShowMusic do not work with the OpenType font (see below
for why).


History of the PMW-Music font
=============================

In the late 1980s, the first implementation of PMW-Music was as a PostScript
Type 3 font, because at that time Adobe was keeping its Type 1 font format
secret by encrypting such fonts. In 2003 I was able to re-implement the font as
a PostScript Type 1 font, using the now public specification as implemented by
the t1asm/t1disasm commands. This greatly improved the appearance of the
characters. Nearly 20 years passed...

In 2022 I learned that Adobe were going to discontinue support for Type 1 fonts
in January 2023. This, of course, doesn't stop anybody else from continuing to
use them, and in particular, I assume (hope) that GhostScript will continue to
work. However, it seemed prudent to investigate alternatives.

Adobe's policy of secrecy forced others to create their own font formats. In
particular, TrueType is an outline font standard developed by Apple in the late
1980s as a competitor to Adobe's Type 1 fonts used in PostScript. Eventually,
however, the major players came together to create OpenType, which merges
features from both PostScript and TrueType, and is touted as the way forward.

For PMW-Music there is one major shortcoming of OpenType. In the PostScript
fonts, each character can have both horizontal and vertical movement associated
with it, and these values can be positive or negative. After a character has
been rendered, the current position can be made to move in any direction,
including backwards. I made use of this by creating a number of characters that
do no drawing, but which move in various ways. These can be used in character
strings to make composite shapes by positioning other characters appropriately.
There are also some vertical tilde characters that move upwards so that
several of them in succession create a vertical squiggle, and a tremolo
character that moves upwards for successive tremolo bars.

OpenType fonts do not support such usage. Indeed, the conversion program that I
used (see below) warned that it was setting leftwards movements to zero, and it
ignored vertical movements altogether. It seems that OpenType fonts can either
have horizontal or vertical movements, but not both, and in the same direction
for all characters.

Changing the characteristics of the music font would seriously break the
expected behaviour of PMW, not to mention backwards compatibility with existing
input files. I therefore modified the code of PMW so that it no longer outputs
movement-only characters in the music font, but instead emulates their action
by splitting the string and outputting it in multiple parts at appropriate
positions. The vertical tilde and tremolo characters are also handled
specially. This means that PMW can now work with either the PostScript (.pfa)
font or the OpenType (.otf) font.

If the OpenType font is used by any other program, the special moving
characters do not work. This required some minor adjustments to the PMW
specification, which includes characters from the font. I hope that few, if
any, other cases exist.


Maintaining the PMW-Music PostScript font
=========================================

The base data is a human-readable description of a PostScript type 1 font
that is in the file PMW-Music.raw. The type 1 font PMW-Music.pfa is built by
running the commend

  t1asm --pfa PMW-Music.raw PMW-Music.pfa

When adding characters to the font, remember to update the AFM file that is in
fontmetrics/PMW-Music.afm.


What I did to make an OpenType Font
===================================

Adobe provide a number of font maintenance tools that are Python programs.

1. The package is a Python thing that has to be installed using "pipx" (itself
installed in Arch Linux by "pacman -S python-pipx"). Then "pipx install afdko"
installs stuff in ~/.local. The acronym stands for "Adobe Font Development Kit
for OpenType".

2. For the first attempt I created a file called GOADB (Glyph Order and Alias
   DataBase) containing lines like these:

     PMWtrebleclef   trebleclef    uni0021
     PMWbassclef     bassclef      uni0022
     PMWaltoclef     altoclef      uni0023

   The first column contains glyph names for the OpenType file, the second
   contains the names in the Type 1 file, and the third effectively gives a
   slot number within the new font. I decided to change all the names because
   some of the originals (for example, "comma") are the same as "standard"
   glyph names, and were causing confusion. The unsupported movement-only
   characters were commented out, causing them to be omitted from the
   conversion.

   HOWEVER: this lead to an OTF font that had the wrong encoding, and altnough
   this could be patched up, it was not ideal. So:

3. Instead of using GOADB, I renamed all the characters in the original font
   (in the .raw file) by adding "PMW" at the start of each name, and turning sp
   into PMWspace. This solved the encoding issue.

4. The following command does the conversion:

   PATH=~/.local/bin:$PATH ~/.local/bin/makeotf -r -f PMW-Music.pfa

   There are a lot of warning messages. The -r option makes a "release" as
   opposed to a "development" version. It seemed to do some additional tidying.
   This command creates PMW-Music.otf.

5. The encoding can be double-checked by making use of the ttx tool that is
   part of the Adobe package. Decode the OpenType font into an XML file using
   the command:

   ~/.local/pipx/venvs/afdko/bin/ttx PMW-Music.otf

   The XML (.ttx) file can be inspected. In principle this could also be edited
   to add new characters directly to the OTF font. If ttx is called for a .ttx
   file, it makes an .otf file. Note that it won't overwrite an existing file;
   it adds #1 to the name, so delete or rename the original file first.

                     ******* WARNING *******

If the OpenType file is loaded into FontForge and then recreated, the encoding
gets reset to StandardEncoding, which is a pain. This suggests that using
FontForge to maintain the font is not reasonable, because the encoding would
have to be patched up (by editing the ttx file) each time.

If both a Type 1 and an OpenType version of the same font exist, GhostScript
sometimes prefers one and sometimes the other. If they are both in the same
directory, my guess is that it uses the one with the higher inode number.


The PMW-Alpha font
==================

This font was created by Richard Hallas on an Acorn RiscOS system, using 
Acorn's font technology. It was eventually able to be exported as a PostScript
Type 3 font, which was how it was bundled with PMW for many years. In early
2025, PMW was upgraded to generate PDF output as an alternative to PostScript. 
In this mode, only OpenType (.otf) fonts - the modern font format - are
supported. I discovered that there was at least one user of the PMW-Alpha font,
so something needed to be done. Luckily, once I had figured out how it worked,
I found it was fairly straightforward to convert the Type 3 font by hand (with
the aid of a helper program) into the source of a Type 1 font. Then it could be
processed in exactly the same way as PMW-Music, described above.


Testing
=======

"Run ShowOne" rebuilds the Type 1 file from raw and then uses it on the ShowOne
test file. "Run ShowMusic" rebuilds and runs the ShowMusic test file.

To test an OTF file, set GS_FONTPATH to its directory when running gv on
ShowOne, ShowMusic, or a PMW output file. If you use gs instead of gv, it
outputs details of font loading, so you can check that it is loading the
.otf rather than the .pfa file.

Philip Hazel
06 March 2025 (minor correction, July 2025)
