W3C home > Mailing lists > Public > www-style@w3.org > April 2011

[css3-fonts] subscripts and superscripts

From: fantasai <fantasai.lists@inkedblade.net>
Date: Tue, 12 Apr 2011 17:43:51 -0700
Message-ID: <4DA4F1C7.5080904@inkedblade.net>
To: "www-style@w3.org" <www-style@w3.org>
The following proposal was whiteboarded by dbaron and fantasai.
It solves lots of funky use cases.
It does not solve fonts with bad font metrics. :)


   *magic*: none | super | sub
   inherited: yes
   applies to: non-replaced inline elements

   superscript size ratio
      The font-size ratio of superscripts to base text, as defined
      by the font metrics (or some heuristic).
   subscript size ratio
      The font-size ratio of subscripts to base text, as defined
      by the font metrics (or some heuristic).
   superscript shift ratio
      The baseline shift associated with superscripting,
      i.e. the distance from the alphabetic to superscript
      baselines in the baseline table.
   subscript shift ratio
      The baseline shift associated with subscripting,
      i.e. the distance from the alphabetic to subscript
      baselines in the baseline table.


   If the value of 'magic' matches the value of 'vertical-align',
   then the computed font size is set by multiplying the
   superscript/subscript proportion (as appropriate) by the
   parent's font size. The specified font-size is ignored.

   The element's baseline is positioned per vertical-align using
   the appropriate shift value (the ratio multiplied by the computed
   font size).

   When drawing text for an inline with 'magic' other than 'none',
   if the appropriate superscript/subscript glyph is available in
   the font, then instead of drawing the usual glyph at the current
   font-size and baseline position,
     1. divide the computed font-size by the superscript/subscript
        proportion to get the appropriate "base font size"
     2. multiply the superscript/subscript shift ratio by the base
        font size and shift the baseline downward by that amount to
        get the "base baseline position"
     3. draw the superscript/subscript using the base font size and
        baseline position

Cases handled:
   - basic superscripts and subscripts, using special glyphs
     in the fonts when available, else synthesizing
   - superscripts and subscripts containing images or other
     atomic inlines
   - nested superscripts and subscripts
   - font size changes within a superscript or subscript
   - mixing any of the above

Cases not handled:
   - mixing special glyphs with anything else if the font's
     subscript or superscript metrics are inaccurate
   - combining magic with length or percentage values of

Alternate #1:
   Instead of ignoring the specified font size in the first paragraph
   and using the parent's computed size, use the element's own font
       * author can change the font size of the superscript/
         subscript without nesting elements
       * not backwards compatible with the tradition of
         "vertical-align: super; font-size: smaller" to get superscripts,
         so the fallback behavior would have to be specified as simply
         "vertical-align; super".

Alternate #2:
   Instead of keying off vertical-align, make the property entirely
   separate and non-inherited. In the drawing text phase, this means
   that when 'magic' is 'none', we have to look up the ancestor chain
   (instead of relying on an inherited property value) to check whether
   we need to draw special glyphs.
       * author only needs to set one declaration
       * style sheets won't be backwards compatible if author doesn't
         set 'vertical-align
       * still need to set both properties to definitely turn things off

Alternate #3:
   Make 'magic' an on/off property, and look up the ancestor chain for
   'vertical-align: sub/super' to determine whether and what kind of
   special glyphs to use.
       * Setting "magic: on" on the root element makes everything magically
       * Lots of ancestor chain walking?

dbaron notes that the ancestor chain walking can be optimized by setting
bitflags, (almost as if there were an inherited property, even though
there's not).

Received on Wednesday, 13 April 2011 00:44:28 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 11 February 2015 12:34:50 UTC