Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Dynamic Height for Bounding Boxes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sam  
View profile  
 More options Jan 28, 1:34 pm
From: Sam <sam.pil...@gmail.com>
Date: Wed, 28 Jan 2009 10:34:20 -0800 (PST)
Local: Wed, Jan 28 2009 1:34 pm
Subject: Dynamic Height for Bounding Boxes
Greetings everyone,

I'm having trouble building a simple document that has several
sections spanning the entire width of the document, but which should
have dynamically expanding heights depending on what's contained
within them.

Currently I have several consecutive bounding_box's, and if I simply
do not specify a :height for the bounding_box call the content
displays fine, but the next bounding_box's content overlap the first
bounding_box, rather than starting after it. I've tried using
pdf.cursor and pdf.y for the coordinates of the second bounding_box
call, but with the same results.

Any guidance would be much appreciated.

Sam


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gregory Brown  
View profile  
 More options Jan 28, 1:38 pm
From: Gregory Brown <gregory.t.br...@gmail.com>
Date: Wed, 28 Jan 2009 13:38:58 -0500
Local: Wed, Jan 28 2009 1:38 pm
Subject: Re: Dynamic Height for Bounding Boxes

On Wed, Jan 28, 2009 at 1:34 PM, Sam <sam.pil...@gmail.com> wrote:
> Currently I have several consecutive bounding_box's, and if I simply
> do not specify a :height for the bounding_box call the content
> displays fine, but the next bounding_box's content overlap the first
> bounding_box, rather than starting after it. I've tried using
> pdf.cursor and pdf.y for the coordinates of the second bounding_box
> call, but with the same results.

> Any guidance would be much appreciated.

I'd be happy to help you take a look at this problem, but to do that,
it'd be much better to work against some code samples rather than try
to describe the problem / solution in words.  Can you code me up an
example of your problem?

-greg

--
Technical Blaag at: http://blog.majesticseacreature.com
 Non-tech stuff at: http://metametta.blogspot.com
"Ruby Best Practices"  Book now in O'Reilly Roughcuts:
http://rubybestpractices.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam  
View profile  
 More options Jan 28, 3:22 pm
From: Sam <sam.pil...@gmail.com>
Date: Wed, 28 Jan 2009 12:22:18 -0800 (PST)
Local: Wed, Jan 28 2009 3:22 pm
Subject: Re: Dynamic Height for Bounding Boxes
Hey Greg, thanks for the quick reply! I should have just posted a
sample in my original -- sorry bout that.

So in the following example of what I'm trying to do, I've got three
bounding_boxes (two of them with nested bounding_boxes) with the
margin bounding_box as an immediate parent. I simply want these three
bounding_boxes to display one after the other vertically down the
page. As it stands however, they stack all up on top of each other
smooshed at the top of the page. I realize that I can push the two
bottom bounding_boxes further down the page by specifying [0,
pdf.bounds.height - n], but I'm not always sure how large the content
of the bounding boxes will be, and would like them to collapse to fit.

Thanks again Greg,
Sam

pdf.bounding_box [0, pdf.bounds.height], :width => pdf.bounds.width
do
  pdf.image "#{RAILS_ROOT}/public/images/favalogoheader.png"

  pdf.bounding_box [100, pdf.bounds.height], :width => 200 do
    pdf.font_size = 12
    pdf.text "FAVA: Film and Video Arts Society"
    pdf.font_size = 8
    pdf.text 'some stuff here'
    pdf.text 'some stuff here'
    pdf.text 'some stuff here'
    pdf.text 'some stuff here'
    pdf.text 'some stuff here'
    pdf.text 'some stuff here'
  end

  pdf.bounding_box [pdf.bounds.width - 150, pdf.bounds.height], :width
=> 150 do
    pdf.font_size = 10
    pdf.text "Invoice #...@invoice.reference}", :align => :right
    pdf.text "#...@invoice.invoice_date.strftime('%a %b %d
%Y')}", :align => :right
  end
end

pdf.bounding_box [0, pdf.cursor], :width => pdf.bounds.width, :height
=> 60 do
  pdf.line_width = 1
  pdf.line pdf.bounds.top_left, pdf.bounds.top_right
  pdf.stroke

  pdf.bounding_box [0, pdf.bounds.height - 10], :width => 300 do
    pdf.font_size = 10
    if @invoice.is_for_user_entity?
      pdf.text "#...@invoice.account.user_entity.full_name}", :size =>
12
      pdf.text "#...@invoice.account.user_entity.address1}" if !
@invoice.account.user_entity.address1.blank?
      pdf.text "#...@invoice.account.user_entity.address2}" if !
@invoice.account.user_entity.address2.blank?
      pdf.text "#...@invoice.account.user_entity.city} #
{...@invoice.account.user_entity.province} #
{...@invoice.account.user_entity.postal_code}"
      pdf.text "#
{...@invoice.account.user_entity.primary_operator_first_name} #
{...@invoice.account.user_entity.primary_operator_last_name} / #
{...@invoice.accountuser_entity.primary_operator_contact_info}" if
primary_operator?(@invoice.account.user_entity)
    elsif @invoice.is_floating_invoice?
      pdf.text "#...@invoice.floating_first_name}"
      pdf.text "#...@invoice.floating_last_name}"
      pdf.text "#...@invoice.floating_contact_info}"
    end

  end

  pdf.bounding_box [310, pdf.bounds.height - 10], :width => 300 do
    # Some stuff will go here
  end
end

pdf.bounding_box [0, pdf.cursor ], :width => pdf.bounds.width do
  if !...@invoice.notes.blank?
    pdf.text "Invoice Notes: #...@invoice.notes}"
  end
end

On Jan 28, 11:38 am, Gregory Brown <gregory.t.br...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam  
View profile  
 More options Jan 28, 3:25 pm
From: Sam <sam.pil...@gmail.com>
Date: Wed, 28 Jan 2009 12:25:09 -0800 (PST)
Local: Wed, Jan 28 2009 3:25 pm
Subject: Re: Dynamic Height for Bounding Boxes
Oh wow, that code paste was ugly -- here's a pastie: http://www.pastie.org/373510

-Sam

On Jan 28, 1:22 pm, Sam <sam.pil...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jamis Buck  
View profile  
 More options Jan 28, 3:28 pm
From: Jamis Buck <ja...@37signals.com>
Date: Wed, 28 Jan 2009 13:28:17 -0700
Local: Wed, Jan 28 2009 3:28 pm
Subject: Re: Dynamic Height for Bounding Boxes
If I had to hazard a guess, I'd guess it's because of using
pdf.bounds.height as the y argument, when the outer box has no height,
thus causing all boxes to be positioned at the same y coordinate.

- Jamis

On 1/28/09 1:22 PM, Sam wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gregory Brown  
View profile  
 More options Jan 28, 3:36 pm
From: Gregory Brown <gregory.t.br...@gmail.com>
Date: Wed, 28 Jan 2009 15:36:01 -0500
Local: Wed, Jan 28 2009 3:36 pm
Subject: Re: Dynamic Height for Bounding Boxes

On Wed, Jan 28, 2009 at 3:28 PM, Jamis Buck <ja...@37signals.com> wrote:

> If I had to hazard a guess, I'd guess it's because of using
> pdf.bounds.height as the y argument, when the outer box has no height,
> thus causing all boxes to be positioned at the same y coordinate.

That's right.  It seems like this example reflects the desired behavior.

==================

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

  bounding_box bounds.top_left, :width => 400 do
    bounding_box [0, cursor], :width => 200 do
      text "La la la " * 50
    end

    bounding_box [50, cursor], :width => 250 do
      text "La la la " * 50
    end

    bounding_box [100, cursor], :width => 100 do
      text "la la la " * 50
    end

    text "la la la" * 50
  end

end

`open foo.pdf`

==================

Does that clear anything up, Sam?

--
Technical Blaag at: http://blog.majesticseacreature.com
 Non-tech stuff at: http://metametta.blogspot.com
"Ruby Best Practices"  Book now in O'Reilly Roughcuts:
http://rubybestpractices.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam  
View profile  
 More options Jan 28, 4:00 pm
From: Sam <sam.pil...@gmail.com>
Date: Wed, 28 Jan 2009 13:00:23 -0800 (PST)
Local: Wed, Jan 28 2009 4:00 pm
Subject: Re: Dynamic Height for Bounding Boxes
Geniuses! You're both well deserving of all the praise I've seen
lavished upon you. Thanks for the unbelievably quick support, not to
mention both of your invaluable contributions to the community at
large. Fine examples you set for peons like myself to strive towards.

Much gratitude,
Sam

On Jan 28, 1:36 pm, Gregory Brown <gregory.t.br...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam  
View profile  
 More options Jan 28, 5:14 pm
From: Sam <sam.pil...@gmail.com>
Date: Wed, 28 Jan 2009 14:14:03 -0800 (PST)
Local: Wed, Jan 28 2009 5:14 pm
Subject: Re: Dynamic Height for Bounding Boxes
Hey guys, I'm still having trouble with nested boxes. The trouble
seems to be because the pdf.cursor coordinate in Outer Box 2 has a
value that's snugging it up against the bottom edge of Inner Box 2,
rather than up against the bottom edge of Outer Box 1.

I've got another pastie of some example code with all the instance
variable references removed: http://www.pastie.org/373665

Any ideas?

Thanks again,
Sam

On Jan 28, 2:00 pm, Sam <sam.pil...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gregory Brown  
View profile  
 More options Jan 28, 5:23 pm
From: Gregory Brown <gregory.t.br...@gmail.com>
Date: Wed, 28 Jan 2009 17:23:59 -0500
Local: Wed, Jan 28 2009 5:23 pm
Subject: Re: Dynamic Height for Bounding Boxes

On Wed, Jan 28, 2009 at 5:14 PM, Sam <sam.pil...@gmail.com> wrote:

> Hey guys, I'm still having trouble with nested boxes. The trouble
> seems to be because the pdf.cursor coordinate in Outer Box 2 has a
> value that's snugging it up against the bottom edge of Inner Box 2,
> rather than up against the bottom edge of Outer Box 1.

Wait a second.  You never set the height of Outer Box 1.
So since Inner Box 2 is the bottom box in there, wouldn't you expect
the bottom of Outer Box 1 to equal the bottom of Inner Box 2?

Or are you expecting the cursor to be at the bottom of Inner Box1
because that takes you deeper into the box?  That's not how
bounding_box works without a height.
A cheap trick would be to swap your boxes so the longest one is the
last to be rendered.

That having been said, It looks like your master box, and all of your
outer bounding boxes are not needed.
Maybe try this without nesting first, because all three of those are
equivalent to the margin box.

-greg

--
Technical Blaag at: http://blog.majesticseacreature.com
 Non-tech stuff at: http://metametta.blogspot.com
"Ruby Best Practices"  Book now in O'Reilly Roughcuts:
http://rubybestpractices.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam  
View profile  
 More options Jan 28, 6:15 pm
From: Sam <sam.pil...@gmail.com>
Date: Wed, 28 Jan 2009 15:15:41 -0800 (PST)
Local: Wed, Jan 28 2009 6:15 pm
Subject: Re: Dynamic Height for Bounding Boxes
I suppose I expect Outer Box 1 to stretch in order to accommodate
whichever is the longer of Inner Box 1 and Inner Box 2, and for cursor
to then point to the bottom edge of the whole mess. In the case of the
example it would be Inner Box 1, but in my real life implementation it
could be either of them depending on some conditionals that have been
removed for simplicity's sake.

Inner Box 1 and Inner Box 2 sit side-by-side on the page, and I need
Outer Box 2 to span accross the entire page directly below that (or a
few points below it via a move_down). I guess the layout portion of my
brain is stuck in CSS land, which doesn't apply at all here I realize
- but is there a way to accomplish this kind of layout in order to
accommodate side-by-side bounding box's with dynamic content heights?
Even without the Master and Outer boxes, Inner Boxes 3 & 4 end up
overlapping whichever is the longer of Inner Boxes 1 & 2, in order to
butt up against the bottom edge of the shorter of the two.

Ideas? Thanks for hanging in there with me...
Sam

On Jan 28, 3:23 pm, Gregory Brown <gregory.t.br...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam  
View profile  
 More options Jan 28, 6:16 pm
From: Sam <sam.pil...@gmail.com>
Date: Wed, 28 Jan 2009 15:16:08 -0800 (PST)
Local: Wed, Jan 28 2009 6:16 pm
Subject: Re: Dynamic Height for Bounding Boxes
I suppose I expect Outer Box 1 to stretch in order to accommodate
whichever is the longer of Inner Box 1 and Inner Box 2, and for cursor
to then point to the bottom edge of the whole mess. In the case of the
example it would be Inner Box 1, but in my real life implementation it
could be either of them depending on some conditionals that have been
removed for simplicity's sake.

Inner Box 1 and Inner Box 2 sit side-by-side on the page, and I need
Outer Box 2 to span accross the entire page directly below that (or a
few points below it via a move_down). I guess the layout portion of my
brain is stuck in CSS land, which doesn't apply at all here I realize
- but is there a way to accomplish this kind of layout in order to
accommodate side-by-side bounding box's with dynamic content heights?
Even without the Master and Outer boxes, Inner Boxes 3 & 4 end up
overlapping whichever is the longer of Inner Boxes 1 & 2, in order to
butt up against the bottom edge of the shorter of the two.

Ideas? Thanks for hanging in there with me...
Sam

On Jan 28, 3:23 pm, Gregory Brown <gregory.t.br...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gregory Brown  
View profile  
 More options Jan 28, 6:22 pm
From: Gregory Brown <gregory.t.br...@gmail.com>
Date: Wed, 28 Jan 2009 18:22:29 -0500
Local: Wed, Jan 28 2009 6:22 pm
Subject: Re: Dynamic Height for Bounding Boxes

On Wed, Jan 28, 2009 at 6:15 PM, Sam <sam.pil...@gmail.com> wrote:

> I suppose I expect Outer Box 1 to stretch in order to accommodate
> whichever is the longer of Inner Box 1 and Inner Box 2, and for cursor
> to then point to the bottom edge of the whole mess. In the case of the
> example it would be Inner Box 1, but in my real life implementation it
> could be either of them depending on some conditionals that have been
> removed for simplicity's sake.

I think the biggest problem is that this is not how bounding_box works
currently.  But I don't see anything wrong with changing it.
This would fix your problem, I imagine.

Please file a ticket for this in Lighthouse to remind me.

-greg

--
Technical Blaag at: http://blog.majesticseacreature.com
 Non-tech stuff at: http://metametta.blogspot.com
"Ruby Best Practices"  Book now in O'Reilly Roughcuts:
http://rubybestpractices.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google