简体   繁体   English

Java:Linux上的字体看起来很乱,但在Windows上很好

[英]Java: Fonts look garbled on Linux, but fine on windows

I'm writing a java application that renders PDF documents to images, and when I run it on windows it works fine. 我正在编写一个将PDF文档呈现给图像的java应用程序,当我在Windows上运行它时,它运行正常。 But when I render the PDF on Linux, the standard fonts look a bit garbled, like there would be a few pixels missing on the right side of some characters. 但是当我在Linux上渲染PDF时,标准字体看起来有点乱,就像在某些字符的右侧会丢失一些像素。

I only tested it on a fresh install of Ubuntu 9.04 with OpenJDK 6, but I'm quite sure I have seen similar issues before on Linux. 我只是在安装了OpenJDK 6的Ubuntu 9.04上进行了测试,但我确信我之前在Linux上遇到过类似的问题。 I also tried to open the PDF with other Java PDF applications, like the SwingLabs PDFRenderer and the IcePDF Demo Applet, and they had the same problem. 我还试图用其他Java PDF应用程序打开PDF,比如SwingLabs PDFRenderer和IcePDF Demo Applet,他们遇到了同样的问题。 On windows they all render the document just fine. 在Windows上,它们都可以很好地渲染文档。 I also opened the document on the same Ubuntu machine with the default PDF viewer, evince. 我还使用默认的PDF查看器evince在同一台Ubuntu机器上打开文档。 Evince rendered the document without the font issue, so I'm quite sure this is a general Java + Linux problem. Evince渲染文档没有字体问题,所以我很确定这是一个普遍的Java + Linux问题。

For comparison: 为了比较:
This image was rendered on Windows. 此图像在Windows上呈现。
This image was rendered on Linux. 此图像在Linux上呈现。 I marked a few garbled characters with red rings. 我用红色圆环标记了一些乱码。
This one was also rendered on Linux. 这个也在Linux上呈现。 It looks like only standard fonts are affected. 看起来只有标准字体会受到影响。

Any help is appreciated. 任何帮助表示赞赏。

OpenJDK has to put out fonts which are copyright protected. OpenJDK必须推出受版权保护的字体。 Install Sun's Java and fonts will be somehwat better. 安装Sun的Java和字体会更好。

I have OpenJDK installed in Linux and all apps were with very, very bad fonts... after many tries to change fonts, antialias, installing Lucida fonts, etc. I found that my problem was in the /etc/fonts/conf.d/35-freefont.conf . 我在Linux中安装了OpenJDK,并且所有应用程序都使用非常非常糟糕的字体...经过多次尝试更改字体,抗锯齿,安装Lucida字体等等后,我发现我的问题出现在/etc/fonts/conf.d/35-freefont.conf

I simply removed that link, run fc-cache -f and all new Java apps got a much better font. 我只是删除了该链接,运行fc-cache -f并且所有新的Java应用程序都获得了更好的字体。

In my case, the freefont config was telling Java to use it instead of much better fonts. 在我的例子中,freefont配置告诉Java使用它而不是更好的字体。 If you have a similar problem, simply run sudo mv /etc/fonts/conf.d /etc/fonts/conf.d.off and a fc-cache -f and test... 如果你有类似的问题,只需运行sudo mv /etc/fonts/conf.d /etc/fonts/conf.d.offfc-cache -f并测试...

If it works, you also have a bad default font substitution and you should restore that dir and test each file. 如果它工作,你也有一个错误的默认字体替换,你应该恢复该目录并测试每个文件。

If it stays the same, then you probably have another problem (don't forget to restore the conf.d dir) 如果它保持不变,那么你可能有另一个问题(不要忘记恢复conf.d目录)

Update 更新

On Ubuntu 12.04, I had a similar problem, all Java fonts where bold. 在Ubuntu 12.04上,我遇到了类似的问题,所有Java字体都是粗体。 Removing /etc/fonts/conf.d/65-nonlatin.conf fixed the problem. 删除/etc/fonts/conf.d/65-nonlatin.conf修复了问题。

Install the latest version of OpenJDK. 安装最新版本的OpenJDK。 Or recompile Freetype with hinting enabled. 或者在启用提示的情况下重新编译Freetype。 The Apple patents regarding hinting have expired. 关于提示的Apple专利已经过期。

Could be font hinting gone bad. 可能是字体暗示变坏了。 Check the font hinting settings of the Linux OS you're working with. 检查您正在使用的Linux OS的字体提示设置。

Could also be the font--try specifying a different one. 也可以是字体 - 尝试指定不同的字体。 The one you're using may simply render badly on Linux--some just do. 你正在使用的那个可能只是在Linux上糟糕地呈现 - 有些只是这样做。 Palatino is one I've found to be particularly bad. Palatino是我发现特别糟糕的一个。

您可以尝试使用pdffonts来帮助您分析问题 - 它至少会告诉您PDF文件中使用的字体的名称,它们的类型,是否嵌入等。如果字体未嵌入,您可以尝试安装它们Linux机器。

There are 8 standard font families you do not need to embed as the PDF viewer should provide. PDF查看器应提供8种标准字体系列,您无需嵌入。 Otherwise they will be substituted. 否则他们将被替换。 What does the PDF look like in the other PDF Java Open Source viewers (Multivalent, JPedal)? PDF在其他PDF Java开源查看器(Multivalent,JPedal)中的含义是什么?

You can use openJDK and use Sun/Oracle's fonts! 您可以使用openJDK并使用Sun / Oracle的字体!

First install openDJK (both runtime and dev packages) 首先安装openDJK(运行时和开发包)

Then install Sun/Oracle's runtime only. 然后只安装Sun / Oracle的运行时。 This will install the fonts, but you'll still be using openJDK's java to run everything. 这将安装字体,但您仍将使用openJDK的java来运行所有内容。

尝试复制所有Windows字体,并将它们放入您的Linux环境中。

字体是否嵌入PDF中?

I haven't test it but according to this forum post at inductiveautomation.com you can correct it by installing the fonts: 我没有测试它,但根据inductiveautomation.com上的论坛帖子,你可以通过安装字体来纠正它:

sudo apt-get install msttcorefonts

and changing lucidasans for arial in the properties of Java fonts: 并改变Java字体属性中的arial的lucidasans:

sudo nano /usr/lib/jvm/java-6-sun/jre/lib/fontconfig.properties

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM