diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Cactus_Classical_Serif/CactusClassicalSerif-Regular.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Cactus_Classical_Serif/CactusClassicalSerif-Regular.ttf new file mode 100644 index 00000000..819f1b83 Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Cactus_Classical_Serif/CactusClassicalSerif-Regular.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Cactus_Classical_Serif/OFL.txt b/Cactus_Classical_Serif,Noto_Serif_TC/Cactus_Classical_Serif/OFL.txt new file mode 100644 index 00000000..40529750 --- /dev/null +++ b/Cactus_Classical_Serif,Noto_Serif_TC/Cactus_Classical_Serif/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2024 The Caactus Classical Serif Project Authors (https://github.com/MoonlitOwen/CactusSerif) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/NotoSerifTC-VariableFont_wght.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/NotoSerifTC-VariableFont_wght.ttf new file mode 100644 index 00000000..af32d2f3 Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/NotoSerifTC-VariableFont_wght.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/OFL.txt b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/OFL.txt new file mode 100644 index 00000000..ffd0f285 --- /dev/null +++ b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2012 Google Inc. All Rights Reserved. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/README.txt b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/README.txt new file mode 100644 index 00000000..8a8237bf --- /dev/null +++ b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/README.txt @@ -0,0 +1,70 @@ +Noto Serif TC Variable Font +=========================== + +This download contains Noto Serif TC as both a variable font and static fonts. + +Noto Serif TC is a variable font with this axis: + wght + +This means all the styles are contained in a single file: + Noto_Serif_TC/NotoSerifTC-VariableFont_wght.ttf + +If your app fully supports variable fonts, you can now pick intermediate styles +that aren’t available as static fonts. Not all apps support variable fonts, and +in those cases you can use the static font files for Noto Serif TC: + Noto_Serif_TC/static/NotoSerifTC-ExtraLight.ttf + Noto_Serif_TC/static/NotoSerifTC-Light.ttf + Noto_Serif_TC/static/NotoSerifTC-Regular.ttf + Noto_Serif_TC/static/NotoSerifTC-Medium.ttf + Noto_Serif_TC/static/NotoSerifTC-SemiBold.ttf + Noto_Serif_TC/static/NotoSerifTC-Bold.ttf + Noto_Serif_TC/static/NotoSerifTC-ExtraBold.ttf + Noto_Serif_TC/static/NotoSerifTC-Black.ttf + +Get started +----------- + +1. Install the font files you want to use + +2. Use your app's font picker to view the font family and all the +available styles + +Learn more about variable fonts +------------------------------- + + https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts + https://variablefonts.typenetwork.com + https://medium.com/variable-fonts + +In desktop apps + + https://theblog.adobe.com/can-variable-fonts-illustrator-cc + https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts + +Online + + https://developers.google.com/fonts/docs/getting_started + https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide + https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts + +Installing fonts + + MacOS: https://support.apple.com/en-us/HT201749 + Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux + Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows + +Android Apps + + https://developers.google.com/fonts/docs/android + https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts + +License +------- +Please read the full license text (OFL.txt) to understand the permissions, +restrictions and requirements for usage, redistribution, and modification. + +You can use them in your products & projects – print or digital, +commercial or otherwise. + +This isn't legal advice, please consider consulting a lawyer and see the full +license for all details. diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Black.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Black.ttf new file mode 100644 index 00000000..6bbfb43c Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Black.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Bold.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Bold.ttf new file mode 100644 index 00000000..f50b122b Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Bold.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-ExtraBold.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-ExtraBold.ttf new file mode 100644 index 00000000..a92fe755 Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-ExtraBold.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-ExtraLight.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-ExtraLight.ttf new file mode 100644 index 00000000..6bcaca48 Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-ExtraLight.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Light.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Light.ttf new file mode 100644 index 00000000..c93740ce Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Light.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Medium.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Medium.ttf new file mode 100644 index 00000000..0c7b787c Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Medium.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Regular.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Regular.ttf new file mode 100644 index 00000000..bce11869 Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-Regular.ttf differ diff --git a/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-SemiBold.ttf b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-SemiBold.ttf new file mode 100644 index 00000000..7c4befa0 Binary files /dev/null and b/Cactus_Classical_Serif,Noto_Serif_TC/Noto_Serif_TC/static/NotoSerifTC-SemiBold.ttf differ diff --git a/backend/app/services/pdf_generator.py b/backend/app/services/pdf_generator.py index 9cef33c3..4c2b3e88 100644 --- a/backend/app/services/pdf_generator.py +++ b/backend/app/services/pdf_generator.py @@ -26,64 +26,71 @@ class PDFGenerator: import os from reportlab.pdfbase.cidfonts import UnicodeCIDFont - # Try to register custom Cactus Classical Serif font first + # Initialize font variables self.custom_font = None + self.chinese_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( + # Try Noto Serif TC first (best Chinese support) + noto_font_path = os.path.join( root_dir, - 'Cactus_Classical_Serif', - 'CactusClassicalSerif-Regular.ttf' + 'Cactus_Classical_Serif,Noto_Serif_TC', + 'Noto_Serif_TC', + 'NotoSerifTC-VariableFont_wght.ttf' ) - print(f"Attempting to load font from: {custom_font_path}") + print(f"Attempting to load Noto Serif TC from: {noto_font_path}") - if os.path.exists(custom_font_path): + if os.path.exists(noto_font_path): try: - pdfmetrics.registerFont(TTFont('CactusClassicalSerif', custom_font_path)) - self.custom_font = 'CactusClassicalSerif' - print(f"Successfully registered Cactus Classical Serif font") + pdfmetrics.registerFont(TTFont('NotoSerifTC', noto_font_path)) + self.custom_font = 'NotoSerifTC' + self.chinese_font = 'NotoSerifTC' + print(f"✅ Successfully registered Noto Serif TC font") except Exception as e: - print(f"Error registering custom font: {e}") + print(f"❌ Error registering Noto Serif TC: {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)) + print(f"⚠️ Noto Serif TC font not found at {noto_font_path}") + + # Try Cactus font as fallback + if not self.custom_font: + custom_font_path = os.path.join( + root_dir, + 'Cactus_Classical_Serif', + 'CactusClassicalSerif-Regular.ttf' + ) + + print(f"Attempting to load Cactus font from: {custom_font_path}") + + if os.path.exists(custom_font_path): + try: + pdfmetrics.registerFont(TTFont('CactusClassicalSerif', custom_font_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}") - + print(f"✅ Successfully registered Cactus Classical Serif font") + except Exception as 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 if not self.custom_font: - try: - # CRITICAL FIX: Use Helvetica instead of STSong-Light to avoid font mapping issues - # STSong-Light may have character mapping bugs causing '練' to render as '煉' - self.chinese_font = 'Helvetica' - print("Using Helvetica for Chinese characters (may have better Unicode support)") - except Exception as e: - print(f"Error setting Chinese font: {e}") - # If setting Helvetica fails (unlikely), try alternative CID fonts - try: - pdfmetrics.registerFont(UnicodeCIDFont('STHeiti-Light')) - self.chinese_font = 'STHeiti-Light' - except Exception: - # Last resort: use MSung for Traditional Chinese - try: - 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: + # Use standard Helvetica if no custom fonts available + self.chinese_font = 'Helvetica' + print("⚠️ Using Helvetica as fallback (limited Chinese support)") + elif not self.chinese_font: self.chinese_font = self.custom_font # Set primary font: use custom font if available, otherwise Chinese font