Skip to content
This repository has been archived by the owner on Nov 29, 2019. It is now read-only.

Commit

Permalink
Further fix to section aggregation. Gets some INASP journals working.
Browse files Browse the repository at this point in the history
  • Loading branch information
kjw committed Apr 10, 2012
1 parent 1f56231 commit 11ad669
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
13 changes: 8 additions & 5 deletions lib/analysis/sections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def self.include_in pdf
not (column[:page] == region[:page] && Spatial.contains?(column, region))
end

containers.first[:regions] << region unless containers.count.zero?
containers.first[:regions] << region unless containers.empty?
end

parser.after do
Expand All @@ -110,19 +110,22 @@ def self.include_in pdf
merging_region = nil

pages.each_pair do |page, columns|
columns.each do |c|
column = c[:column]
columns.each do |container|
column = container[:column]

c[:regions].each do |region|
container[:regions].each do |region|
if candidate? pdf, region, column
if !merging_region.nil? && match?(merging_region, region)
content = Spatial.merge_lines(merging_region, region, {})

merging_region.merge!(content)

merging_region[:components] << Spatial.get_dimensions(region)
elsif !merging_region.nil?
sections << merging_region
merging_region = nil
merging_region = region.merge({
:components => [Spatial.get_dimensions(region)]
})
else
merging_region = region.merge({
:components => [Spatial.get_dimensions(region)]
Expand Down
10 changes: 9 additions & 1 deletion lib/font_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ def initialize font
@ascent = font.ascent
@descent = font.descent
@bbox = font.bbox
@glyph_width_lookup = proc { |c| font.glyph_width c.codepoints.first }
@glyph_width_lookup = proc do |c|
begin
font.glyph_width c.codepoints.first
rescue TypeError => e
# It seems some fonts don't have a first char attribute in their
# descriptor and this causes problems for pdf-reader.
0
end
end
end

if not @bbox.nil?
Expand Down
14 changes: 7 additions & 7 deletions lib/model/regions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def self.append_line_spacing region
height_taken = from_top + line[:height]
end
end

def self.include_in pdf
pdf.spatials :regions, :paged => true, :depends_on => [:chunks] do |parser|
chunks = []
Expand All @@ -51,7 +51,7 @@ def self.include_in pdf
chunks = []
regions = []
end

parser.objects :chunks do |chunk|
y = chunk[:y].floor

Expand All @@ -72,16 +72,16 @@ def self.include_in pdf
chunk[:lines] = [Spatial.as_line(chunk)]
chunk.delete :content
end

compare_index = 1
while chunks.count > compare_index
b = chunks.first
t = chunks[compare_index]

line_height = b[:line_height]
line_slop = [line_height, t[:height]].min * pdf.settings[:line_slop]
incident_y = (b[:y] + b[:height] + line_slop) >= t[:y]

if incident_y && incident(t, b)
chunks[0] = Spatial.merge t, b, :lines => true
chunks.delete_at compare_index
Expand All @@ -96,7 +96,7 @@ def self.include_in pdf
compare_index = 1
end
end

regions << chunks.first unless chunks.first.nil?

regions.each do |region|
Expand All @@ -112,6 +112,6 @@ def self.include_in pdf
end
end
end

end
end

0 comments on commit 11ad669

Please sign in to comment.