Long Chinese sentence can't be wrapped in a table cell

11 views
Skip to first unread message

sun sunjing

unread,
Nov 20, 2009, 5:24:01 AM11/20/09
to prawn...@googlegroups.com
Prawn Team:

Very Thank you for you helps.
I have almost finished generate PDF function.

There is only one problem, Long Chinese sentence can't be wrapped in
a table cell.
you can check it from attachment file, Could you give me some suggestion?

--
phoebe sun
301.pdf

Henrik Nyh

unread,
Nov 20, 2009, 7:43:28 AM11/20/09
to prawn...@googlegroups.com
I'm guessing Chinese sentences have no spaces?

I use this for one Prawn document to enable linebreaks in potentially
long e-mail addresses:

def linebreakable_email
# Turn e.g. 'f...@bar.baz.com' into 'foo<font size="0">
</font>@<font size="0"> </font>bar.baz.com'
# so Prawn line-breaks it correctly.
@customer.email.split(/(@)/).reject(&:blank?).map {|part|
h(part) }.join('<font size="0"> </font>')
end

It requires prawn-format. It (intentionally) doesn't insert any
hyphens. The trick is that it inserts spaces, which Prawn may break on
(Prawn never breaks inside words), but the spaces have no width, so if
it doesn't break the line, you don't see a space.

I'm sure you could do something similar.

Daniel Nelson

unread,
Nov 20, 2009, 9:36:28 AM11/20/09
to prawn...@googlegroups.com
Does the :wrap => :character text option work inside tables?

Best,

Daniel

Gregory Brown

unread,
Nov 20, 2009, 10:18:03 AM11/20/09
to prawn...@googlegroups.com
On Fri, Nov 20, 2009 at 9:36 AM, Daniel Nelson <dnel...@gmail.com> wrote:
> Does the :wrap => :character text option work inside tables?

It should, but right now there's no public API for it, except for:

Document.new(:text_options => { :wrap => :character })

I will add Document#wrap_mode accessor for 0.7, providing it doesn't
break things.

Daniel Nelson

unread,
Nov 20, 2009, 10:37:59 AM11/20/09
to prawn...@googlegroups.com
Hi Greg,

When I saw the :wrap => :character option, I was a bit surprised. Is
there ever a time when we want a solid block of text to extend beyond
the current bounding box? It seems to me that if a "word" is too long
to fit within the bounding box, then Prawn should automatically split
that word by character, the way text editors do. That is what I did in
my oval_text extension.

Best,

Daniel

Gregory Brown

unread,
Nov 20, 2009, 10:42:54 AM11/20/09
to prawn...@googlegroups.com
On Fri, Nov 20, 2009 at 10:37 AM, Daniel Nelson <dnel...@gmail.com> wrote:
> Hi Greg,
>
> When I saw the :wrap => :character option, I was a bit surprised. Is
> there ever a time when we want a solid block of text to extend beyond
> the current bounding box? It seems to me that if a "word" is too long
> to fit within the bounding box, then Prawn should automatically split
> that word by character, the way text editors do. That is what I did in
> my oval_text extension.

Interesting point. You can patch it, sure. (for 0.7, of course)

Brad Ediger

unread,
Nov 20, 2009, 10:56:43 AM11/20/09
to prawn...@googlegroups.com
Hard wrapping is one way, but the other alternative is that we bring
in hyphenation support. It would be highly language-specific (and
wouldn't help sun's problem), but it would be a nice feature for us to
have. I've been meaning to look into it, so I'll put it on my wish
list.

Brad

Daniel Nelson

unread,
Nov 20, 2009, 11:05:51 AM11/20/09
to prawn...@googlegroups.com
> Interesting point.   You can patch it, sure.  (for 0.7, of course)

Okay. I'll put that on my list.

Best,

Daniel

Gregory Brown

unread,
Nov 20, 2009, 11:00:39 AM11/20/09
to prawn...@googlegroups.com
On Fri, Nov 20, 2009 at 10:56 AM, Brad Ediger <br...@bradediger.com> wrote:

> Hard wrapping is one way, but the other alternative is that we bring
> in hyphenation support. It would be highly language-specific (and
> wouldn't help sun's problem), but it would be a nice feature for us to
> have. I've been meaning to look into it, so I'll put it on my wish
> list.

Doing TeX optimal wrap is something we've always wanted to support,
but it seems to have been a pipe dream for most who have attempted it.
I'd be happy to support it so long as it could be swapped out for
something language independent by an option.

-greg

Wojciech Piekutowski

unread,
Nov 20, 2009, 12:49:24 PM11/20/09
to prawn...@googlegroups.com
2009/11/20 Brad Ediger <br...@bradediger.com>:
That would be cool. Even better if it would be possible to plug-in
your own hyphenator. Something like Prawn.hyphenator =
MySuperHyphenator.new. Then people could write various implementations
- from basic ones like 'by whitespace' (built-in), to the ones
specific for different languages or based on libhyphen (probably as
separate gems).

Wojtek

> You received this message because you are subscribed to the Google Groups "Prawn" group.
> To post to this group, send email to prawn...@googlegroups.com.
> To unsubscribe from this group, send email to prawn-ruby+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/prawn-ruby?hl=.
>
>
>

Gregory Brown

unread,
Nov 20, 2009, 12:55:57 PM11/20/09
to prawn...@googlegroups.com
On Fri, Nov 20, 2009 at 12:49 PM, Wojciech Piekutowski
<w.piek...@gmail.com> wrote:

> That would be cool. Even better if it would be possible to plug-in
> your own hyphenator. Something like Prawn.hyphenator =
> MySuperHyphenator.new. Then people could write various implementations
> - from basic ones like 'by whitespace' (built-in), to the ones
> specific for different languages or based on libhyphen (probably as
> separate gems).

Well, speaking more generally, we'd be plugging in our own wrap modes.

I'm definitely considering allowing wrap_mode to accept a block
passing the same params our code takes.
This would allow for

Prawn::Document.wrap_mode { |*a| my_wrapper(*a) }

atotic

unread,
Dec 7, 2009, 7:35:14 PM12/7/09
to Prawn
On Nov 20, 9:55 am, Gregory Brown <gregory.t.br...@gmail.com> wrote:
> On Fri, Nov 20, 2009 at 12:49 PM, Wojciech Piekutowski
>
> Well, speaking more generally, we'd be plugging in our ownwrapmodes.
>
> I'm definitely considering allowing wrap_mode to accept a block
> passing the same params our code takes.
> This would allow for
>
> Prawn::Document.wrap_mode { |*a| my_wrapper(*a) }

+1 on this. I just ran into a chinese wrapping issue, and this would
allow me
to fix it without hacking the main code.

On the other hand, you do want the default wrap to work for majority
of the users.
In the ideal world, maybe an implementation of unicode word-break
algorithm
for unicode fonts http://unicode.org/reports/tr14/

Aleks

Daniel Nelson

unread,
Dec 7, 2009, 10:37:13 PM12/7/09
to prawn...@googlegroups.com
What was your wrapping issue?

The text wrapping slated for the 0.7 release combines word and
character wrapping. It does away with the :wrap => :character option
because the default wrapping now handles it, but it does accept a
:wrap_block option. See the code for details.

-Daniel
Reply all
Reply to author
Forward
0 new messages