mcfonts.compacting#

Compacting is the process of taking every "bitmap" character texture provided
by a Minecraft font provider and storing it in as little space as possible.

This means:

  1. Finding the largest effective dimensions out of all the characters,

  2. Expanding the dimensions of all other character textures to fit those new dimensions,

  3. Creating a new texture that will fit all characters in those dimensions,

  4. Sequencing them one-after-another while ignoring characters with a blank texture,

  5. Creating a new charlist that corresponds with the compacted texture.

This contains functions for compacting any provider(s) into individual textures (one for each provider), and for compacting a list of providers into a single, cohesive texture.

Module Contents#

Functions#

compact_glyphs(, square_cells, tuple[int, int]])

Given a list of glyphs, return an image wherein all glyphs are compacted into a single sheet,

compact_images(, square_cells, include_empty_images, ...)

Similar to compact_glyphs() except that it works on plain Image instead.

mcfonts.compacting.compact_glyphs(glyphs: list[mcfonts.glyphs.BitmapGlyph | mcfonts.glyphs.UnihexGlyph], chars_in_row: int = 0, cell_size: tuple[int, int] = (0, 0), square_cells: bool = True) tuple[PIL.Image.Image, tuple[int, int]]#
Given a list of glyphs, return an image wherein all glyphs are compacted into a single sheet,
with the number of glyphs in one row matches chars_in_row (excluding exceptions).
Parameters:
  • glyphs -- A list of lists of [glyphs (PIL.Image.Image), their height, and their ascent]. Baseline can be calculated from this: \(height - ascent\).

  • chars_in_row -- How many characters to fit inside each row of the resulting sheet. Only positive values will set fixed rows. If this is negative or 0, this will be set so that the resulting sheet is square. By default, this is 0 (a square).

  • cell_size -- What size to make each glyph cell. If this is (0, 0), this will be set to the largest dimensions of every glyph in glyphs. If this is any other tuple of numbers,

  • square_cells -- If True, each glyph's width will equal its height. This is based on whichever number is largest. If False, each glyph's width will be unrelated to its height.

Returns:

A tuple containing (a modified resource with the least amount of padding between glyphs, and a tuple of the size of each glyph cell).

mcfonts.compacting.compact_images(images: list[PIL.Image.Image | None], chars_in_row: int = 0, cell_size: tuple[int, int] = (0, 0), square_cells: bool = True, include_empty_images: bool = True) tuple[PIL.Image.Image, tuple[int, int]]#

Similar to compact_glyphs() except that it works on plain Image instead.