public final class RichRunPainter
- Object
- 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
fFont- the base font
setBaseSizePx
public void setBaseSizePx(int px)Overrides the base (unscaled) run size in pixels; defaults to the base
font height.
Parameters
pxint- 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
rgbint- the color
headingScale
public static float headingScale(int blockType)The heading scale factor for a paragraph block type (
RichBlocks.H1..H6).Parameters
blockTypeint- the block type
Returns
the scale multiplier
isHeading
public static boolean isHeading(int blockType)Whether a block type is a heading (h1..h6).
Parameters
blockTypeint- 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
levelint- 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
blockTypeint- the paragraph block type
stTextStyle- 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
pxint- the pixel size
boldboolean- bold weight
italicboolean- 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
blockTypeint- the paragraph block type
stTextStyle- 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
gGraphics- graphics
runString- the run text
stTextStyle- the run style
rfFont- the resolved run font
xint- left pixel
yint- top pixel of the row
lineHeightint- the row height
Returns
the painted advance width