1. A Tale of Opposing Directions:

    Bidirectional Text in HTML and CSS

    Elika J. Etemad (fantasai) Mozilla Project W3C CSS Working Group
  2. Introduction to Bidirectional Text

    What is bidirectional text?

  3. Introduction to Bidirectional Text

    What is bidirectional text?

    As soon as you expect to have any RTL, you must deal with bidi.

  4. Introduction to Bidirectional Text

    Text is stored in logical order, not visual order.

    by Elika Etemad (الیکا اعتماد) on bidi.
    1    2      3      5      4     6   7
  5. Introduction to Bidirectional Text

    Visual order depends on line-breaking.

    by Elika Etemad (الیکا اعتماد) on bidi.
    1    2      3      5      4     6   7
    by Elika Etemad (الیکا
    1    2      3      4
    اعتماد) on bidi.
       5     6   7
  6. The (Vastly Simplified) Unicode Bidirectional Algorithm

    1. Classify all neutrals
    2. Assign embedding levels
    3. Reorder by number
  7. Resolving Neutrals: Intrinsic Directionality

    All Unicode characters are either

    Note: Numbers are special. We'll pretend they're L for now.

  8. Resolving Neutrals: Sandwich Rule

    Surrounded neutrals take surrounding directionality.

    L N N N L
    L L L L L
  9. Resolving Neutrals: Sandwich Rule Failures

  10. Resolving Neutrals: Base Direction

    Each paragraph has a base direction.

    Use the base direction for initial/final/conflicted neutrals.

  11. Embedding Levels

    L ⇒ evens R ⇒ odds
    1. Assign all characters to base level.
    2. Increase by one as required by directionality.
  12. Embedding Levels: LTR Base Direction

    Fox پرید over Dog.
    LLLNRRRRNLLLLNLLLN
    LLLLRRRRLLLLLLLLLL
    000011110000000000
    abc DEF ghij
    000 111 0000
  13. Embedding Levels: RTL Base Direction

    رروباه از رو Dog پرید.
    NRRRRNLLLNRRNRRNRRRRRR
    RRRRRRLLLRRRRRRRRRRRRR
    1111112221111111111111
    ABC def GHIJ
    111 222 1111
  14. Reordering

    For each level run:

    1. Reverse the order of chars.
    2. Reduce their level by one.
  15. Reordering: LTR Base Direction

    abc DEF ghij
    000 111 0000
    abc FED ghij
    000 000 0000
  16. Reordering: RTL Base Direction

    ABC def GHIJ
    111 222 1111
    ABC fed GHIJ
    111 111 1111
    JIHG def CBA
    0000 000 000
  17. Embeddings: Why Embed?

    The fox پرید over the lazy dog.
    1—————► ◄——2 3————————————————►
    ——————————————————————————————►
    The fox پرید over the تنبل dog.
    1—————► ◄——2 3——————► ◄——2 1——►
    ——————————————————————————————►
  18. Embeddings: Why Embed?

    الیکا ”...“ نوشت.
    ◄———3  2—►  ◄———1
    ◄———————————————
    Fox پرید over Dog.
    1—► ◄——2 3———————►
    —————————————————►
  19. Embeddings: Why Embed?

    الیکا ”Fox پرید over Dog“ نوشت.
    ◄———5  4——————► ◄——3 2———►  ◄———1
    الیکا ”Fox پرید over Dog“ نوشت.
    ◄———3  2———————————————►  ◄———1
    ◄———5  2—► ◄——3 4——————►  ◄———1
  20. Embeddings: Mechanics

    Embeddings are markup that creates a "paragraph" within a paragraph.

    الیکا ”Fox پرید over Dog!“ نوشت.
    ◄—1—►  ◄——————2—————————►  ◄—1—►
    11111  222 3333 222222222  11111
    ZYXWV  stu OPQR nmlkjihgf  EDCBA
  21. Embeddings: Reordering

    ABCDE »fghijklmn OPQR stu« VWXYZ
    ◄—1—►  ◄——————2—————————►  ◄—1—►
    11111  222222222 3333 222  11111
    ABCDE fghijklmn RQPO stu VWXYZ
    11111 222222222 2222 222 11111
    ABCDE uts OPQR nmlkjihgf VWXYZ
    11111 111 1111 111111111 11111
    ZYXWV stu OPQR nmlkjihgf EDCBA
    00000 000 0000 000000000 00000
  22. Intermission

    End of Part I

  23. Bidi in HTML 4: Controls

    Global dir attribute

  24. Bidi in HTML 4: Usage

    Global dir attribute

  25. Bidi in CSS 2: Effects

    Directionality affects:

  26. Bidi in CSS 2: Do Not Use

  27. Bidi Basics: Document Base Direction

    <html dir=rtl>
  28. Bidi Basics: Embedding Blocks

    <blockquote dir=rtl>...</blockquote>
    <div dir=rtl>...</div>
  29. Bidi Basics: Embedding Inline

    <p>... <q dir=rtl>...</q> ...</p>
  30. Some Problems... and How to Fix Them

    Most problems in bidi are due to either

  31. Creating Separation: Neutrals

    L N N N L
    L L L L L

    strong right-to-left (R), e.g. العربية‎, עִבְרִית

    strong right-to-left (R), e.g. العربية, עִבְרִית

    strong right-to-left (R), e.g. العربية&lrm;, עִבְרִית

  32. Embedding Woes

    Short story: embeddings suck.

  33. Dealing with User Input: HTML4 Edition

  34. Auto-Detection

    No heuristic is always right! It's just a heuristic.

  35. Intermission

    End of Part II

  36. HTML5: Isolates

    e.g. <bdi dir=rtl>العربية</bdi>,
     <bdi dir=rtl>עִבְרִית</bdi>
    
  37. HTML5: Auto-Detection

    dir=auto provides browser-side first-strong auto-detection

  38. CSS3: Direction-based Selectors

    :dir(rtl) { ... CSS for rtl elements ... }
    :dir(ltr) { ... CSS for ltr elements ... }
  39. CSS3: Matching Alignment

    text-align: start | end | match-parent
  40. Acknowledgements and References