This commit is contained in:
MarkLo 2025-11-25 19:04:23 +08:00
parent 7e954bfdf9
commit a53fcf98bf
3 changed files with 2697 additions and 2656 deletions

View File

@ -28,12 +28,20 @@ class PDFGenerator:
# Try to register custom Cactus Classical Serif font first # Try to register custom Cactus Classical Serif font first
self.custom_font = None self.custom_font = None
# Ensure we have the absolute path to the current file
current_file = os.path.abspath(__file__)
# backend/app/services/pdf_generator.py -> backend/app/services -> backend/app -> backend -> root
root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(current_file))))
custom_font_path = os.path.join( custom_font_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))), root_dir,
'Cactus_Classical_Serif', 'Cactus_Classical_Serif',
'CactusClassicalSerif-Regular.ttf' 'CactusClassicalSerif-Regular.ttf'
) )
print(f"Attempting to load font from: {custom_font_path}")
if os.path.exists(custom_font_path): if os.path.exists(custom_font_path):
try: try:
pdfmetrics.registerFont(TTFont('CactusClassicalSerif', custom_font_path)) pdfmetrics.registerFont(TTFont('CactusClassicalSerif', custom_font_path))
@ -41,12 +49,25 @@ class PDFGenerator:
print(f"Successfully registered Cactus Classical Serif font") print(f"Successfully registered Cactus Classical Serif font")
except Exception as e: except Exception as e:
print(f"Error registering custom font: {e}") print(f"Error registering custom font: {e}")
else:
print(f"Custom font file not found at {custom_font_path}")
# Try looking in current working directory as fallback
cwd_path = os.path.join(os.getcwd(), 'Cactus_Classical_Serif', 'CactusClassicalSerif-Regular.ttf')
if os.path.exists(cwd_path):
try:
pdfmetrics.registerFont(TTFont('CactusClassicalSerif', cwd_path))
self.custom_font = 'CactusClassicalSerif'
print(f"Successfully registered Cactus Classical Serif font from CWD")
except Exception as e:
print(f"Error registering custom font from CWD: {e}")
# Register Chinese font as fallback for CJK characters # Register Chinese font as fallback for CJK characters
if not self.custom_font:
try: try:
# Register Chinese font (Traditional Chinese support) # Register Chinese font (Traditional Chinese support)
pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light')) pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))
self.chinese_font = 'STSong-Light' self.chinese_font = 'STSong-Light'
print("Registered STSong-Light as fallback (Warning: May not be visible in all viewers)")
except Exception as e: except Exception as e:
# If CID font registration fails, try alternative method # If CID font registration fails, try alternative method
try: try:
@ -61,6 +82,8 @@ class PDFGenerator:
# Fallback to basic font # Fallback to basic font
self.chinese_font = 'Helvetica' self.chinese_font = 'Helvetica'
print("Warning: Could not register Chinese font") print("Warning: Could not register Chinese font")
else:
self.chinese_font = self.custom_font
# Set primary font: use custom font if available, otherwise Chinese font # Set primary font: use custom font if available, otherwise Chinese font
self.primary_font = self.custom_font if self.custom_font else self.chinese_font self.primary_font = self.custom_font if self.custom_font else self.chinese_font

View File

@ -18,12 +18,14 @@ dependencies = [
"langchain-google-genai>=2.1.5", "langchain-google-genai>=2.1.5",
"langchain-openai>=0.3.23", "langchain-openai>=0.3.23",
"langgraph>=0.4.8", "langgraph>=0.4.8",
"markdown>=3.9",
"pandas>=2.3.0", "pandas>=2.3.0",
"parsel>=1.10.0", "parsel>=1.10.0",
"praw>=7.8.1", "praw>=7.8.1",
"pytz>=2025.2", "pytz>=2025.2",
"questionary>=2.1.0", "questionary>=2.1.0",
"redis>=6.2.0", "redis>=6.2.0",
"reportlab>=4.4.5",
"requests>=2.32.4", "requests>=2.32.4",
"rich>=14.0.0", "rich>=14.0.0",
"setuptools>=80.9.0", "setuptools>=80.9.0",

5294
uv.lock

File diff suppressed because it is too large Load Diff