Class RichRunPainter
java.lang.Object
com.codename1.ui.editor.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfontFor(int px, boolean bold, boolean italic) Derives a cached font at the given pixel size and weight/slant from the base font.intThe base (unscaled) run size in pixels.static floatheadingScale(int blockType) The heading scale factor for a paragraph block type (RichBlocks.H1..H6).static booleanisHeading(int blockType) Whether a block type is a heading (h1..h6).intPaints one styled run at(x, y)within a row oflineHeight, drawing highlight/inline-code background, then the glyphs with color and underline/strike decorations.The concrete font a run resolves to (size fromrunPx(int, TextStyle), bold from the style or a heading block, italic from the style).intThe pixel size for a run: an absoluteTextStyle.getFontSizePx()(> 0) wins over the relative level, and the paragraph heading scale is applied on top of either.voidsetBaseFont(Font f) Sets the base font from which sized/weighted run fonts are derived.voidsetBaseSizePx(int px) Overrides the base (unscaled) run size in pixels; defaults to the base font height.voidsetTextColor(int rgb) The default foreground color (0xRRGGBB) used when a run does not set one.static floatsizeLevelScale(int level) The relative-level scale factor (levels 1..7; 0/3 = 1.0).
-
Constructor Details
-
RichRunPainter
public RichRunPainter()
-
-
Method Details
-
setBaseFont
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
The pixel size for a run: an absoluteTextStyle.getFontSizePx()(> 0) wins over the relative level, and the paragraph heading scale is applied on top of either.- Parameters:
blockType- the paragraph block typest- the run style- Returns:
- the run size in pixels
-
fontFor
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 sizebold- bold weightitalic- italic slant- Returns:
- the derived font
-
runFont
The concrete font a run resolves to (size fromrunPx(int, TextStyle), bold from the style or a heading block, italic from the style).- Parameters:
blockType- the paragraph block typest- the run style- Returns:
- the run font
-
paintRun
Paints one styled run at(x, y)within a row oflineHeight, drawing highlight/inline-code background, then the glyphs with color and underline/strike decorations. The caller supplies the already-resolved run font (fromrunFont(int, TextStyle)).- Parameters:
g- graphicsrun- the run textst- the run stylerf- the resolved run fontx- left pixely- top pixel of the rowlineHeight- the row height- Returns:
- the painted advance width
-