Class TextStyle
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 Summary
FieldsModifier and TypeFieldDescriptionfinal intThe highlight color, orNO_BACKGROUND.static final StringNormal baseline position.final booleanWhether the text is bold.final intThe text color.static final TextStyleThe style of text that names no formatting of its own.final StringThe font family name.final booleanWhether the text is italic.final StringThe hyperlink target, or the empty string.static final intMarks the absence of a highlight color.final RevisionThe tracked change this run belongs to, or null.final StringOne ofBASELINE,SUPERSCRIPTorSUBSCRIPT.final floatThe font size in points.final booleanWhether the text is struck through.static final StringLowered and reduced, as in a chemical formula.static final StringRaised and reduced, as in an exponent.final booleanWhether the text is underlined. -
Constructor Summary
ConstructorsConstructorDescriptionTextStyle(String font, float size, int color, boolean bold, boolean italic, boolean underline, boolean strike, int background, String link, String script) Creates a style.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. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTwo styles are equal when every attribute is.inthashCode()A hash consistent withequals.withBackground(int value) A copy with a different highlight.withBold(boolean value) A copy with bold switched.withColor(int value) A copy with a different text color.A copy with a different font family.withItalic(boolean value) A copy with italic switched.A copy with a different hyperlink.withRevision(Revision value) A copy marked as a tracked change, or with the mark removed.withScript(String value) A copy with a different baseline position.withSize(float value) A copy with a different size.withStrike(boolean value) A copy with strike-through switched.withUnderline(boolean value) A copy with underline switched.
-
Field Details
-
NO_BACKGROUND
public static final int NO_BACKGROUNDMarks the absence of a highlight color.- See Also:
-
BASELINE
-
SUPERSCRIPT
-
SUBSCRIPT
-
DEFAULT
The style of text that names no formatting of its own. -
font
The font family name. -
link
The hyperlink target, or the empty string. -
color
public final int colorThe text color. -
background
public final int backgroundThe highlight color, orNO_BACKGROUND. -
size
public final float sizeThe font size in points. -
bold
public final boolean boldWhether the text is bold. -
italic
public final boolean italicWhether the text is italic. -
underline
public final boolean underlineWhether the text is underlined. -
strike
public final boolean strikeWhether the text is struck through. -
script
One ofBASELINE,SUPERSCRIPTorSUBSCRIPT. -
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, orNO_BACKGROUND -
link: the hyperlink target, or null or empty for none -
script:BASELINE,SUPERSCRIPTorSUBSCRIPT; null meansBASELINE
-
-
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 forSerif -
size: the size in points -
color: the text color -
bold: bold -
italic: italic -
underline: underline -
strike: strikethrough -
background: the highlight color, orNO_BACKGROUND -
link: the hyperlink target, or null or empty for none -
script:BASELINE,SUPERSCRIPTorSUBSCRIPT; null meansBASELINE -
revision: the tracked change the run belongs to, or null
-
-
-
Method Details
-
withFont
-
withSize
A copy with a different size.
Parameters
value: the size in points
Returns
the derived style
-
withColor
A copy with a different text color.
Parameters
value: the RGB color
Returns
the derived style
-
withBackground
A copy with a different highlight.
Parameters
value: the RGB color, orNO_BACKGROUND
Returns
the derived style
-
withBold
A copy with bold switched.
Parameters
value: bold or not
Returns
the derived style
-
withItalic
A copy with italic switched.
Parameters
value: italic or not
Returns
the derived style
-
withUnderline
A copy with underline switched.
Parameters
value: underlined or not
Returns
the derived style
-
withStrike
A copy with strike-through switched.
Parameters
value: struck through or not
Returns
the derived style
-
withLink
-
withScript
-
withRevision
-
equals
-
hashCode
-