英文:
Java XSL-FO hyphenation in PDF formatting
问题
我有一个生成XML文件并将其渲染为PDF的Java程序。问题是,我似乎无法使连字符化起作用。
我已经简要阅读了https://www.w3.org/TR/xsl/#d0e26492,但我仍然不明白为什么无法使文本连字符化。我尝试在几乎所有块中插入了 hyphenate="true"
,但诸如“AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...”之类的字符串仍然超出了边界。我也尝试设置 language
和 locale
,但我真的不在乎连字符化发生在哪里,任何地方都可以。
英文:
I have a Java program that generates an XML file, which is rendered in to a PDF. The problem is that I can't seem to get the hyphenation to work.
I've read trough https://www.w3.org/TR/xsl/#d0e26492 briefly but I still don't understand why I can't get my text to hyphenate. I've tried inserting hyphenate="true"
in nearly all blocks but strings such as "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..." still go out of bounds. I've tried to set language
and locale
too but I don't really care where the hyphenation happens, anywhere would be fine.
答案1
得分: 4
连字通常基于连字词典和/或能够匹配已知字母序列并仅在允许的位置断开单词的算法。不同的语言有不同的连字约定,即使是美式英语和英式英语也存在差异。
像“AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...”这样的字符串不太可能在连字词典中找到匹配项,因此实现不知道在何处断开这个“单词”。
您可能想要类似于一些在分割表格单元格中的文本的解决方案;例如:
- https://stackoverflow.com/questions/4350788/xsl-fo-force-wrap-on-table-entries/33689540#33689540
- https://stackoverflow.com/questions/17317588/wrap-within-table-cell-with-long-word-in-fop
英文:
Hyphenation is usually based on a hyphenation dictionary and/or an algorithm that matches known sequences of letters and breaks words only where it is allowed. Different languages have different hyphenation conventions, and even US English and British English have differences.
Strings like "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..." are unlikely to match anything in a hyphenation dictionary, so the implementation doesn't know where to break the "word".
You probably want something like some of the solutions proposed for breaking text in table cells; for example:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论