Package limn.graphics

Enum Class ShapedText.Direction

java.lang.Object
java.lang.Enum<ShapedText.Direction>
limn.graphics.ShapedText.Direction
All Implemented Interfaces:
Serializable, Comparable<ShapedText.Direction>, Constable
Enclosing class:
ShapedText

public static enum ShapedText.Direction extends Enum<ShapedText.Direction>
Which way a paragraph reads.

There is deliberately no third constant meaning "decide later". Direction is resolved from the text before anything is shaped, and by the time a ShapedText exists the answer is known — so a constant standing for the question would be a value a widget could store in a field, hand back through ShapedText.baseDirection(), and compare against. Stating a direction and declining to state one are different acts, and they are spelled as different shape overloads on TextRuler rather than as two values of one type.

This is the direction of a run of text, which is why it lives here. Direction as a layout axis — leading and trailing insets, mirrored ink, arrow semantics, popup anchoring — is a separate decision that has not been taken, and pre-empting it with a type in the drawing package would put a text-shaping concern in every layout signature it touches.

  • Enum Constant Details

    • LTR

      public static final ShapedText.Direction LTR
      Left to right: Latin, Greek, Cyrillic, the CJK scripts as this toolkit sets them, and the answer for a string with no strong character at all.
    • RTL

      public static final ShapedText.Direction RTL
      Right to left: Arabic, Hebrew.
  • Method Details

    • values

      public static ShapedText.Direction[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ShapedText.Direction valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • of

      public static ShapedText.Direction of(String text, ShapedText.Direction whenNeutral)
      The base direction of text under the Unicode Bidirectional Algorithm's first-strong-character rule, as java.text.Bidi implements it.

      The rule lives here, in one place with no backend under it, so that every ruler resolves a paragraph the same way and a test can pin it with nothing installed.

      whenNeutral is returned for text with no strong character at all ("42", "(...)", the empty string), which is the one case the rule cannot answer. It is a parameter rather than a constant because the right answer there is the direction of the surrounding user interface, which nothing in this package owns yet; passing LTR reproduces the behaviour of a toolkit with no direction axis, and this parameter is the seam where that gets fixed.

      Parameters:
      text - the paragraph to inspect
      whenNeutral - what to return when text contains no strong character
      Throws:
      NullPointerException - if either argument is null