feat: add multilingual font support for translated PDFs
- Add NotoSansKR and NotoSansThai fonts for Korean and Thai language support - Update download_fonts.sh to download all required fonts - Add LANGUAGE_FONT_MAP for language-to-font mapping in pdf_generator_service.py - Add get_font_for_language() method to select appropriate font based on target language - Update _get_reflow_styles() to accept target_lang parameter - Pass target_lang through generate_translated_pdf() to PDF generation methods - Fix garbled characters (亂碼) issue for Korean and Thai translations Supported languages: - Chinese (zh-CN/zh-TW), Japanese (ja): NotoSansSC - Korean (ko): NotoSansKR - Thai (th): NotoSansThai - Russian, Vietnamese, Latin languages: NotoSansSC 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,31 +1,56 @@
|
||||
#!/bin/bash
|
||||
# Download Noto Sans SC TrueType font for layout-preserving PDF generation
|
||||
# Download Noto Sans fonts for multilingual PDF generation
|
||||
# Supports: CJK (Chinese, Japanese, Korean), Thai, Vietnamese, Russian, etc.
|
||||
|
||||
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..."
|
||||
echo "🔤 Downloading fonts for multilingual 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"
|
||||
# Function to download font
|
||||
download_font() {
|
||||
local url="$1"
|
||||
local file="$2"
|
||||
local desc="$3"
|
||||
|
||||
if [ -f "$FONT_DIR/$FONT_FILE" ]; then
|
||||
SIZE=$(du -h "$FONT_DIR/$FONT_FILE" | cut -f1)
|
||||
echo "✓ Font downloaded successfully: $SIZE"
|
||||
if [ -f "$FONT_DIR/$file" ]; then
|
||||
echo "✓ $desc already exists"
|
||||
else
|
||||
echo "✗ Font download failed"
|
||||
exit 1
|
||||
echo "Downloading $desc..."
|
||||
if wget -q "$url" -O "$FONT_DIR/$file"; then
|
||||
SIZE=$(du -h "$FONT_DIR/$file" | cut -f1)
|
||||
echo "✓ $desc downloaded: $SIZE"
|
||||
else
|
||||
echo "✗ Failed to download $desc"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# NotoSansSC - Chinese (Simplified), also covers Japanese and basic CJK
|
||||
download_font \
|
||||
"https://github.com/notofonts/noto-cjk/raw/main/Sans/Variable/TTF/Subset/NotoSansSC-VF.ttf" \
|
||||
"NotoSansSC-Regular.ttf" \
|
||||
"Noto Sans SC (Chinese/Japanese)"
|
||||
|
||||
# NotoSansKR - Korean
|
||||
download_font \
|
||||
"https://github.com/notofonts/noto-cjk/raw/main/Sans/Variable/TTF/Subset/NotoSansKR-VF.ttf" \
|
||||
"NotoSansKR-Regular.ttf" \
|
||||
"Noto Sans KR (Korean)"
|
||||
|
||||
# NotoSansThai - Thai
|
||||
download_font \
|
||||
"https://github.com/notofonts/noto-fonts/raw/main/hinted/ttf/NotoSansThai/NotoSansThai-Regular.ttf" \
|
||||
"NotoSansThai-Regular.ttf" \
|
||||
"Noto Sans Thai"
|
||||
|
||||
echo ""
|
||||
echo "✅ Font setup complete!"
|
||||
echo "Supported languages: Chinese (zh-CN/zh-TW), Japanese (ja), Korean (ko),"
|
||||
echo " Thai (th), Russian (ru), Vietnamese (vi),"
|
||||
echo " and all Latin-based languages (en, de, fr, es, etc.)"
|
||||
|
||||
Reference in New Issue
Block a user