lib/pdf/reader/page_layout.rb in pdf-reader-1.4.1 vs lib/pdf/reader/page_layout.rb in pdf-reader-2.0.0.beta1
- old
+ new
@@ -6,21 +6,23 @@
# string that best approximates the way they'd appear on a render PDF page.
#
# media box should be a 4 number array that describes the dimensions of the
# page to be rendered as described by the page's MediaBox attribute
class PageLayout
+
+ DEFAULT_FONT_SIZE = 12
+
def initialize(runs, mediabox)
raise ArgumentError, "a mediabox must be provided" if mediabox.nil?
@runs = merge_runs(runs)
- @mean_font_size = mean(@runs.map(&:font_size)) || 0
+ @mean_font_size = mean(@runs.map(&:font_size)) || DEFAULT_FONT_SIZE
+ @mean_font_size = DEFAULT_FONT_SIZE if @mean_font_size == 0
@mean_glyph_width = mean(@runs.map(&:mean_character_width)) || 0
@page_width = mediabox[2] - mediabox[0]
@page_height = mediabox[3] - mediabox[1]
@x_offset = @runs.map(&:x).sort.first
- @current_platform_is_rbx_19 = RUBY_DESCRIPTION =~ /\Arubinius 2.0.0/ &&
- RUBY_VERSION >= "1.9.0"
end
def to_s
return "" if @runs.empty?
@@ -108,23 +110,10 @@
end
end
runs
end
- # This is a simple alternative to String#[]=. We can't use the string
- # method as it's buggy on rubinius 2.0rc1 (in 1.9 mode)
- #
- # See my bug report at https://github.com/rubinius/rubinius/issues/1985
def local_string_insert(haystack, needle, index)
- if @current_platform_is_rbx_19
- char_count = needle.length
- haystack.replace(
- (haystack[0,index] || "") +
- needle +
- (haystack[index+char_count,500] || "")
- )
- else
- haystack[Range.new(index, index + needle.length - 1)] = String.new(needle)
- end
+ haystack[Range.new(index, index + needle.length - 1)] = String.new(needle)
end
end
end