JasperReports:防止textField在空格或连字符上拆分 [英] JasperReports: Prevent textField to split on space or hyphen

查看:57
本文介绍了JasperReports:防止textField在空格或连字符上拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JasperReports模板,其中包含一个textField元素,该元素将包含可变长度的字符串.如果字符串太长而无法适合宽度,则将其拆分,除非字符串包含连字符或空格字符,否则可以进行拆分.在这种情况下,字符串将从该char拆分.以下是一些输入,观察到的结果以及想要的结果和摘要的示例,使我的观点更容易理解.

I have a JasperReports template that contains a textField element that will contain a variable length of strings. If the string is too long to fit the width, it'll be split which is fine except when the string contains a hyphen or a space char. In this case the string is split from that char. Below are some example of what's the input, observed outcome and wanted outcome + summary to make my point easier to understand.

input      observed   wanted   summary
_____________________________________
overflow  -> overfl -> overfl : OK
over flow -> over   -> over f : NOT OK
over-flow -> over-  -> over-f : NOT OK

将reportElement设置为具有isStretchWithOverflow ="true"属性会将文本分为两行,但这不是我们想要的行为.

Setting the reportElement to have isStretchWithOverflow="true" attribute will split the text on two lines, but this is not wanted behaviour.

反正有解决此问题的方法吗?

Is there anyway to fix this?

谢谢.

编辑:输入数据来自外部来源,因此我无法直接更改它.我进行了一些测试,发现使用不间断的空格将对空格有效.另一方面,不打断连字符根本不会打印,即文本"over-flow"变成"overflow".不太想要什么.

EDIT: The input data comes from an external source, so I cannot directly change that. I ran some tests and noticed that using non-breaking space will do for spaces. non-breaking hyphen on the other hand is not printed at all, i.e. text 'over-flow' becomes 'overflow'. Not quite what is wanted.

尽管输入源不在我的控制范围内,但我可以编写一个Scriptlet来解决此问题,该脚本必须将空格改为不间断的连字符,并将连字符改为不间断的连字符,只有打印出那些令人讨厌的连字符为止

Despite the input source not in my control, I could fix this problem by writing a Scriptlet that'll change spaces to non-breaking spaces and hyphens to non-breaking hyphens, only if those darn non-breaking hyphens would be printed.

通过打印为PDF的方式,以防出现问题.

Printing to PDF by the way, in case that gives some hints of the problem.

推荐答案

这是字体问题.如果字体支持连字符,连字符也可以正常工作(\ u2011).有关如何加载默认字体(例如,DejaVu Sans)的信息,请参见字体示例.

It's a font issue. Non-breaking hyphen works(\u2011) fine, when the font supports it. See fonts sample on how load other than the default font (DejaVu Sans for example).

如果有人比Scriptlet拥有更好的输入源修改选项,请告诉我.

If anyone has a better option for the input source modification than the Scriptlet, please let me know.

(将我自己的答案标记为正确,以便结束本主题.)

(Marking my own answer as correct in order to get this topic closed.)

必须等待两天才能将该答案标记为正确.

Have to wait for two days in order to mark this answer correct.

这篇关于JasperReports:防止textField在空格或连字符上拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆