Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table cell auto width calculated wrong with inline styles #360

Closed
cymen opened this issue Jun 15, 2012 · 2 comments
Closed

Table cell auto width calculated wrong with inline styles #360

cymen opened this issue Jun 15, 2012 · 2 comments

Comments

@cymen
Copy link

cymen commented Jun 15, 2012

Using prawn (0.12.0) gem.

I noticed that the cell width calculate seems to take into account the characters doing inline styles even though these aren't visible in the cell. For example, look at the width output on these 3 tables. Note how the inline styles on the bottom row of table 2 makes the cell wider. The same thing happens with the 1st table -- hopefully these three illustrate the issue. I am able to set the width manually on the table to make it narrower.

require 'prawn'
require 'pry'

Prawn::Document.generate("bug.pdf") do

      vertical_date_1 = make_table [
          [ "<font size='22'>5</font>" ],
          [ "<font size='44'><color rgb='ffffff'>18</color></font>" ],
          [ "<font size='22'>2012</font>" ]
      ],  
      cell_style: {border_width: 0}, 
      do  
        column(0).align = :center
        column(0).inline_format = true
        row(1).style background_color: '32a5f5'
      end 

      vertical_date_2 = make_table [
          [ "5" ],
          [ "18" ],
          [ "<font size='22'>2012</font>" ]
      ],  
      cell_style: {border_width: 0}, 
      do  
        column(0).align = :center
        column(0).inline_format = true
        row(1).style background_color: '32a5f5'
      end 

      vertical_date_3 = make_table [
          [ "5" ],
          [ "18" ],
          [ "2012" ]
      ],  
      cell_style: {border_width: 0}, 
      do  
        column(0).align = :center
        column(0).inline_format = true
        row(1).style background_color: '32a5f5'
      end 

      vertical_date_1.draw
      vertical_date_2.draw
      vertical_date_3.draw
end

The bug actually causes problems with this as it thinks the width is larger than 540 when it isn't:

require 'prawn'
require 'pry'

Prawn::Document.generate("bug2.pdf") do

  bounding_box [0, 300], width: 540, height: 200 do

    some_other_table = make_table [
      [ "<font size='22'>blah blah blah</font>" ]
    ],  
    cell_style: {border_width: 0, kerning: true},
    do  
      column(0).inline_format = true
    end 

    total_and_terms = make_table [
      [ "<font size='15'>Total:</font>", "<font size='15'><b><color rgb='32a5f5'>$20,881.25</color></b></font>" ],
      [ "<font size='15'>Terms:</font>", "<font size='15'><b><color rgb='32a5f5'>NET 30</color></b></font>" ]
    ],  
    cell_style: {border_width: 0, kerning: true},
    do  
      column(0).inline_format = true
      column(1).inline_format = true
    end 

    table [
      [ some_other_table, total_and_terms ]
    ]   
  end 
end
@cymen
Copy link
Author

cymen commented Jun 15, 2012

I see the comment now at the top of lib/prawn/table.rb to set widths manually if the calculated width fails. So I'll go forward with that.

@bradediger
Copy link
Member

The issue with sizing styled text was fixed in 373cc43, which as of now is only available in the RC version of prawn (1.0.0.rc1). See issue #167.

-be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants