Whats the easiest way to fix wrapping issue in chinese on trunk version?

56 views
Skip to first unread message

goodwill

unread,
Aug 14, 2010, 3:52:44 AM8/14/10
to Prawn
Basically its for all CJK character which each character has to be
wrapped if they are not english words, tried:

pdf=Prawn::Document.new(:page_size=>'A4', :margin=>[30,30,20,30], :wrap=>:character)

with no luck, the wrap doesn't seems to change at all.

Also ideally wrapping can be controlled by bounding box as we have
chinese and english passages mixed within the same document.

Daniel Nelson

unread,
Aug 14, 2010, 9:35:28 AM8/14/10
to prawn...@googlegroups.com
> Basically its for all CJK character which each character has to be
> wrapped if they are not english words, tried:
>
> pdf=Prawn::Document.new(:page_size=>'A4', :margin=>[30,30,20,30], :wrap=>:character)

What version of Prawn are you using? The :wrap => :character option
was removed a long time ago (late 2009, if I recall correctly). See
examples/m17n/chinese_text_wrapping.rb for an example that includes
wrapping Chinese text.

Kind Regards,

Daniel

goodwill

unread,
Aug 14, 2010, 9:55:11 AM8/14/10
to Prawn
ic so I am confused with the docs. Anyway, I looked at the example-
doesn't seems to work for me coz I actually do have spaces within
(think about mixing chinese and english) then prawn just use the space
instead of trying to put line break between those chinese character.

For example:

- 更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历您的DB中的内容,写个小爬虫把你的页面上的关键信息顺次爬下来也
which I expect:

- 更可怕的是,同质化竞争对手可以按照URL
中后面这个ID来遍历您的DB中的内容,写个
小爬虫把你的页面上的关键信息顺次爬下来也

What actually happen:
-
更可怕的是,同质化竞争对手可以按照URL中
后面这个ID来遍历您的DB中的内容,写个小
爬虫把你的页面上的关键信息顺次爬下来也

Would be great if you have some idea on how to fix this.

Daniel Nelson

unread,
Aug 14, 2010, 11:29:05 AM8/14/10
to prawn...@googlegroups.com
> ic so I am confused with the docs. Anyway, I looked at the example-
> doesn't seems to work for me coz I actually do have spaces within
> (think about mixing chinese and english) then prawn just use the space
> instead of trying to put line break between those chinese character.

If you don't want to break on spaces, use a non-breaking space (or,
for your convenience, Prawn::Text::NBSP).

Kind Regards,

Daniel

goodwill

unread,
Aug 15, 2010, 5:37:38 AM8/15/10
to Prawn
Works like a charm! Thanks for that :)

Yeung William

unread,
Aug 23, 2010, 11:40:46 PM8/23/10
to prawn...@googlegroups.com
Hmm... after more testing I think this approach is not a very good one regarding fixing the bad line break with chinese + english characters. The logic should be instead of introducing non-breaking space, the wrapper should know wrapping is always allowed between chinese characters. In the past there are many browsers have similar problem, the solution we had is insert spaces between all chinese characters.

Gregory Brown

unread,
Aug 24, 2010, 12:19:54 AM8/24/10
to prawn...@googlegroups.com
On 8/23/10 11:40 PM, Yeung William wrote:
> Hmm... after more testing I think this approach is not a very good
> one
regarding fixing the bad line break with chinese + english characters.
The logic should be instead of introducing non-breaking space, the
wrapper should know wrapping is always allowed between chinese
characters. In the past there are many browsers have similar problem,
the solution we had is insert spaces between all chinese characters.

But this knowledge requires specific localized knowledge of the
language, if we continue to special case this way, things will get very
complex. If you want this functionality, please create a wrapping
module for Chinese and release it independently. We have made our text
wrapping easy to extend for this reason.

-greg

Yeung William

unread,
Aug 24, 2010, 12:27:55 AM8/24/10
to prawn...@googlegroups.com
Hi Greg,

Yep I digg this- can give some example on how to extend the wrapping? I kinda confused when I read the code there- there seems to have a few classes involved, from the linewrap to some of the wrapping methods inside formatted and normal text box.

Daniel Nelson

unread,
Aug 24, 2010, 12:54:16 AM8/24/10
to prawn...@googlegroups.com
> Yep I digg this- can give some example on how to extend the wrapping? I kinda confused when I read the code there- there seems to have a few classes involved, from the linewrap to some of the wrapping methods inside formatted and normal text box.

Check out Prawn::Text::Box#extensions. The API documentation shows how
to override wrapping. See the API documentation for
Prawn::Core::Text::Wrap#wrap for details of what the overriding #wrap
method needs to do.

- Daniel

Reply all
Reply to author
Forward
0 new messages