如何用unicode图像替换字符? [英] How can I replace a character with an unicode image?
问题描述
如何将文本中的 - 字符替换为带有图像的数据库中的jasper字段?目标如下图所示:
How can I replace a - character in a text which comes from a data base into jasper field, with an image? The goal is as the illustration bellow:
类似于: $ F {KN_Zusatzinfo_DV_Einleitungstext} .replaceAll( - ,[\\ x254])
其中 x254
是红色正方形的ascii代码。
Something like: $F{KN_Zusatzinfo_DV_Einleitungstext}.replaceAll("- ", "[\\x254]")
where the x254
is ascii code for a red square.
但是上面的代码在文本中写了ascii代码并且没有生成图像。
But the above code writes the ascii code as is in the text and does not produce the image.
推荐答案
呈现unicode符号的正确语法是 \ uXXXX
The correct syntax to render a unicode symbol is \uXXXX
例如,这个表达式:
$F{listItem}.replaceAll("-", "\u2588")
渲染这个
现在你喜欢点为红色所以我们需要应用一些样式,让我们设置在 textElement
上 markup =html
并将替换更改为此
Now you like the dot to be red so we need to apply some style, lets set markup="html"
on textElement
and change the replace to this
$F{listItem}.replaceAll("-", "<font color=\"red\">\u2588</font>")
它将呈现:
注意:在
replaceAll
中需要注意正则表达式,我可能会
^ -
,因此以-
开头(以避免替换其他<$ c) $ c> - in text),
此外,通常的方法是在每行
上添加一个红色矩形元素。如果要导出到
pdf,也要处理字体扩展,以便正确呈现字体
Note: You need to be careful with regex in
replaceAll
, I probably would us^-
, hence starts with-
(to avoid replacing other-
in text), furthermore the normal way would be to just add a red rectangle element on each row. Also take care of font-extensions if you are exporting to pdf, so that your font is render correctly
这篇关于如何用unicode图像替换字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!