#!/usr/bin/env python3
"""
生成 DMG 背景图 — 美家卡智影
画布: 660 x 400 px
"""

import subprocess
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont

W, H = 660, 400

BG = (249, 250, 251)
TEXT_PRIMARY = (17, 24, 39)
TEXT_SECONDARY = (107, 114, 128)
TEXT_TERTIARY = (156, 163, 175)


def get_font(size, bold=False):
    result = subprocess.run(
        ["fc-match", "-f", "%{file}", "PingFang SC"],
        capture_output=True, text=True
    )
    path = result.stdout.strip()
    if path and Path(path).exists():
        idx = 2 if bold else 0
        return ImageFont.truetype(path, size, index=idx)
    return ImageFont.load_default()


font_title = get_font(22, bold=True)
font_body = get_font(13)
font_caption = get_font(11)

bg = Image.new("RGBA", (W, H), (*BG, 255))
draw = ImageDraw.Draw(bg)

# ── 顶部标题 ──
draw.text((W // 2, 55), "拖拽到 Applications 文件夹",
          fill=TEXT_PRIMARY, font=font_title, anchor="mm")

# ── 中部留白：系统图标区域 y≈140~300 ──

# ── 底部提示文字 ──
tip_lines = [
    '首次打开如遇拦截，请右键应用图标选择"打开"',
    '或前往 系统设置 → 隐私与安全性 → 点击"仍要打开"',
]
for i, line in enumerate(tip_lines):
    draw.text((W // 2, 325 + i * 22), line,
              fill=TEXT_SECONDARY, font=font_body, anchor="mm")

# ── 版本号 ──
draw.text((W // 2, H - 14), "v1.5.18",
          fill=TEXT_TERTIARY, font=font_caption, anchor="mm")

output = bg.convert("RGB")
output.save("dmg-background.png", "PNG")
print("✅ Generated: dmg-background.png (660x400)")
