csswebkittypographygeckoblink

Does `text-align: justify` stretch all white space characters evenly?


There are several horizontal white space characters in the Unicode standard beyond the usual space & non-breaking space. I tried using some of them with text-align: justify and it appears to my eye that the result is uneven: the «usual» spaces seem to stretch too easily while other spaces hardly stretch at all. For example: in left-aligned passages I can easily spot an odd en-space, in justified — not so, depending on the amount of stretch a line requires.

Hence the question: how do web engines distribute the «justification stretch» across the white space characters of various kinds? What do the algorithms think of, say, «ideographic space», «medium mathematical space», and so on?


Solution

  • As a knowledgeable person explained to me on Reddit:

    I only have easy access to the blink code base and in that it justifies on kSpaceCharacter, kTabulationCharacter, kNewlineCharacter, and kNoBreakSpaceCharacter (0x0020, 0x0009, 0x000A, 0x00A0). The function is called NGInlineLayoutAlgorithm::ApplyJustify.

    As far as I can tell from some very brief tests it looks like it is the same in Firefox as well.

    Further:

    I found how it works in gecko as well and it is quite complicated. There is a long list of "breaking" characters that depend on if the page is rendered in Japanese, Chinese, or a different language. For non-jp/zh languages it works almost exactly as blink.

    You can find it here. aLangIsCJ basically means if it is a Chinese or Japanese document.