elm-ui icon indicating copy to clipboard operation
elm-ui copied to clipboard

Improve handling of byCapital font sizing

Open jneubrand opened this issue 3 years ago • 1 comments

  • When determining offsets, use metrics for the current font as opposed to the inherited one (and remove logging that may have been intended to debug this issue)
  • Instead of saving a raw percentage, assume that fonts have an offset within [0, 0.25] and a height within [0.5, 1]. This will allow users to use more precise alignment values, as we skip saving 3 redundant bits in the inheritance BitField. These bounds should probably be cross-checked with common fonts. This may seem arbitrary, but note that the [0, 1] range isn't even enough for some fonts—for example, Zapfino would need an offset below zero. Having another bit or two of precision each would be great for large text. I don't feel qualified to judge the design decisions in BitEncodings, but this may be good to keep in mind for future changes (will widthFill/heightFill still exist, are 12 bits for spacingX needed…)

jneubrand avatar Dec 28 '21 22:12 jneubrand

By the way, those magic 0.25em numbers could be removed and get us to this:

let
    topVal =
        offset

    bottomVal =
        (1 - offset) - height

    margin =
        String.fromFloat (negate topVal)
            ++ "em "
            ++ (String.fromInt spacingX ++ "0px ")
            ++ String.fromFloat (negate bottomVal)
            ++ "em"
in
Attr.style "margin"
    margin
    :: Attr.style "padding" "0 calc((1/32) * 1em) 0 0px"
    :: Attr.style "overflow" "visible"
    :: attrs

—note the overflow: visible. This way, the hitbox isn't larger than necessary :)

jneubrand avatar Dec 28 '21 22:12 jneubrand