# Class RichRunPainter

java.lang.Object
com.codename1.ui.editor.RichRunPainter

public final class RichRunPainter extends Object

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.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RichRunPainter()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Font`
  `fontFor(int px, boolean bold, boolean italic)`
  Derives a cached font at the given pixel size and weight/slant from the base font.
  `int`
  `getBaseSizePx()`
  The base (unscaled) run size in pixels.
  `static float`
  `headingScale(int blockType)`
  The heading scale factor for a paragraph block type (`RichBlocks.H1`..H6).
  `static boolean`
  `isHeading(int blockType)`
  Whether a block type is a heading (h1..h6).
  `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.
  `Font`
  `runFont(int blockType, TextStyle st)`
  The concrete font a run resolves to (size from `runPx(int, TextStyle)`, bold from the style or a heading block, italic from the style).
  `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.
  `void`
  `setBaseFont(Font f)`
  Sets the base font from which sized/weighted run fonts are derived.
  `void`
  `setBaseSizePx(int px)`
  Overrides the base (unscaled) run size in pixels; defaults to the base font height.
  `void`
  `setTextColor(int rgb)`
  The default foreground color (0xRRGGBB) used when a run does not set one.
  `static float`
  `sizeLevelScale(int level)`
  The relative-level scale factor (levels 1..7; 0/3 = 1.0).

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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` - 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` - 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` - the color

  - ### headingScale

    public static float headingScale(int blockType)
    The heading scale factor for a paragraph block type (`RichBlocks.H1`..H6).
    Parameters:
      `blockType` - 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` - 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` - 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` - the paragraph block type
      `st` - 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` - the pixel size
      `bold` - bold weight
      `italic` - italic slant
    Returns:
      the derived font

  - ### runFont

    public Font runFont(int blockType, TextStyle st)
    The concrete font a run resolves to (size from `runPx(int, TextStyle)`, bold from the style or a heading block, italic from the style).
    Parameters:
      `blockType` - the paragraph block type
      `st` - 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(int, TextStyle)`).
    Parameters:
      `g` - graphics
      `run` - the run text
      `st` - the run style
      `rf` - the resolved run font
      `x` - left pixel
      `y` - top pixel of the row
      `lineHeight` - the row height
    Returns:
      the painted advance width