#!/bin/bash
# Download Noto Sans SC TrueType font for layout-preserving PDF generation

set -e

FONT_DIR="backend/fonts"
FONT_URL="https://github.com/notofonts/noto-cjk/raw/main/Sans/Variable/TTF/Subset/NotoSansSC-VF.ttf"
FONT_FILE="NotoSansSC-Regular.ttf"

echo "🔤 Downloading Chinese font for PDF generation..."

# Create font directory
mkdir -p "$FONT_DIR"

# Download font if not exists
if [ -f "$FONT_DIR/$FONT_FILE" ]; then
    echo "✓ Font already exists: $FONT_DIR/$FONT_FILE"
else
    echo "Downloading from GitHub..."
    wget "$FONT_URL" -O "$FONT_DIR/$FONT_FILE"

    if [ -f "$FONT_DIR/$FONT_FILE" ]; then
        SIZE=$(du -h "$FONT_DIR/$FONT_FILE" | cut -f1)
        echo "✓ Font downloaded successfully: $SIZE"
    else
        echo "✗ Font download failed"
        exit 1
    fi
fi

echo "✅ Font setup complete!"
