Module: Font
- Included in:
- AtariBitmapFont, C64GeosFont, PrintShopFont, ShapeTableFont
- Defined in:
- lib/native_file_types/generic/Font.rb
Instance Method Summary collapse
- #char_height ⇒ Object
- #draw_string(canvas, string, start_x, start_y, colour) ⇒ Object
- #font_description ⇒ Object
- #font_format ⇒ Object
- #line_of_print ⇒ Object
- #normalised_font_name ⇒ Object
- #picture_format ⇒ Object
- #picture_height ⇒ Object
- #picture_width ⇒ Object
-
#to_font ⇒ Object
export font in Glyph Bitmap Distribution Format (BDF).
- #to_picture ⇒ Object
Instance Method Details
#char_height ⇒ Object
26 27 28 |
# File 'lib/native_file_types/generic/Font.rb', line 26 def char_height point_size end |
#draw_string(canvas, string, start_x, start_y, colour) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/native_file_types/generic/Font.rb', line 101 def draw_string(canvas,string,start_x,start_y,colour) x=start_x y=start_y string.each_byte do |b| c=b.chr width=char_width(c) if (x+width>=picture_width) then x=0 y+=point_size end break if (y+point_size)>=picture_height draw_char(canvas,c,x,y,colour) x+=width end [x,y] end |
#font_description ⇒ Object
30 31 32 |
# File 'lib/native_file_types/generic/Font.rb', line 30 def font_description "#{fontname} #{point_size.to_i}" end |
#font_format ⇒ Object
11 12 13 |
# File 'lib/native_file_types/generic/Font.rb', line 11 def font_format :bdf end |
#line_of_print ⇒ Object
22 23 24 |
# File 'lib/native_file_types/generic/Font.rb', line 22 def line_of_print point_size end |
#normalised_font_name ⇒ Object
34 35 36 |
# File 'lib/native_file_types/generic/Font.rb', line 34 def normalised_font_name "peekbot-#{filename.downcase.gsub(/\W/,"-")}#{ filename=~/\d$/ ? "" : "-"+point_size.to_s}" end |
#picture_format ⇒ Object
7 8 9 |
# File 'lib/native_file_types/generic/Font.rb', line 7 def picture_format :png end |
#picture_height ⇒ Object
17 18 19 |
# File 'lib/native_file_types/generic/Font.rb', line 17 def picture_height file_system_image.file_system.host_system.screen_rows*file_system_image.file_system.host_system.font_height end |
#picture_width ⇒ Object
14 15 16 |
# File 'lib/native_file_types/generic/Font.rb', line 14 def picture_width file_system_image.file_system.host_system.default_screen_width*file_system_image.file_system.host_system.font_width end |
#to_font ⇒ Object
export font in Glyph Bitmap Distribution Format (BDF)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/native_file_types/generic/Font.rb', line 39 def to_font charlist=get_charlist s=" STARTFONT 2.1 FONT #{normalised_font_name} SIZE #{point_size} 75 75 COMMENT image: #{file_system_image.filename} COMMENT filename: #{filename} COMMENT timestamp: #{Time.now} FONTBOUNDINGBOX #{point_size} #{point_size} 0 0 STARTPROPERTIES 2 FONT_ASCENT #{line_of_print} FONT_DESCENT #{char_height-line_of_print} ENDPROPERTIES CHARS #{charlist.length}" charlist.each do |char_data| b=char_data[:unicode_encoding] dwidth=char_data[:width]#char_width(b.chr) #width in pixels swidth=(1000*dwidth)/point_size #width in 'Scalable Width' units lines=char_data[:bitstreams] char_height=lines.length s<<" STARTCHAR U+#{"%04x" % b} ENCODING #{b} SWIDTH #{swidth} 0 DWIDTH #{dwidth} 0 BBX #{dwidth} #{char_height} 0 #{line_of_print-char_height} BITMAP " lines.length.times do |line| # puts "line #{line} of #{lines.length} for char #{b}" bitmap=0 dwidth.times do |pixel| bitmap=bitmap<<1 bitmap+=1 if (lines[line][pixel]==1) end bitmap_byte_width=((dwidth+7)/8) bitmap<<=((8-(dwidth%8))%8) s<<("%0#{2*bitmap_byte_width}x\n" % bitmap) end s<<"ENDCHAR\n" end s<<" ENDFONT " s end |
#to_picture ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/native_file_types/generic/Font.rb', line 92 def to_picture require 'PatchedPNG' canvas = PNG::Canvas.new picture_width,picture_height, file_system_image.file_system.host_system.default_background_colour draw_sampler(canvas) png = PNG.new canvas result=png.raw_bytes result end |