本文介绍了XSL-FO:在表单元格中包装长字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Docbook-XSL和Apache FOP生成包含表的PDF文档.使用默认设置,表具有固定宽度的列,并且在单词边界处换行.但是,如果单词长于单元格宽度,则会使单元格溢出.在这种情况下,我想将单词分成多行.该怎么办?

I'm using Docbook-XSL and Apache FOP to generate PDF documents containing tables. With the default settings, tables have fixed-width columns and lines wrap at word boundaries. But if a word is longer than the cell width, it overflows the cell. I'd like to break up the words across multiple lines in such a case. How could this be done?

连字符不是解决方案,因为单词不必是英语. (其他语言中的连字符也不是解决方案.可能无法提前知道数据所用的语言,并且可能存在无法连字符的单词",例如数字字符串.)

Hyphenation is not a solution since the words need not be in English. ( hyphenation in other languages is not a solution either. It may not be known ahead of time what language the data is in, and there may be "words" that cannot be hyphenated, such as numeric strings.)

我发现了将keep-together.within-column="always"用于fo:table-row的建议,但这似乎没有任何作用.

I found suggestions to use keep-together.within-column="always" for fo:table-rows, but that didn't seem to have any effect.

()另一个建议是在所有字符之间插入零宽度的空格.但这也打断了单词中间词.我需要一个尽可能在单词边界处中断的解决方案,并且仅在需要时才在单词中中断.

() Another suggestion was to insert zero-width spaces between all characters. But this also breaks short words mid-word. I would need a solution that breaks at word boundaries whenever possible, and mid-word only when needed.

推荐答案

FOP几乎与每个FO处理器一样,都可以断字除英语以外的其他语言.参见 http://xmlgraphics.apache.org/fop/2.1/hyphenation.html

FOP, like just about every FO processor, can hyphenate languages other than English. See http://xmlgraphics.apache.org/fop/2.1/hyphenation.html

您可以尝试使用FO处理器,例如Antenna House AH Formatter,该处理器可实现自动"表格布局,并可以根据文本可能会中断的位置来调整表格列的宽度(以及对多种语言进行连字处理) ).

You could try using an FO processor, such as Antenna House AH Formatter, that implements 'auto' table layout and can adjust the widths of the table columns depending on where the text can break (as well as do hyphenation for multiple languages).

其他在表格单元格中打破文本的答案是:

Other answers for breaking text in table cells are at:

这篇关于XSL-FO:在表单元格中包装长字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!