htmlunicodediacritics

Unicode (HTML) for circumflex over numeral?


To add a circumflex accent, a.k.a. "hat" (^) over the preceding character, we can use Unicode U+0302, COMBINING CIRCUMFLEX ACCENT, or ̂ in HTML, e.g. ŝ gives ŝ ("s hat").

In music theory, this accent is used on top of numerals.

Attempts to use the combining code with numerals do not always render correctly. The circumflex is shifted to the right and slightly overprinted in Windows/Chrome. The circumflex is omitted in Android/Chrome.

3Į gives on your system.

Although HTML is where I want to use this mark, it is not the only place it occurs.

Here it is in Windows Charcter Map:

Windows Character Map screenshot

Can anything be done to get this to render correctly and consistently?

Side note: Wikipedia works around it with special template that returns an image, e.g. {{music|scale|3}} gives 3 hat. If the grand army of Wikipedians can't come up with a better solution, maybe none exists.


Solution

  • The root issue is whether the font being used to display the combination was designed to support that particular combination. Let me explain.

    In a font, each glyph has metric values that determine where the shape is positioned in relation to the initial pen position (the "left side bearing"), and how far the pen position moves from the initial position after that glyph has been drawn (the "advance width"). The following figure illustrates this for the digit 3 from the Arial font: the horizontal guidelines are font-wide metric values but the vertical guidelines show glyph-specific metrics:

    glyph for digit 3 with metric values shown

    The left side bearing of the glyph is 86 design units and the advance width is 1139 design units.

    When displaying the sequence 3Į, the default placement of the glyph for U+0302 will depend on its left side bearing — that is, where the outline is in relation to x = 0. The following figure shows the metrics for the combining circumflex glyph in Arial:

    glyph for combining circumflex with metric values shown

    Note that the advance width is 0: this is a combining mark that should not add any advance width beyond that of the base character it sits on. Also note the placement of the outline: it straddles x = 0. So, for the sequence 3̂3, the default placement of the combining mark straddles the middle of the gap between 3 and 3, and that's what we oberve:

    a combination 3 circumflex 3 with the circumflex positioned halfway between the first 3 and the second 3

    Now, I've been referring to the default placement. In an OpenType font, the font designer can add advanced layout tables that modify glyph metrics for certain contexts. These would be contained with a 'GPOS' (glyph positioning) table within the font. The 'GPOS' table supports several kinds of positioning actions (in OpenType terminology, several "lookup subtable types"). For above or below combining mark glyphs, placement in relation to a base glyph will usually be implemented using "mark-to-base attachment positioning". This type of positioning action allows an "anchor point" to be defined for base glyphs, and an anchor point to be defined for the mark glyph. When anchors are defined for both glyphs, the layout engine will automatically align the two anchor points to obtained the desired placement of the mark in relation to the base.

    Here's how that looks in a designer's tool for the combining circumflex glyph positioned using anchors over an a glyph:

    glyph a with cicumflex glyph above and a cross indicating the location of aligned glyph anchors

    So, with that background, I can now explain that, for the sequence 3̂ using the Arial font, the font does not have any positioning actions for the glyphs in that character sequence, and the circumflex is simply displayed using its default position and metrics.

    To get a combining circumflex positioned correctly over a digit 3, either the default position would have to provide that result or mark positioning actions will be needed for that particular combination. Not many fonts are likely to have positioning data for combining marks over digits since that is not a commonly-used combination (outside of music theory), yet supporting it takes extra data in the font and extra work on the font designers part.

    Some fonts do support mark positioning over digits, however. For example, the Doulos SIL font has mark-to-base attachment positioning for 3 with combining circumflex:

    digit 3 with circumflex glyph above and a cross indicating the location of aligned glyph anchors

    So, to get this combination to work, you just need to find a font designed to support mark positioning for that combination.