Unicode Staff Grid
The fretboard post ended with βthese approaches also apply to musical staves.β This version does just that, but keeps one constraint: start with the Unicode staff glyph, measure the source units once, and derive the placement grid from those measurements instead of nudging pixels by hand.
The relevant character is 𝄚,
U+1D11A MUSICAL SYMBOL FIVE-LINE STAFF.
The source file in notofonts/music is
sources/NotoMusic.glyphs.
A small Python script now builds one measurement table across the 4-string fretboard, 5-string
fretboard, 5-line staff, stemless notehead, quarter note, and half note.
Minimal Python to download the source and print the table:
The full table is longer, but for this post the staff, quarter-note, and half-note rows are the ones that matter:
| Glyph | Codepoint | Glyph name | Advance | Bounds (l,b)-(r,t) |
Size | Center | Details |
|---|---|---|---|---|---|---|---|
| 5-line staff | U+1D11A | u1D11A |
1100 | (50, 0)-(1050, 1000) | 1000x1000 | (550.0, 500.0) | 5 lines; thickness 24; gap 220; center step 244; note step 122 |
| Quarter note | U+1D15F | u1D15F |
400 | (51, 11)-(350, 1009) | 299x998 | (200.5, 510.0) | measured from built TTF glyph bounds |
| Half note | U+1D15E | u1D15E |
397 | (50, -1)-(347, 1009) | 297x1010 | (198.5, 504.0) | measured from built TTF glyph bounds |
The useful CSS variables fall straight out of those measurements:
50 / 1000 is the left inset, 12 / 1000 is the top-line center, and 122 / 1000 is half of
the 244 unit line-center spacing, so it lands on both lines and spaces.
For the marks themselves, quarter notes and half notes are easier to read than bare noteheads. The
overlay uses Noto Music glyphs for both from the same musical-symbol family:
π
, U+1D15F MUSICAL SYMBOL QUARTER NOTE, and
π
, U+1D15E MUSICAL SYMBOL HALF NOTE.
With that grid, a sparse data-pos overlay can treat one scaled staff glyph as one 16-slot
measure block and place the treble clef, the stacked 4/4, and then the note characters. Every
character uses exactly one row letter plus a two-digit base-10 column: the clef centers on G,
column 02 is left empty because the treble clef is wide, the time-signature digits sit on a
and c, and the notes use their pitch rows. The last two digits give the column from 01
through 16. Uppercase and lowercase distinguish lower and
higher pitches. The first measure of βTwinkle, Twinkle, Little Starβ is G G d d; the next
measure starts a new staff block when the 16 slots run out.
This is the part I wanted from the start: one Unicode background glyph, one measured grid, and then ordinary markup on top. The fretboard glyph and the staff glyph both work better once the source units become the API.