Java中的XSL-FO连字符在PDF格式化中的应用

huangapple go评论79阅读模式
英文:

Java XSL-FO hyphenation in PDF formatting

问题

我有一个生成XML文件并将其渲染为PDF的Java程序。问题是,我似乎无法使连字符化起作用。

我已经简要阅读了https://www.w3.org/TR/xsl/#d0e26492,但我仍然不明白为什么无法使文本连字符化。我尝试在几乎所有块中插入了 hyphenate="true",但诸如“AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...”之类的字符串仍然超出了边界。我也尝试设置 languagelocale,但我真的不在乎连字符化发生在哪里,任何地方都可以。

英文:

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...”这样的字符串不太可能在连字词典中找到匹配项,因此实现不知道在何处断开这个“单词”。

您可能想要类似于一些在分割表格单元格中的文本的解决方案;例如:

英文:

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:

huangapple
  • 本文由 发表于 2020年8月27日 19:06:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63614687.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定