Class: C64GeosFont

Inherits:
C64GeosFile show all
Includes:
Font
Defined in:
lib/native_file_types/c64/C64GeosFont.rb

Instance Attribute Summary

Attributes inherited from NativeFileType

#aux_code, #contents, #file_system_image, #file_type, #filename

Instance Method Summary collapse

Methods included from Font

#draw_string, #font_format, #normalised_font_name, #picture_format, #to_font, #to_picture

Methods inherited from C64GeosFile

#contents, #header_filename, #icon_background, #icon_bitmap, #icon_foreground, #icon_format, #icon_height, #icon_tag, #icon_width, #info_block, #load_address, #parent_application, #record_nos, #to_hex_dump, #to_icon, #type_description

Methods inherited from CbmFile

file_system_file_types, #type_description

Methods inherited from NativeFileType

#<=>, #==, all_native_file_types, best_fit, code_for_tests, compatability_score, #data_without_header, file_type_matches?, #full_filename, #header_length, #initialize, is_valid_file_if, #load_address, load_address, matching_score, native_file_types_possible_on_file_system, non_matching_score, #to_hex_dump, #to_info_dump, #type_description

Methods included from SubclassTracking

extended

Constructor Details

This class inherits a constructor from NativeFileType

Instance Method Details

#bitstreams(char) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 108

def bitstreams(char)
	font_data=@contents[point_size+1]
	return nil if font_data.nil?
	bit_stream_index=font_data[0x04]+0x100*font_data[0x05]
	bit_stream_base=font_data[0x06]+0x100*font_data[0x07]
	char_pointer=2*((char[0]%0x80)-0x20)
	start_of_char=font_data[char_pointer+bit_stream_index]+0x100*font_data[char_pointer+bit_stream_index+1]
	start_of_next_char=font_data[char_pointer+bit_stream_index+2]+0x100*font_data[char_pointer+bit_stream_index+3]
#	puts "# #{filename} #{point_size} #{char} #{start_of_char} - #{start_of_next_char}"
	bitstream=[]
	char_height.times do |line|
		bitstream[line]=[]
		bit_counter=0
		start_of_line_bitstream=line*bytes_in_bitstream+bit_stream_base
		(start_of_char..start_of_next_char-1).each do |bit_offset|
			byte_offset=bit_offset/8
			bitmask=0b10000000>>(bit_offset % 8)
			byte=font_data[start_of_line_bitstream+byte_offset]
#			puts "%08b:%08b==%08b" % [byte,bitmask,byte & bitmask]
			bitstream[line][bit_counter]=(((byte & bitmask)!=0)? 1 : 0)
			bit_counter+=1
		end	
#		bitstream[line][bit_counter]="\n"
	end
	bitstream
end

#bytes_in_bitstreamObject



91
92
93
94
95
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 91

def bytes_in_bitstream
	font_data=@contents[point_size+1]
	return nil if font_data.nil?
	font_data[0x01]+font_data[0x02]*100	
end

#char_heightObject



97
98
99
100
101
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 97

def char_height
	font_data=@contents[point_size+1]
	return nil if font_data.nil?
	font_data[0x03]
end

#char_width(char) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 78

def char_width(char)
	
	font_data=@contents[point_size+1]
	return nil if font_data.nil?
	bit_stream_index=font_data[0x04]+0x100*font_data[0x05]
	char_pointer=2*((char[0]%0x80)-0x20)
	start_of_char=font_data[char_pointer+bit_stream_index]+0x100*font_data[char_pointer+bit_stream_index+1]
	start_of_next_char=font_data[char_pointer+bit_stream_index+2]+0x100*font_data[char_pointer+bit_stream_index+3]
	width=(start_of_next_char-start_of_char)
	raise "invalid char width #{width} for char $#{"%02x" % char[0]} point size #{point_size} - char pointer=#{char_pointer}" if width>(2*point_size)
	width
end

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



138
139
140
141
142
143
144
145
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 138

def draw_char(canvas,char,x,y,colour)
	lines=bitstreams(char)
	lines.length.times do |line|
		lines[line].length.times do |pixel|
			canvas[x+pixel,y+line]=colour if lines[line][pixel]==1
		end
	end
end

#font_descriptionObject



27
28
29
30
31
32
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 27

def font_description
  first_letter=filename[0].chr
  #some fonts have only upper case, some have only lower case, some have both
  best_case_filename= (char_width(first_letter.upcase) > char_width(first_letter.downcase) ? filename.upcase : filename.downcase)
  "#{best_case_filename} #{point_size}"
end

#get_charlistObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 34

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

#lengthsObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 66

def lengths
	if @lengths.nil? then
		@lengths=[]
		16.times do |i|
			length=info_block[2*i+0x61]+100*info_block[2*i+0x62]
			break if length==0
			@lengths<<length
		end
	end
	@lengths
end

#line_of_printObject



103
104
105
106
107
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 103

def line_of_print
	font_data=@contents[point_size+1]
	return nil if font_data.nil?
	font_data[0x00]
end

#meta_dataObject



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 148

def 
	return super unless @contents.kind_of?(Array) && !info_block.nil?
	@meta_data["geos_font_id"]="$%02x" % (info_block[0x80]+info_block[0x81]*100)
	@meta_data["geos_font_point_ids"]=(point_ids.collect{|x| '$%04x' % x}).join(",")
	@meta_data["geos_font_lengths"]=(lengths.collect{|x| '$%04x' % x}).join(",")
#	point_sizes.each do |point_size|
#		prefix="geos_font_point_size_#{point_size}"
#		font_data=@contents[point_size+1]
#		next if font_data.nil?
#		@meta_data["#{prefix}_line_of_print"]=font_data[0x00]
#		@meta_data["#{prefix}_bytes_in_bitstream"]=bytes_in_bitstream(point_size)
#		@meta_data["#{prefix}_character_height"]=char_height(point_size)
#		@meta_data["#{prefix}_character_width_space"]=char_width(point_size," ")
#		@meta_data["#{prefix}_character_width_A"]=char_width(point_size,"A")
#		@meta_data["#{prefix}_bitstream_A"]=bitstreams(point_size,"A")		
#  	end
	
	super
end

#picture_heightObject



23
24
25
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 23

def picture_height
	240
end

#picture_widthObject



20
21
22
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 20

def picture_width
	320
end

#point_idsObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 49

def point_ids
	if @point_ids.nil? then
		@point_ids=[]
		16.times do |i|
			point_id=info_block[2*i+0x82]+100*info_block[2*i+0x83]
			break if point_id==0
			@point_ids<<point_id 
		end
	end
	@point_ids
end

#point_sizeObject



61
62
63
64
# File 'lib/native_file_types/c64/C64GeosFont.rb', line 61

def point_size
	#just use the biggest point size
	record_nos.last-1
end