Feedback

13 views
Skip to first unread message

Jonathan Viney

unread,
Aug 28, 2008, 8:57:34 PM8/28/08
to prawn...@googlegroups.com
Hi,

I've just embarked on developing a report with prawn. I've attached a screenshot, and the code is here: http://pastie.org/262216

My questions are:

1. Is there a better way to get the background colour behind the text? My approach of determining the text height, drawing a polygon, moving the document, and the writing the text seems quite involved.

2. Drawing a border around the item doesn't seem to work correctly. The top border line is below the heading, instead of above. Also, calculating the correct bottom position for the border is not totally straightforward, having to look at the height of the image and details sections and move the document down if necessary.

The other thing I noticed is that tables in bounding boxes without specified heights display one row on every page.

Thanks, it seems like Prawn is making good progress!
-Jonathan.
Screenshot-items.pdf.png

Gregory Brown

unread,
Aug 28, 2008, 10:18:31 PM8/28/08
to prawn...@googlegroups.com
On Thu, Aug 28, 2008 at 8:57 PM, Jonathan Viney
<jonatha...@gmail.com> wrote:
> Hi,
>
> I've just embarked on developing a report with prawn. I've attached a
> screenshot, and the code is here: http://pastie.org/262216
>
> My questions are:
>
> 1. Is there a better way to get the background colour behind the text? My
> approach of determining the text height, drawing a polygon, moving the
> document, and the writing the text seems quite involved.

That +is+ involved... You should be able to use a cell for this,
specifying only a point and a width at a minimum, but it appears like
this is broken in stable. :-/
I'll look into it and see what I can do.

> 2. Drawing a border around the item doesn't seem to work correctly. The top
> border line is below the heading, instead of above.

Are you assuming y=0 is at the top of your document? It isn't.
Are you assuming a rectangle is specified by the bottom left corner? It isn't.

> Also, calculating the
> correct bottom position for the border is not totally straightforward,
> having to look at the height of the image and details sections and move the
> document down if necessary.

This, I feel isn't too bad:

Prawn::Document.generate("border.pdf") do
bounding_box([100,500], :width => 300) do
text "Foo "*100
stroke_rectangle bounds.top_left, bounds.width, bounds.height
end
end

Just remember to manually set the bounding box height, or do your
rectangle drawing *last*

> The other thing I noticed is that tables in bounding boxes without specified
> heights display one row on every page.

Can you produce a simple example and file a defect ticket in
Lighthouse for this? Thanks.

-greg


--
Technical Blaag at: http://blog.majesticseacreature.com | Non-tech
stuff at: http://metametta.blogspot.com

Gregory Brown

unread,
Aug 28, 2008, 10:22:35 PM8/28/08
to prawn...@googlegroups.com
On Thu, Aug 28, 2008 at 10:18 PM, Gregory Brown
<gregory...@gmail.com> wrote:
> On Thu, Aug 28, 2008 at 8:57 PM, Jonathan Viney
> <jonatha...@gmail.com> wrote:
>> Hi,
>>
>> I've just embarked on developing a report with prawn. I've attached a
>> screenshot, and the code is here: http://pastie.org/262216
>>
>> My questions are:
>>
>> 1. Is there a better way to get the background colour behind the text? My
>> approach of determining the text height, drawing a polygon, moving the
>> document, and the writing the text seems quite involved.
>
> That +is+ involved... You should be able to use a cell for this,
> specifying only a point and a width at a minimum, but it appears like
> this is broken in stable. :-/
> I'll look into it and see what I can do.
>
>> 2. Drawing a border around the item doesn't seem to work correctly. The top
>> border line is below the heading, instead of above.
>
> Are you assuming y=0 is at the top of your document? It isn't.
> Are you assuming a rectangle is specified by the bottom left corner? It isn't.

Oh, I see your code now, missed that originally. The answer is that
bounds.top is always going to be the y in bounding_box [x,y], opts
You put your header outside of your bounding box, so you'd actually need:

# Why doesn't pdf.bounds.top include the header section?
pdf.stroke_rectangle [0, pdf.bounds.top + header_height],
item_width, pdf.bounds.height + header_height

I feel like it'd be a little weird to stretch the box as you move
upwards as well as when you move down...

Jonathan Viney

unread,
Sep 1, 2008, 9:18:10 AM9/1/08
to prawn...@googlegroups.com
Can you produce a simple example and file a defect ticket in
Lighthouse for this?  Thanks.
Reply all
Reply to author
Forward
0 new messages