对于java.awt.Toolkit类型,未定义getLineMetrics()方法

时间:2018-06-05 13:49:55

标签: javascript awt undefined toolkit

有人可以告诉我为什么会这样:

方法getLineMetrics()未定义类型java.awt.Toolkit

代码:

function StyleHelper(styleText, styleName) {
var defaultFont = "Arial,0,12";

if (styleName == null) styleName = "";
if (styleText == null) styleText = "";

var styleSheet = new Packages.com.servoy.j2db.util.ServoyStyleSheet(styleText, styleName);

this.getFontString = function(styleClass) {
    var rule = styleSheet.getCSSRule(styleClass);
    if (!rule) return defaultFont;
    var font = styleSheet.getFont(rule);
    if (!font) return defaultFont;
    return Packages.com.servoy.j2db.util.PersistHelper.createFontString(font);
}

this.getTextWidth = function(font, text) {
    if (!text) {
        return 0;
    }
    if (!font) {
        font = defaultFont;
    }
    try {
        var fontParts = font.split(",");
        var javaFont = java.awt.Font(fontParts[0], fontParts[1], fontParts[2]);
        var tlkt = java.awt.Toolkit.getDefaultToolkit();
        var metrics = tlkt.getLineMetrics(javaFont);
        if (text.substr(0, 5) == "i18n:") {
            text = i18n.getI18NMessage(text);
        }
        return metrics.stringWidth(text);
    } catch (e) {
        logger.error("Error getting text width for font \"" + font + "\"", e);
        return 0;
    }
}

this.getFontHeight = function(font) {
    if (!font) {
        font = defaultFont;
    }
    try {
        var fontParts = font.split(",");
        var javaFont = java.awt.Font(fontParts[0], fontParts[1], fontParts[2]);
        var tlkt = java.awt.Toolkit.getDefaultToolkit();
        var metrics = tlkt.getLineMetrics(javaFont);
        return metrics.getHeight();
    } catch (e) {
        logger.error("Error getting text height for font \"" + font + "\"", e);
        return 0;
    } 
}
}

我知道不推荐使用getFormMetrics(),这就是我现在尝试使用getLineMetrics()的原因

我也不确定为什么stringWidth(text)和getHeight()也显示为未定义。

由于

0 个答案:

没有答案