将希腊字母放入java中的rtf编辑器内容中,显示问号
Putting Greek letters into rtf editor content in java, showing question marks
我正在使用 rtf 编辑器向用户显示内容。内容是使用有时由希腊字母组成的数据库值组成的。
最初它们显示为问号 ? ? ? ?
而不是 Γ γ Ψ ψ
。
在线研究后将 CONTENT.getBytes();
更改为 CONTENT.getBytes("UTF8");
将这些内容写入响应对象时使用 bytearraystream
作为 response.getOutPutStream
来自 CONTENTS 并使用 JavaScript
显示
document.myobj.HttpOpenFileFromStream(contents passed through earlier in response)
任何正常的文本内容在编辑器中都可以正常显示,但如果有希腊字母,例如 Γ γ Ψ ψ
,那么在编辑器中它们将显示为 Γ γ Ψ ψ
。
为了仔细检查,我在放入 html 页面之前打印了内容,它显示了所需的字符 Γ γ Ψ ψ
,但是当这些字符显示在 RTF 编辑器的 UI 中时,它们变成了 Γ γ Ψ ψ
。有人可以帮我弄这个吗?
提前致谢。
RTF 不是这样工作的。 RTF 文件只能包含 7 位 ASCII 字符(这是名称的 T[ext] 部分的一部分),但它们可以通过两种 text-based 编码之一表示其他字符。 The Wikipedia article on RTF 提供详细信息:
The character escapes are of two types: code page escapes and, starting with RTF 1.5, Unicode escapes. [...] For a Unicode escape the control word \u is used, followed by a 16-bit signed decimal integer giving the Unicode UTF-16 code unit number. For the benefit of programs without Unicode support, this must be followed by the nearest representation of this character in the specified code page. For example, \u1576? would give the Arabic letter bāʼ ب, specifying that older programs which do not have Unicode support should render it as a question mark instead.
因此,字符 Γ γ ψ ψ 的一种正确的 RTF 编码是:
\u915? \u947? \u936? \u968?
当然,任何特定的 RTF 软件 是否正确处理此类转义序列是一个完全不同的问题。
谢谢@John。它有效 这是我的代码。
if (ascii <= 128)
{
copyBuffer.append(ch);
}
else
{
copyBuffer.append("\u"+ascii+"?");
}
我正在使用 rtf 编辑器向用户显示内容。内容是使用有时由希腊字母组成的数据库值组成的。
最初它们显示为问号 ? ? ? ?
而不是 Γ γ Ψ ψ
。
在线研究后将 CONTENT.getBytes();
更改为 CONTENT.getBytes("UTF8");
将这些内容写入响应对象时使用 bytearraystream
作为 response.getOutPutStream
来自 CONTENTS 并使用 JavaScript
document.myobj.HttpOpenFileFromStream(contents passed through earlier in response)
任何正常的文本内容在编辑器中都可以正常显示,但如果有希腊字母,例如 Γ γ Ψ ψ
,那么在编辑器中它们将显示为 Γ γ Ψ ψ
。
为了仔细检查,我在放入 html 页面之前打印了内容,它显示了所需的字符 Γ γ Ψ ψ
,但是当这些字符显示在 RTF 编辑器的 UI 中时,它们变成了 Γ γ Ψ ψ
。有人可以帮我弄这个吗?
提前致谢。
RTF 不是这样工作的。 RTF 文件只能包含 7 位 ASCII 字符(这是名称的 T[ext] 部分的一部分),但它们可以通过两种 text-based 编码之一表示其他字符。 The Wikipedia article on RTF 提供详细信息:
The character escapes are of two types: code page escapes and, starting with RTF 1.5, Unicode escapes. [...] For a Unicode escape the control word \u is used, followed by a 16-bit signed decimal integer giving the Unicode UTF-16 code unit number. For the benefit of programs without Unicode support, this must be followed by the nearest representation of this character in the specified code page. For example, \u1576? would give the Arabic letter bāʼ ب, specifying that older programs which do not have Unicode support should render it as a question mark instead.
因此,字符 Γ γ ψ ψ 的一种正确的 RTF 编码是:
\u915? \u947? \u936? \u968?
当然,任何特定的 RTF 软件 是否正确处理此类转义序列是一个完全不同的问题。
谢谢@John。它有效 这是我的代码。
if (ascii <= 128)
{
copyBuffer.append(ch);
}
else
{
copyBuffer.append("\u"+ascii+"?");
}