public final class RichRunPainter

  1. Object
  2. RichRunPainter

Shared inline-run styling primitive for the rich text subsystem: it turns a TextStyle plus a paragraph block type into a concrete pixel size and derived Font, and paints one styled run (foreground color, highlight background, inline-code tint, underline and strike-through decorations).

The same style semantics power both the editable RichView and the read-only rich text renderer, so a run built for one draws identically in the other. Font size honors an absolute TextStyle.getFontSizePx() when set, otherwise the relative TextStyle.getFontSizeLevel(), with heading scale applied on top in both cases.

Constructors

public RichRunPainter()

Methods

public void setBaseFont(Font f)Sets the base font from which sized/weighted run fonts are derived.
public void setBaseSizePx(int px)Overrides the base (unscaled) run size in pixels; defaults to the base font height.
public int getBaseSizePx()The base (unscaled) run size in pixels.
public void setTextColor(int rgb)The default foreground color (0xRRGGBB) used when a run does not set one.
public static float headingScale(int blockType)The heading scale factor for a paragraph block type (RichBlocks.H1..H6).
public static boolean isHeading(int blockType)Whether a block type is a heading (h1..h6).
public static float sizeLevelScale(int level)The relative-level scale factor (levels 1..7; 0/3 = 1.0).
public int runPx(int blockType, TextStyle st)The pixel size for a run: an absolute TextStyle.getFontSizePx() (> 0) wins over the relative level, and the paragraph heading scale is applied on top of either.
public Font fontFor(int px, boolean bold, boolean italic)Derives a cached font at the given pixel size and weight/slant from the base font.
public Font runFont(int blockType, TextStyle st)The concrete font a run resolves to (size from runPx, bold from the style or a heading block, italic from the style).
public int paintRun(Graphics g, String run, TextStyle st, Font rf, int x, int y, int lineHeight)Paints one styled run at (x, y) within a row of lineHeight, drawing highlight/inline-code background, then the glyphs with color and underline/strike decorations.

Inherited methods

Constructor details

RichRunPainter

public RichRunPainter()

Method details

setBaseFont

public void setBaseFont(Font f)
Sets the base font from which sized/weighted run fonts are derived. The base size defaults to the font height.

Parameters

f Font
the base font

setBaseSizePx

public void setBaseSizePx(int px)
Overrides the base (unscaled) run size in pixels; defaults to the base font height.

Parameters

px int
the base size in pixels

getBaseSizePx

public int getBaseSizePx()
The base (unscaled) run size in pixels.

Returns

base size in pixels

setTextColor

public void setTextColor(int rgb)
The default foreground color (0xRRGGBB) used when a run does not set one.

Parameters

rgb int
the color

headingScale

public static float headingScale(int blockType)
The heading scale factor for a paragraph block type (RichBlocks.H1..H6).

Parameters

blockType int
the block type

Returns

the scale multiplier

isHeading

public static boolean isHeading(int blockType)
Whether a block type is a heading (h1..h6).

Parameters

blockType int
the block type

Returns

true for headings

sizeLevelScale

public static float sizeLevelScale(int level)
The relative-level scale factor (levels 1..7; 0/3 = 1.0).

Parameters

level int
the size level

Returns

the scale multiplier

runPx

public int runPx(int blockType, TextStyle st)
The pixel size for a run: an absolute TextStyle.getFontSizePx() (> 0) wins over the relative level, and the paragraph heading scale is applied on top of either.

Parameters

blockType int
the paragraph block type
st TextStyle
the run style

Returns

the run size in pixels

fontFor

public Font fontFor(int px, boolean bold, boolean italic)
Derives a cached font at the given pixel size and weight/slant from the base font. A non-TTF base font cannot be resized and is returned as-is.

Parameters

px int
the pixel size
bold boolean
bold weight
italic boolean
italic slant

Returns

the derived font

runFont

public Font runFont(int blockType, TextStyle st)
The concrete font a run resolves to (size from runPx, bold from the style or a heading block, italic from the style).

Parameters

blockType int
the paragraph block type
st TextStyle
the run style

Returns

the run font

paintRun

public int paintRun(Graphics g, String run, TextStyle st, Font rf, int x, int y, int lineHeight)
Paints one styled run at (x, y) within a row of lineHeight, drawing highlight/inline-code background, then the glyphs with color and underline/strike decorations. The caller supplies the already-resolved run font (from runFont).

Parameters

g Graphics
graphics
run String
the run text
st TextStyle
the run style
rf Font
the resolved run font
x int
left pixel
y int
top pixel of the row
lineHeight int
the row height

Returns

the painted advance width