Gecko:LineBreakerAPI

From MozillaWiki
Jump to: navigation, search

New Linebreaking API

Overview

  • Compute linebreaks for a run of text with one API call, where the run of text begins and ends with either a known line-break or non-text content
  • The run of text can contain text from different DOM nodes
  • We only need to compute linebreaks for some parts of the text (for other parts of the text we already know the linebreaks or there can't be linebreaks because of CSS white-space override)
  • There should only be ONE linebreaker algorithm seen by layout. If we need language-specific behaviour, the linebreaker should implement that internally. So Thai text will have to be handled by detecting Thai characters and applying the Thai algorithm to the Thai parts of the string.

Suggestion

class nsLineBreaker {
public:
  struct TextChunk {
    nsIAtom*      mLanguageHint;
    const void*   mCharacters;
    PRUint32      mLength;
    enum { CHAR, UNICHAR } mCharacterType;
    PRPackedBool  mNeedBreakData;

    /* aBreakBefore points to mLength + 1 bytes, set to PR_TRUE if we can
       break *before* the corresponding character of mText. This gets called
       only if mNeedBreakData is true. aBreakBefore[mLength] is set to PR_TRUE
       if we can break after this chunk.
       The intent is that layout will subclass TextChunk and override
       SetBreaks to store the break data into the textrun object associated
       with this text chunk.
    */
    virtual void SetBreaks(PRPackedBool* aBreakBefore) = 0;
  };

  /**
   * Asks the linebreaker to compute line break opportunities for a block
   * of text. The text is a sequence of text chunks. The chunks with
   * mNeedBreakData set to true get break data computed for them and then
   * set by calling SetBreaks on the chunk. The chunks with mNeedBreakData set
   * to false are included so that the line breaking algorithm can get all the
   * context it might need.
   */
  void ComputeLineBreaks(const TextChunk* aTextChunks, PRUint32 aNumChunks);
};