Add read_string_int method to StreamUtil

This commit is contained in:
Kiki Luqman Hakiem 2015-04-30 21:45:46 +07:00
parent 39d9dfbf05
commit 035ebe3ed6

View File

@ -343,6 +343,14 @@ class FastImage
def read_int def read_int
read(2).unpack('n')[0] read(2).unpack('n')[0]
end end
def read_string_int
value = []
while read(1) =~ /(\d)/
value << $1
end
value.join.to_i
end
end end
class FiberStream # :nodoc: class FiberStream # :nodoc:
@ -625,10 +633,12 @@ class FastImage
case char case char
when "=" when "="
if attr_name.join =~ /width/i if attr_name.join =~ /width/i
@width = attr_value.to_i @stream.read(1)
@width = @stream.read_string_int
return if @height return if @height
elsif attr_name.join =~ /height/i elsif attr_name.join =~ /height/i
@height = attr_value.to_i @stream.read(1)
@height = @stream.read_string_int
return if @width return if @width
elsif attr_name.join =~ /viewbox/i elsif attr_name.join =~ /viewbox/i
values = attr_value.split(/\s/) values = attr_value.split(/\s/)