This commit is contained in:
parent
7e954bfdf9
commit
a53fcf98bf
|
|
@ -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,26 +49,41 @@ 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
|
||||||
try:
|
if not self.custom_font:
|
||||||
# Register Chinese font (Traditional Chinese support)
|
|
||||||
pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))
|
|
||||||
self.chinese_font = 'STSong-Light'
|
|
||||||
except Exception as e:
|
|
||||||
# If CID font registration fails, try alternative method
|
|
||||||
try:
|
try:
|
||||||
pdfmetrics.registerFont(UnicodeCIDFont('STHeiti-Light'))
|
# Register Chinese font (Traditional Chinese support)
|
||||||
self.chinese_font = 'STHeiti-Light'
|
pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))
|
||||||
except Exception:
|
self.chinese_font = 'STSong-Light'
|
||||||
# Last resort: use MSung for Traditional Chinese
|
print("Registered STSong-Light as fallback (Warning: May not be visible in all viewers)")
|
||||||
|
except Exception as e:
|
||||||
|
# If CID font registration fails, try alternative method
|
||||||
try:
|
try:
|
||||||
pdfmetrics.registerFont(UnicodeCIDFont('MSung-Light'))
|
pdfmetrics.registerFont(UnicodeCIDFont('STHeiti-Light'))
|
||||||
self.chinese_font = 'MSung-Light'
|
self.chinese_font = 'STHeiti-Light'
|
||||||
except Exception:
|
except Exception:
|
||||||
# Fallback to basic font
|
# Last resort: use MSung for Traditional Chinese
|
||||||
self.chinese_font = 'Helvetica'
|
try:
|
||||||
print("Warning: Could not register Chinese font")
|
pdfmetrics.registerFont(UnicodeCIDFont('MSung-Light'))
|
||||||
|
self.chinese_font = 'MSung-Light'
|
||||||
|
except Exception:
|
||||||
|
# Fallback to basic font
|
||||||
|
self.chinese_font = 'Helvetica'
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue