Class: Skrift::BoxDrawing

Inherits:
Object
  • Object
show all
Defined in:
lib/skrift/boxdrawing.rb,
lib/skrift/boxdrawing/version.rb

Overview

Renders Unicode box-drawing glyphs (U+2500..U+257F) as crisp alpha Images for a fixed cell size, independent of any font. Wire it into a renderer via Skrift::GlyphCache’s ‘special:` hook:

boxes = Skrift::BoxDrawing.new(cache.cell_width, cache.cell_height)
cache = Skrift::GlyphCache.new(font, x_scale: 16, y_scale: 16,
                               special: ->(cp) { boxes.glyph(cp) })

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(boxw, boxh) ⇒ BoxDrawing

Returns a new instance of BoxDrawing.



13
14
15
16
# File 'lib/skrift/boxdrawing.rb', line 13

def initialize(boxw, boxh)
  @boxw, @boxh = boxw, boxh
  @cache = {}
end

Instance Method Details

#glyph(cp) ⇒ Object

A Skrift::Image for a box-drawing codepoint, the full block █ (U+2588), or nil otherwise.



22
23
24
25
# File 'lib/skrift/boxdrawing.rb', line 22

def glyph(cp)
  return nil unless (0x2500..0x257f).include?(cp) || cp == 0x2588
  @cache[cp] ||= cache_box(cp)
end

#strideObject



18
# File 'lib/skrift/boxdrawing.rb', line 18

def stride = (@boxw + 3) & ~3