bounding box without overflow to next page and ellipses for long text lines without spaces

147 views
Skip to first unread message

nico

unread,
Aug 14, 2009, 4:30:43 AM8/14/09
to Prawn
Is it possible to have a bounding box that doesn't overflow text to
the next page when it doesn't
fit in the box? We need to implement that behaviour somehow, to avoid
our layout beeing
totally messed.

Also we need to have long text lines without spaces to be shortened
with an ellipses,
in the same way text_box does with :overflow => :ellipses when the
line includes spaces.
The problem is that e.g. long filenames simply overflow the bounding
box on the right when they don't fit.

Any help on this?

Nico

Gregory Brown

unread,
Aug 14, 2009, 6:52:46 AM8/14/09
to prawn...@googlegroups.com
On Fri, Aug 14, 2009 at 4:30 AM, nico<nico.r...@googlemail.com> wrote:

> Also we need to have long text lines without spaces to be shortened
> with an ellipses,
> in the same way text_box does with :overflow => :ellipses when the
> line includes spaces.
> The problem is that e.g. long filenames simply overflow the bounding
> box on the right when they don't fit.
>
> Any help on this?

This issue with text_box sounds like a bug. Please file an issue on github.

There is no way to prevent a bounding box from advancing to the next
page. If you show me an example of what you're trying to do, there
might be other ways around it.

nico

unread,
Aug 14, 2009, 3:52:31 PM8/14/09
to Prawn
Thanks for your answer Gregory.

> This issue with text_box sounds like a bug. Please file an issue on github.

You mean its a bug that a line with long text without spaces overflows
out of the sourrounding bounding box?
That seems to me normal behaviour. But not wanted... :) We'd like to
have the line simply be shortened with an
ellipses the same way text with spaces is shortened when puting it in
a text_box.

> There is no way to prevent a bounding box from advancing to the next
> page. If you show me an example of what you're trying to do, there
> might be other ways around it.

Well, we have a fixed layout on each page of the pdf with various
boxes that should simply not expand (or overflow to the next page)
but should hide any vertically overflowing text, possibly also shorten
it with an ellipses.

Nico

Gregory Brown

unread,
Aug 14, 2009, 3:56:30 PM8/14/09
to prawn...@googlegroups.com
On Fri, Aug 14, 2009 at 3:52 PM, nico<nico.r...@googlemail.com> wrote:
>
> Thanks for your answer Gregory.
>
>> This issue with text_box sounds like a bug.  Please file an issue on github.
>
> You mean its a bug that a line with long text without spaces overflows
> out of the sourrounding bounding box?
> That seems to me normal behaviour. But not wanted... :) We'd like to
> have the line simply be shortened with an
> ellipses the same way text with spaces is shortened when puting it in
> a text_box.

for this, I think that it should just truncate by the last 3 chars,
not worrying about complete words.
Maybe I'm misunderstanding your problem though. Please give me an
example that reproduces the problem.

>> There is no way to prevent a bounding box from advancing to the next
>> page.  If you show me an example of what you're trying to do, there
>> might be other ways around it.
>
> Well, we have a fixed layout on each page of the pdf with various
> boxes that should simply not expand (or overflow to the next page)
> but should hide any vertically overflowing text, possibly also shorten
> it with an ellipses.

Well, this is what text_box is for. Is there a reason why it's not
doing what you need? (Beside the above mentioned bug)

nico

unread,
Aug 15, 2009, 1:47:22 AM8/15/09
to Prawn
> Well, this is what text_box is for. Is there a reason why it's not
> doing what you need? (Beside the above mentioned bug)

We can't really use a text_box, for 2 reasons: First we can't format
text differently, all text in the same text_box will have the same
formatting (right?).
If text_box would take a block, then we could use it, like

text_box :overflow => :ellipses do
pdf.text first_line
pdf.text second_line, :style => :bold
...
end

Secondly text_box seems to have a margin/padding we can't get rid of.

> for this, I think that it should just truncate by the last 3 chars,
> not worrying about complete words.
> Maybe I'm misunderstanding your problem though. Please give me an
> example that reproduces the problem.

Okay, here is an example:

pdf.bounding_box([100,100], :height => 100, :width =>200) do
pdf.text
"verylongtextthatdoesnthaveanyspacestomakeitreadable" #
overflows
pdf.text_box
"verylongtextthatdoesnthaveanyspacestomakeitreadable", # disappears
:height => pdf.font.height, :overflow => :ellipses
pdf.text_box "very long text that does have spaces to make it
readable", # correctly truncated with ellipses
:height => pdf.font.height, :overflow => :ellipses
end

The output is this:

verylongtextthatdoesnthaveanyspacestomakeitreadable

very long text that does have spac...

But what we like is to have the first line also truncate, like

verylongtextthatdoesnthaveanysp...

Nico

nico

unread,
Aug 25, 2009, 3:31:49 AM8/25/09
to Prawn
Any help on this? Thanks!

nico

unread,
Sep 2, 2009, 3:27:14 AM9/2/09
to Prawn
Hello! Anybody here who might be able to help on this?

Thanks,
Nico

runs_with_kona

unread,
Sep 3, 2009, 11:04:11 PM9/3/09
to Prawn
You could use two text_box(es) to change the font or style. I don't
have a solution for doing inline, though.

I dealt with the margin/padding by using a rectangle as the border and
placing a borderless text_box within the rectangle.

I hope this helps.
Reply all
Reply to author
Forward
0 new messages