在OpenJdk中,如何使用appendedfontpath属性设置字体目录 [英] In OpenJdk how do I set font dir with appendedfontpath property

查看:201
本文介绍了在OpenJdk中,如何使用appendedfontpath属性设置字体目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过 appendedfontpath 属性使我的应用程序在OpenJdk安装中的特定位置使用字体,但是它对我不起作用.

I am trying to get my application to use fonts from a particular location in an OpenJdk installation using appendedfontpath property but it is not working for me.

../jre1.8.0_121+1/bin/java  -Dappendedfontpath=/usr/lib/fonts/  -jar lib/songkong-4.7.jar -m /mnt/disk1/share

未报告未安装的字体,但是/usr/lib/fonts文件夹中确实包含字体ipag.ttf

reporting no fonts installed, but the /usr/lib/fonts folder does contain a font ipag.ttf

请注意:

  • OpenJdk没有预安装的字体,它依赖于系统上安装的字体
  • 这是一个嵌入式系统,报告服务器上未安装任何字体,fc-list不返回任何内容
  • 如果我将字体复制到jre/lib/fonts文件夹中,它可以工作,但不允许将任何内容复制到该文件夹​​中.
  • 也不允许我运行root命令,例如fc-cache -f
  • OpenJdk comes with no preinstalled fonts it relies on fonts installed on system
  • This is an embedded system that reports no fonts installed on server, fc-list returns nothing
  • If I copy the font into jre/lib/fonts folder it works but I'm not allowed to copy anything into this folder.
  • Nor am I allowed to run root commands such as fc-cache -f

如果仅指定包含字体的字体文件夹就可以使它工作,那么对我来说这将是一个可行的解决方案.

If I could get it working by just specifying a font folder containing fonts, it would be a working solution for me.

推荐答案

您可以尝试在启动JVM之前设置JAVA_FONTS环境变量,以使其了解目录路径. 对于您的情况,这可以通过export JAVA_FONTS=/usr/lib/fonts完成. 我的答案基于archlinux Wiki的 Java运行时环境字体文章.

You could try to set the JAVA_FONTS enviroment variable befor starting the JVM to make it aware of the directory path. For your case this could be done by export JAVA_FONTS=/usr/lib/fonts. My answer is based on the Java Runtime Enviroment fonts article of the archlinux wiki.


在未安装字体的VM中进行测试表明,设置JAVA_FONTS不起作用 我得出的结论是,通过您的设置,可能无法实现您的目标.
我使用以下程序在未安装字体的VM上重现该错误:


Test in a VM with no Fonts installed show that setting JAVA_FONTS does not work and I have come to the conclusion that with your setup it might not be possible to achieve your goal.
I used the following Program to reproduce the error on a VM with no Fonts installed:

import javax.swing.*;
public class example{

    public static void main(String[] tArgs){
        JFrame j = new JFrame();
        j.add(new JButton("Test"));
        j.setVisible(true);
        j.pack();
   }

}

这是我的Stacktrace: https://pastebin.com/fy3JDnkN
给出 X11FontManager for (int i=0; i<fontConfigFonts.length; i++) {行中构造字体管理器时发生错误.

Here is my Stacktrace: https://pastebin.com/fy3JDnkN
Given the source of the X11FontManager the error occurs while the Font Manager is constructed in the line with for (int i=0; i<fontConfigFonts.length; i++) {.

public String[] getDefaultPlatformFont() {
    if (defaultPlatformFont != null) {
        return defaultPlatformFont;
    }
    String[] info = new String[2];
    getFontConfigManager().initFontConfigFonts(false);
    FontConfigManager.FcCompFont[] fontConfigFonts =
        getFontConfigManager().getFontConfigFonts();
    for (int i=0; i<fontConfigFonts.length; i++) {
        if ("sans".equals(fontConfigFonts[i].fcFamily) &&
            0 == fontConfigFonts[i].style) {
            info[0] = fontConfigFonts[i].firstFont.familyName;
            info[1] = fontConfigFonts[i].firstFont.fontFile;
            break;
        }
    }
    /* Absolute last ditch attempt in the face of fontconfig problems.
     * If we didn't match, pick the first, or just make something
     * up so we don't NPE.
     */
    if (info[0] == null) {
        if (fontConfigFonts.length > 0 &&
            fontConfigFonts[0].firstFont.fontFile != null) {
            info[0] = fontConfigFonts[0].firstFont.familyName;
            info[1] = fontConfigFonts[0].firstFont.fontFile;
        } else {
            info[0] = "Dialog";
            info[1] = "/dialog.ttf";
        }
    }
    defaultPlatformFont = info;
    return defaultPlatformFont;
}

由于NullPointerException发生在我们可以访问字体管理器之前,因此无法手动添加字体,这种行为表明以后再给注释添加一行是不希望的.

This makes it impossible to add Fonts Manually since the NullPointerException occurs prior to us having access to the Font Manager, this behavior seams to not be intended given the comment a couple lines later.

如果还有另一个适用于Linux的FontManager在没有安装默认系统字体的情况下不会崩溃,但是我找不到这样的替换字体,那么仍然有可能实现您的目标.

It might still be possible to achieve your goal if there is another FontManager for Linux that does not crash with no default System Font installed, but I could not find such a replacement.

这篇关于在OpenJdk中,如何使用appendedfontpath属性设置字体目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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