importPackage(java.awt);

const SANS_LAO = Resources.readFont(Resources.idr("fonts/sans_lao/sans_lao.ttf"));
const SOURCE_HAN_SANS_CN = Resources.readFont(Resources.idr("fonts/source-han-sans-cn/source-han-sans-cn-regular.otf"));
const NUM_WIDTH = 1120;
const NUM_HEIGHT = 240;
const ERROR = "请检查侧线名。|Please check the siding name."

function drawNum(g, num, fontSize) {
    if (!g) return;
    let font = SANS_LAO.deriveFont(fontSize);
    let fm = g.getFontMetrics(font);
    let width = (NUM_WIDTH - fm.stringWidth(num)) / 2;
    let height = NUM_HEIGHT - 12;
    g.setColor(new java.awt.Color(0, 0, 0));
    g.setFont(font);
    g.drawString(num, width, height);
    print("编号" + num + "绘制成功！宽度：" + width + "，高度：" + height + "。");
}

function drawError(g) {
    if (!g) return;
    let font = SOURCE_HAN_SANS_CN.deriveFont(60);
    let fm = g.getFontMetrics(font);
    let width = (NUM_WIDTH - fm.stringWidth(ERROR)) / 2;
    let height = NUM_HEIGHT - 12;
    g.setColor(new java.awt.Color(255, 0, 0));
    g.setFont(font);
    g.drawString(ERROR, width, height);
    print(ERROR);
}