Corpus

class text_renderer.corpus.Corpus(cfg: text_renderer.corpus.corpus.CorpusCfg)[source]

Base class of different corpus. See CorpusCfg for base configs for corpus.

static filter_by_chars(text, chars_file)[source]

Filter chars not exist in chars file

Parameters
  • text (Union[str, List[str]]) – text to filter

  • chars_file (Path) – one char per line

Returns

string(s) removed chars not exist in chars file

Return type

Union[str, List[str]]

abstract get_text()[source]
Returns

text to render

Return type

str

sample()[source]

This method ensures that the selected font supports all characters.

Returns

A FontText object contains text and font.

Return type

FontText

class text_renderer.corpus.CorpusCfg(font_dir: pathlib.Path, font_size: Tuple[int, int], font_list_file: pathlib.Path = None, clip_length: int = - 1, char_spacing: Union[float, Tuple[float, float]] = - 1, text_color_cfg: text_renderer.config.TextColorCfg = SimpleTextColorCfg(alpha=110, 255), horizontal: bool = True)[source]

Base config for corpus

Parameters
  • font_dir (path) – font files directory

  • font_list_file (path) – font file names to load from font_dir, if not provided, all fonts in font_dir will be used

  • font_size (tuple[int, int]) – font size in point (min_font_size, max_font_size)

  • clip_length (int) – clip get_text() output. set -1 disables clip

  • char_spacing ((Union[float, tuple[float, float]])) – Draw character with spacing. If tuple, random choice between [min, max) Set -1 to disable

  • text_color_cfg (TextColorCfg) – see TextColorCfg. has higher priority than RenderCfg.text_color_cfg

  • horizontal (bool) – generate the horizontal(default) or vertical text Set False to generate vertical text