pixelflow_canvas 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pixelflow_canvas/fonts/4x6.bdf +11981 -0
- data/lib/pixelflow_canvas/fonts/6x10.bdf +27181 -0
- data/lib/pixelflow_canvas/fonts/7x13.bdf +64553 -0
- data/lib/pixelflow_canvas/fonts/7x13B.bdf +20093 -0
- data/lib/pixelflow_canvas/fonts/8x13.bdf +74092 -0
- data/lib/pixelflow_canvas/fonts/8x13B.bdf +22852 -0
- data/lib/pixelflow_canvas/fonts/9x15.bdf +105126 -0
- data/lib/pixelflow_canvas/fonts/9x15B.bdf +37168 -0
- data/lib/pixelflow_canvas/version.rb +1 -1
- data/lib/pixelflow_canvas.rb +67 -0
- data/{test-draw.rb → test-triangle.rb} +0 -1
- metadata +10 -2
data/lib/pixelflow_canvas.rb
CHANGED
@@ -484,6 +484,73 @@ module Pixelflow
|
|
484
484
|
draw_line(x1, y1, x2, y2)
|
485
485
|
draw_line(x2, y2, x0, y0)
|
486
486
|
end
|
487
|
+
|
488
|
+
# FONT RENDERING
|
489
|
+
def self.load_font(font)
|
490
|
+
@@cypher_fonts ||= {}
|
491
|
+
return if @@cypher_fonts[font]
|
492
|
+
# STDERR.puts "Loading font from #{path}..."
|
493
|
+
font_data = {}
|
494
|
+
File.open(File.join(File.dirname(__FILE__), 'pixelflow_canvas', 'fonts', "#{font}.bdf")) do |f|
|
495
|
+
char = nil
|
496
|
+
f.each_line do |line|
|
497
|
+
if line[0, 9] == 'STARTCHAR'
|
498
|
+
char = {}
|
499
|
+
elsif line[0, 8] == 'ENCODING'
|
500
|
+
char[:encoding] = line.sub('ENCODING ', '').strip.to_i
|
501
|
+
elsif line[0, 7] == 'ENDCHAR'
|
502
|
+
font_data[char[:encoding]] = char
|
503
|
+
char = nil
|
504
|
+
elsif line[0, 3] == 'BBX'
|
505
|
+
parts = line.split(' ')
|
506
|
+
char[:width] = parts[1].to_i
|
507
|
+
char[:height] = parts[2].to_i
|
508
|
+
elsif line[0, 6] == 'BITMAP'
|
509
|
+
char[:bitmap] = []
|
510
|
+
else
|
511
|
+
if char && char[:bitmap]
|
512
|
+
char[:bitmap] << line.to_i(16)
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
517
|
+
@@cypher_fonts[font] = font_data
|
518
|
+
end
|
519
|
+
|
520
|
+
def draw_text(x, y, s, font, scale = 1)
|
521
|
+
Canvas.load_font(font)
|
522
|
+
dx = 0
|
523
|
+
s.each_char do |c|
|
524
|
+
glyph = @@cypher_fonts[font][c.ord]
|
525
|
+
if glyph
|
526
|
+
w = ((((glyph[:width] - 1) >> 3) + 1) << 3) - 1
|
527
|
+
(0...glyph[:height]).each do |iy|
|
528
|
+
(0...glyph[:width]).each do |ix|
|
529
|
+
if (((glyph[:bitmap][iy] >> (w - ix)) & 1) == 1)
|
530
|
+
(0...scale).each do |oy|
|
531
|
+
(0...scale).each do |ox|
|
532
|
+
set_pixel(x + (ix + dx) * scale + ox, y + iy * scale + oy)
|
533
|
+
end
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|
537
|
+
end
|
538
|
+
dx += glyph[:width]
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
def self.text_width(s, font, options = {})
|
544
|
+
Canvas.load_font(font)
|
545
|
+
width = 0
|
546
|
+
s.each_char do |c|
|
547
|
+
glyph = @@cypher_fonts[font][c.ord]
|
548
|
+
if glyph
|
549
|
+
width += glyph[:width]
|
550
|
+
end
|
551
|
+
end
|
552
|
+
width
|
553
|
+
end
|
487
554
|
end
|
488
555
|
|
489
556
|
class Turtle
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixelflow_canvas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Specht
|
@@ -36,12 +36,20 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
38
|
- lib/pixelflow_canvas.rb
|
39
|
+
- lib/pixelflow_canvas/fonts/4x6.bdf
|
40
|
+
- lib/pixelflow_canvas/fonts/6x10.bdf
|
41
|
+
- lib/pixelflow_canvas/fonts/7x13.bdf
|
42
|
+
- lib/pixelflow_canvas/fonts/7x13B.bdf
|
43
|
+
- lib/pixelflow_canvas/fonts/8x13.bdf
|
44
|
+
- lib/pixelflow_canvas/fonts/8x13B.bdf
|
45
|
+
- lib/pixelflow_canvas/fonts/9x15.bdf
|
46
|
+
- lib/pixelflow_canvas/fonts/9x15B.bdf
|
39
47
|
- lib/pixelflow_canvas/version.rb
|
40
48
|
- lib/pixelflow_canvas/vga_palette.rb
|
41
49
|
- sig/pixelflow_canvas.rbs
|
42
50
|
- test-anaglyph.rb
|
43
|
-
- test-draw.rb
|
44
51
|
- test-sirds.rb
|
52
|
+
- test-triangle.rb
|
45
53
|
- test-turtle.rb
|
46
54
|
- test.rb
|
47
55
|
homepage: https://github.com/specht/pixelflow_canvas_ruby
|