Module: PrintShopFont

Includes:
Font
Included in:
AppleDosPrintShopFont
Defined in:
lib/native_file_types/apple2/ApplePrintShopFont.rb

Instance Method Summary collapse

Methods included from Font

#draw_string, #font_description, #font_format, #normalised_font_name, #picture_format, #picture_height, #picture_width, #to_font, #to_picture

Instance Method Details

#ascii_to_shape_number(char) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 109

def ascii_to_shape_number(char)
  b=char.upcase[0]
  case b
    when 32..90 then return b-32
  end
  nil
end

#char_height(char = "A") ⇒ Object



53
54
55
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 53

def char_height(char="A")
  2*inter_character_gap+unpadded_char_height(char)
end

#char_width(char) ⇒ Object



39
40
41
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 39

def char_width(char)
  inter_character_gap+unpadded_char_width(char)
end

#draw_char(canvas, char, x, y, colour) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 116

def draw_char(canvas,char,x,y,colour)
  bitmap=get_bitmap(char)
  return [x,y] if bitmap.nil?
  bitmap.length.times do |line|
    bitmap[line].length.times do |col|
      if bitmap[line][col]==1 then
        canvas[x+col, y+line]=colour
      end
    end
  end
  [x+char_width(char),y]
end

#get_bitmap(char) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 73

def get_bitmap(char)
  b=ascii_to_shape_number(char)
  return nil if b.nil?
  lo= contents[b+bitmap_pointer_lo_table]
  hi= contents[b+bitmap_pointer_hi_table]
  ptr=(hi<<8)+lo
  width_in_pixels=unpadded_char_width(char)
  padded_width_in_pixels=char_width(char)
  width_in_bytes=(width_in_pixels+7)/8
  height=unpadded_char_height(char)
# puts "#{char}/%02x = %04x - width-%02x/%01x, height=%02x" % [b,ptr,width_in_pixels,width_in_bytes,height]
  bitmap=[]
  inter_character_gap.times {bitmap<<Array.new(Array.new(padded_width_in_pixels,0))}
  offset=inter_character_gap
  height.times do |i|
    line=i+offset
    bitmap[line]=Array.new(padded_width_in_pixels,0)
    col=0
    width_in_bytes.times do 
      font_byte=data_without_header[ptr-load_address+i*width_in_bytes+col/8]
      8.times do |x_offset|
        bit_mask=1<<(8-(x_offset+1))
        if ((font_byte & bit_mask)==bit_mask) then
          bitmap[line][col]=1
        end
        col+=1
        break if col>=width_in_pixels
      end
    end
  end
  inter_character_gap.times {bitmap<<Array.new(Array.new(padded_width_in_pixels,0))}
  
  raise "bitmap length error" unless bitmap.length==char_height(char)
  bitmap
end

#get_charlistObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 23

def get_charlist
  if @charlist.nil? then
    @charlist=[]
    (32..90).each do |b|
      c=b.chr
      char_data={}
      char_data[:native_encoding]=b
      char_data[:unicode_encoding]=b
      char_data[:width]=char_width(c) #width in pixels
      char_data[:bitstreams]=get_bitmap(c)
      @charlist<<char_data
    end

  end
  @charlist
end

#inter_character_gapObject



49
50
51
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 49

def inter_character_gap
  2
end

#line_of_printObject



57
58
59
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 57

def line_of_print
 unpadded_char_height("A")
end

#point_sizeObject



66
67
68
69
70
71
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 66

def point_size
  if @point_size.nil? then
    @point_size=char_height('A')
  end
  @point_size
end

#unpadded_char_height(char) ⇒ Object



60
61
62
63
64
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 60

def unpadded_char_height(char)
  b=ascii_to_shape_number(char)
  return nil if b.nil?
  return contents[b+height_table_start]
end

#unpadded_char_width(char) ⇒ Object



43
44
45
46
47
# File 'lib/native_file_types/apple2/ApplePrintShopFont.rb', line 43

def unpadded_char_width(char)
  b=ascii_to_shape_number(char)
  return nil if b.nil?
  return contents[b+width_table_start]
end