Forum How do I...?

Margin problems with Japanese text

Bjarne
Hi,

I'm trying to render a manual both in English and Japanese and have problem with the rightmost margin in the Japanese version - or maybe better said, the lack of margin - the text just flows over the page boundaries! Is that due to lack of white space characters, so Prince has problem to decide where to break the line, or? and if so, how can it be published with a nice layout?

///Bjarne
mikeday
Hi Bjarne,

The problem is caused by the lack of whitespace characters. Currently, Prince will not break an unbroken string of text across multiple lines, so you need to add explicit whitespace. This can include invisible whitespace, such as the ZERO WIDTH SPACE character (U+200B), which can be included using the character entity ​

In the future, we will extend Prince to be aware of the line-breaking behaviour needed for Japanese and Chinese text so that explicit whitespace is not required.

Best regards,

Michael
Bjarne
Hi Michael,

and thanks for the answer - now I at least know what the behaviour comes from!

It's also great to hear that you intend to develop Prince to handle such cases.
However, I need to get the manual generated shortly, and there is quite a lot of text, so it will be a hard work to get these whitespaces put into the right places - especially when the language is not so familar.

Are the any other work-arounds available?

Kind regards,
Bjarne
mikeday
Hi Bjarne,

The easy solution would be to add a zero-width space character after every Japanese character in the document, like this:
<!-- before -->
<p>Hello</p>

<!-- after -->
<p>H&#x200B;e&#x200B;l&#x200B;l&#x200B;o&#x200B;</p>

(assuming that "Hello" is Japanese text). It would be relatively straightforward to write a script of some kind to perform this task.

However, I don't know whether or not this would meet your requirements; is it okay to break lines anywhere in the Japanese text, or should certain sequences be kept unbroken? Such sequences would need to be identified with some markup so that no zero-width space characters would be added to them.

If this sounds like a workable solution, then perhaps I can help put together an XSLT transform or script to do this.

Best regards,

Michael
James Evans
You can also use regular spaces between the Chinese or Japanese characters as long as you put the characters in a separate tag (like <lang>). Then in your css file you need to assign the letter-spacing property for that tag as something like -2.5px.

Your xml would look something like this :
<lang>你 好!我 是</lang> James.

Your css would look something like this:
lang
{
font-family:"Arial Unicode MS";
display:inline;
letter-spacing:-2.5px;
}
mikeday
Today we have released Prince 6.0 rev 4, which includes support for line-breaking between Chinese, Japanese and Korean characters.