0

我在画布上使用 gc.setText() 方法显示文本。但是如果 gc 对象发生变化,那么文本的宽度也会发生变化。

我正在使用 gc.setFont(font) 将相同的字体应用于 GC。

Font font = new Font(gc.getDevice(), fontFamily, (int) fontSize,     swtFontStyle);
    if (color != null) {
        gc.setForeground(color);
    } else {
        gc.setForeground(ColorConstants.black);
    }
    gc.setFont(font);
System.out.println("char width in gc: "+gc.getCharWidth('a'));

当 gc 的对象发生变化时,它会返回不同的字符宽度。

谁能帮我解决这个问题。

谢谢伊山耆那教

4

0 回答 0