Class TextStyle

java.lang.Object
com.codename1.wordprocessing.TextStyle

public final class TextStyle extends Object

Immutable character formatting for a run of text. Sizes are in points and colors are 24 bit RGB values.

A style is changed by deriving a new one, never in place:

// com.codename1.ui.editor has a TextStyle too, hence the full name
com.codename1.wordprocessing.TextStyle heading =
        com.codename1.wordprocessing.TextStyle.DEFAULT.withSize(18).withBold(true);
Log.p("heading at " + heading.size + "pt");
  • Field Details

    • NO_BACKGROUND

      public static final int NO_BACKGROUND
      Marks the absence of a highlight color.
      See Also:
    • BASELINE

      public static final String BASELINE
      Normal baseline position.
      See Also:
    • SUPERSCRIPT

      public static final String SUPERSCRIPT
      Raised and reduced, as in an exponent.
      See Also:
    • SUBSCRIPT

      public static final String SUBSCRIPT
      Lowered and reduced, as in a chemical formula.
      See Also:
    • DEFAULT

      public static final TextStyle DEFAULT
      The style of text that names no formatting of its own.
    • font

      public final String font
      The font family name.
    • color

      public final int color
      The text color.
    • background

      public final int background
      The highlight color, or NO_BACKGROUND.
    • size

      public final float size
      The font size in points.
    • bold

      public final boolean bold
      Whether the text is bold.
    • italic

      public final boolean italic
      Whether the text is italic.
    • underline

      public final boolean underline
      Whether the text is underlined.
    • strike

      public final boolean strike
      Whether the text is struck through.
    • script

      public final String script
      One of BASELINE, SUPERSCRIPT or SUBSCRIPT.
    • revision

      public final Revision revision
      The tracked change this run belongs to, or null.
  • Constructor Details

    • TextStyle

      public TextStyle(String font, float size, int color, boolean bold, boolean italic, boolean underline, boolean strike, int background, String link, String script)

      Creates a style.

      Parameters
      • font: the font family

      • size: the size in points, greater than zero

      • color: the RGB text color

      • bold: bold text

      • italic: italic text

      • underline: underlined text

      • strike: struck-through text

      • background: the RGB highlight, or NO_BACKGROUND

      • link: the hyperlink target, or null or empty for none

      • script: BASELINE, SUPERSCRIPT or SUBSCRIPT; null means BASELINE

    • TextStyle

      public TextStyle(String font, float size, int color, boolean bold, boolean italic, boolean underline, boolean strike, int background, String link, String script, Revision revision)

      Creates a style with a tracked change.

      Parameters
      • font: the font family, or null for Serif

      • size: the size in points

      • color: the text color

      • bold: bold

      • italic: italic

      • underline: underline

      • strike: strikethrough

      • background: the highlight color, or NO_BACKGROUND

      • link: the hyperlink target, or null or empty for none

      • script: BASELINE, SUPERSCRIPT or SUBSCRIPT; null means BASELINE

      • revision: the tracked change the run belongs to, or null

  • Method Details

    • withFont

      public TextStyle withFont(String value)

      A copy with a different font family.

      Parameters
      • value: the family
      Returns

      the derived style

    • withSize

      public TextStyle withSize(float value)

      A copy with a different size.

      Parameters
      • value: the size in points
      Returns

      the derived style

    • withColor

      public TextStyle withColor(int value)

      A copy with a different text color.

      Parameters
      • value: the RGB color
      Returns

      the derived style

    • withBackground

      public TextStyle withBackground(int value)

      A copy with a different highlight.

      Parameters
      • value: the RGB color, or NO_BACKGROUND
      Returns

      the derived style

    • withBold

      public TextStyle withBold(boolean value)

      A copy with bold switched.

      Parameters
      • value: bold or not
      Returns

      the derived style

    • withItalic

      public TextStyle withItalic(boolean value)

      A copy with italic switched.

      Parameters
      • value: italic or not
      Returns

      the derived style

    • withUnderline

      public TextStyle withUnderline(boolean value)

      A copy with underline switched.

      Parameters
      • value: underlined or not
      Returns

      the derived style

    • withStrike

      public TextStyle withStrike(boolean value)

      A copy with strike-through switched.

      Parameters
      • value: struck through or not
      Returns

      the derived style

    • withLink

      public TextStyle withLink(String value)

      A copy with a different hyperlink.

      Parameters
      • value: the target, or null or empty for none
      Returns

      the derived style

    • withScript

      public TextStyle withScript(String value)

      A copy with a different baseline position.

      Parameters
      • value: BASELINE, SUPERSCRIPT or SUBSCRIPT
      Returns

      the derived style

    • withRevision

      public TextStyle withRevision(Revision value)

      A copy marked as a tracked change, or with the mark removed.

      Parameters
      • value: the revision, or null
      Returns

      the derived style

    • equals

      public boolean equals(Object o)

      Two styles are equal when every attribute is.

      Parameters
      • o: the other object
      Returns

      true when equal

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()

      A hash consistent with equals.

      Returns

      the hash

      Overrides:
      hashCode in class Object