module BBS::BlockFont
A block font five pixels high for a boardโs logo: the letters A-Z, the digits and some signs, most three pixels wide, a pixel of space between them. A modern terminal shows it in half blocks, two pixel rows to a line (::half_blocks); a Commodore 64 in reversed spaces, a pixel row to a line (::petscii). A word of nine letters is 35 columns wide, so it fits the C64โs 40.
A glyph is five Strings, # for a set pixel and . for a clear one. Every method takes glyphs, a Hash of glyphs over FONT, for another shape of a letter (NARROW_I, WIDE_W) or one of the boardโs own.
BBS::BlockFont.half_blocks('WARP') BBS::BlockFont.petscii('SCRIPTORIUM', colors: [WH, WH, YE, YE, CY], glyphs: BBS::BlockFont::NARROW_I)
Constants
- CLEAR
-
A clear pixel in a glyph row.
- FONT
-
The glyphs: a character => its five rows.
- HALF
-
A pair of pixels, the upper and the lower, => its half block.
- HEIGHT
-
The pixel rows of a glyph.
- NARROW_I
-
An I one pixel wide, a plain stroke.
- SET
-
A set pixel in a glyph row.
- WIDE_W
-
A W five pixels wide, with the middle stroke.
Public Class Methods
Source
# File lib/bbs/block_font.rb, line 56 def self.glyph(char, glyphs: {}) glyphs[char] || FONT[char] || glyphs[char.upcase] || FONT.fetch(char.upcase) end
The five rows of char (looked up as it is, then in capitals) in glyphs over FONT. Raises KeyError for a character the font lacks.
# File lib/bbs/block_font.rb, line 83 def self.half_blocks(word, glyphs: {}, colors: nil, reset: Ansi::RESET) lines = pixel_pairs(rows(word, glyphs: glyphs)).map { |pairs| pairs.map { |pair| HALF[pair] }.join } return lines if colors.nil? lines.each_with_index.map { |line, i| "#{color_of(colors, i)}#{line}#{reset}" } end
word in three rows of half blocks (โ โ โ and space), the five pixel rows two by two, the last with a clear row under it. Each row is as wide as the word.
- colors
-
an Array of SGR sequences, one a row, or one sequence for all: each row starts with its colour and ends with
reset;nilfor bare rows - reset
-
what ends a coloured row
Returns the rows, an Array of three Strings.
# File lib/bbs/block_font.rb, line 119 def self.petscii(word, colors:, glyphs: {}, indent: 0, reset: Ansi::GREY, reverse: Ansi::REVERSE, normal: Ansi::REVERSE_OFF) rows(word, glyphs: glyphs).each_with_index.map do |row, i| "#{' ' * indent}#{color_of(colors, i)}#{reversed(row, reverse: reverse, normal: normal)}#{reset}" end end
word in five rows of reversed spaces (::reversed) for a C64, each row indent spaces in, then its colour, then the pixels, then reset.
- colors
-
an Array of SGR sequences (
BBS::Petscii::Colors), one a row, or one sequence for all - indent
-
the spaces before each row
- reset
-
what ends each row
Returns the rows, an Array of five Strings.
BBS::BlockFont.petscii('WARP', colors: [LB, LB, CY, CY, WH], indent: 10)
# File lib/bbs/block_font.rb, line 104 def self.reversed(row, reverse: Ansi::REVERSE, normal: Ansi::REVERSE_OFF) row.gsub(/#{SET}+/o) { |run| "#{reverse}#{' ' * run.size}#{normal}" }.tr(CLEAR, ' ') end
One pixel row, a String of # and . (or spaces), as reversed spaces: every run of set pixels between reverse and normal, the clear ones plain spaces.
BBS::BlockFont.reversed('#.##') # => "\e[7m \e[27m \e[7m \e[27m"
Source
# File lib/bbs/block_font.rb, line 65 def self.rows(word, glyphs: {}) chars = word.to_s.chars Array.new(HEIGHT) { |row| chars.map { |c| glyph(c, glyphs: glyphs)[row] }.join(CLEAR) } end
The five pixel rows of word, its glyphs side by side with a clear column between them: an Array of Strings of # and .. Raises KeyError for a character the font lacks.
BBS::BlockFont.rows('HI').first # => "#.#.###"
Source
# File lib/bbs/block_font.rb, line 71 def self.width(word, glyphs: {}) = rows(word, glyphs: glyphs).first.length
The columns word takes.