Class: Skrift::BoxDrawing
- Inherits:
-
Object
- Object
- Skrift::BoxDrawing
- 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
-
#glyph(cp) ⇒ Object
A Skrift::Image for a box-drawing codepoint, the full block █ (U+2588), or nil otherwise.
-
#initialize(boxw, boxh) ⇒ BoxDrawing
constructor
A new instance of BoxDrawing.
- #stride ⇒ Object
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 |
#stride ⇒ Object
18 |
# File 'lib/skrift/boxdrawing.rb', line 18 def stride = (@boxw + 3) & ~3 |